|
|
View previous topic :: View next topic |
Author |
Message |
art
Joined: 21 May 2015 Posts: 181
|
ADC problem |
Posted: Tue Sep 15, 2015 1:28 am |
|
|
Hi, i'm having trouble with ADC. Suppose when i used pic18f4550 it can be used for 10 bit ADC. But it only display 8bit. What is wrong with my code?
Code: | #include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,error)
void main()
{
int i;
float min, value, max;
setup_port_a(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
do {
min=1023;
max=0;
for(i=0; i<=1; ++i)
{
delay_ms(5);
value = Read_ADC();
If( value<=min);
min=value*5/1023;
If( value>=min);
max=value;
}
printf(" Voltage : %2.3f V NO: %3.0f ", min, max);
}while(TRUE);
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 15, 2015 1:45 am |
|
|
Download the CCS manual for your compiler:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Look in the section called "ADC". It's on page 48 in the Adobe reader.
(numbered page 38).
It says:
Quote: |
#DEVICE ADC=xx
Configures the read_adc return size. For example, using a PIC with a
10 bit A/D you can use 8 or 10 for xx- 8 will return the most significant
byte, 10 will return the full A/D reading of 10 bits.
|
The default is 8 bits. So you need to put in a #device statement right
after the #include for your PIC.
Also, this is going to fail to compile:
Quote: | #use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,error) |
Consult the CCS manual and fix it. |
|
|
art
Joined: 21 May 2015 Posts: 181
|
|
Posted: Tue Sep 15, 2015 1:51 am |
|
|
Thank you very much, problem solve. |
|
|
|
|
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
|