|
|
View previous topic :: View next topic |
Author |
Message |
Jarle Guest
|
8 Bits A/D with PIC16F877 |
Posted: Wed Apr 30, 2003 7:30 pm |
|
|
<font face="Courier New" size=-1>Hello!
Can anyone help me to tell me how I can set up PIC16F877 to a 8-bits A/D converter instead of 10-bits. I found this code but it doesn't work:
#device PIC16F877 *=16 ADC=10
use #device adc = 10 //to implement a 10-bit conversion,
// otherwise the default is 8-bits.
I have also only try: #device adc = 8
Default value is 10-bit.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14104 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 8 Bits A/D with PIC16F877 |
Posted: Thu May 01, 2003 11:34 am |
|
|
:=<font face="Courier New" size=-1>Hello!
:=Can anyone help me to tell me how I can set up PIC16F877 to a 8-bits A/D converter instead of 10-bits. I found this code but it doesn't work:
:=#device PIC16F877 *=16 ADC=10
:=use #device adc = 10 //to implement a 10-bit conversion,
:= // otherwise the default is 8-bits.
:=
:=I have also only try: #device adc = 8
:=Default value is 10-bit.</font>
------------------------------------------------------
What version of the PCM compiler do you have ?
Some older versions had problems with the #device adc
statement. (You can see the version at the top of the
.LST file)
If you post the version, I can post a demo program
that shows how to get 8-bit adc output.
___________________________
This message was ported from CCS's old forum
Original Post ID: 14120 |
|
|
Jarle Guest
|
Re: 8 Bits A/D with PIC16F877 |
Posted: Thu May 01, 2003 6:47 pm |
|
|
Thank you for helping me!
My compiler version:
CCS PCM C Compiler, Version 2.717, 9459
cheers,
Jarle
:=:=<font face="Courier New" size=-1>Hello!
:=:=Can anyone help me to tell me how I can set up PIC16F877 to a 8-bits A/D converter instead of 10-bits. I found this code but it doesn't work:
:=:=#device PIC16F877 *=16 ADC=10
:=:=use #device adc = 10 //to implement a 10-bit conversion,
:=:= // otherwise the default is 8-bits.
:=:=
:=:=I have also only try: #device adc = 8
:=:=Default value is 10-bit.</font>
:=------------------------------------------------------
:=
:=What version of the PCM compiler do you have ?
:=Some older versions had problems with the #device adc
:=statement. (You can see the version at the top of the
:=.LST file)
:=
:=If you post the version, I can post a demo program
:=that shows how to get 8-bit adc output.
___________________________
This message was ported from CCS's old forum
Original Post ID: 14135 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: 8 Bits A/D with PIC16F877 |
Posted: Fri May 02, 2003 1:49 pm |
|
|
:=What version of the PCM compiler do you have ?
:=Some older versions had problems with the #device adc
:=statement. (You can see the version at the top of the
:=.LST file)
:=
:=If you post the version, I can post a demo program
:=that shows how to get 8-bit adc output.
---------------------------------------------------------------
I got your private message. You should not rely on using
private messages, because they only work 1/3 of the time.
I have 21 messages listed as being sent to me, but I can
only see 7 of them. 14 of them are lost somewhere.
So I advise you to use the main board to post messages.
Your version of the compiler could have bugs with the #device
adc=8 statement. Here are two lines from the old CCS versions
page:
2.729 When using #DEVICE ADC=8 the correct 8 bits are now used for all chips
2.732 A Bug in #DEVICE ADC= is now fixed - See read.me file
So it's likely that you do have a problem with adc=8.
I made a demo program that should fix it. Just call the
new function "read_adc_8()", instead of calling read_adc().
I tested it, and it works OK.
<PRE>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 8000000)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
<BR>
// To use the read_adc_8() function, you need to include
// the following lines above main(). These definitions
// are for a 16F877.
#define AD_LEFT_JUSTIFY 0
#define AD_RIGHT_JUSTIFY 1
#bit ADFM_BIT = 0x9f.7
#bit ADC_GO_BIT = 0x1F.2
#byte ADRESH_REG = 0x1E
<BR>
char read_adc_8(void);
<BR>
//=====================================
void main()
{
char c;
<BR>
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_DIV_32);
set_adc_channel( 0 );
<BR>
while(1)
{
c = read_adc_8();
<BR>
printf("\%x\n\r", c);
<BR>
delay_ms(500);
}
<BR>
}
<BR>
//===============================
char read_adc_8(void)
{
ADFM_BIT = AD_LEFT_JUSTIFY;
ADC_GO_BIT = 1;
while(ADC_GO_BIT);
return(ADRESH_REG);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14153 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|