View previous topic :: View next topic |
Author |
Message |
Paolino
Joined: 19 Jan 2004 Posts: 42
|
ADC readings fault |
Posted: Tue Jan 03, 2006 2:44 am |
|
|
I do not know what I am missing, but it seems that my PIC18F252 reads 8 bits data instead of 10 bits... I am working with CCS PCWH 3.241. Here is my code:
Code: | void analog_reading (void)
{
int16 adc_value=0;
set_adc_channel(0);
delay_us(100);
read_adc(ADC_START_ONLY);
delay_us(100);
adc_value= read_adc(ADC_READ_ONLY);
lcd_gotoxy(1,1);
printf (lcd_putc,"%X analog",adc_value);
}
|
And here my include file preferencies:
Code: | #include <18F252.h>
#device adc=10
#use delay(clock=10000000)
#fuses HS,NOWDT,NOBROWNOUT,NODEBUG, NOLVP, NOWDT
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
The LCD always shows an 8 bits value; I connected directly the 5V to AN0 and I've seen "FF analog"...
Do you think it is a printf bug or I am making a mistake which I can not see?
Thank you for your help.
Paolo |
|
|
JBM
Joined: 12 May 2004 Posts: 54 Location: edinburgh, Scotland
|
Printf format? |
Posted: Tue Jan 03, 2006 4:10 am |
|
|
Firstly, I think your problem lies in your prinitng out:
%X prints an int8 to the screen, but you have an int16.
Just change the code to read:
Code: | printf (lcd_putc,"%LX analog",adc_value); |
hope this helps
-JBM |
|
|
Paolino
Joined: 19 Jan 2004 Posts: 42
|
|
Posted: Tue Jan 03, 2006 10:45 am |
|
|
Dear JBM,
I will test it tomorrow morning. Thank you for your help. I will let you know.
Paolo. |
|
|
DragonPIC
Joined: 11 Nov 2003 Posts: 118
|
|
Posted: Tue Jan 03, 2006 2:36 pm |
|
|
did you setup the ADC?
setup_adc_ports();
setup_adc(); _________________ -Matt |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
Re: Printf format? |
Posted: Tue Jan 03, 2006 5:27 pm |
|
|
JBM wrote: | Firstly, I think your problem lies in your prinitng out:
%X prints an int8 to the screen, but you have an int16.
Just change the code to read:
Code: | printf (lcd_putc,"%LX analog",adc_value); |
hope this helps
-JBM |
This is VERY likely to be the problem. Use %LX like JBM suggests. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
Guest
|
|
Posted: Wed Jan 04, 2006 3:47 am |
|
|
That was the point. Thank you; my eyes have been open by your answers... After lot of hours, I could not see a simple %LX missing... Thank you again for your help.
Paolo. |
|
|
Paolino
Joined: 19 Jan 2004 Posts: 42
|
|
Posted: Wed Jan 04, 2006 3:48 am |
|
|
Sorry, I was not logged in...
That was the point. Thank you; my eyes have been open by your answers... After lot of hours, I could not see a simple %LX missing... Thank you again for your help.
Paolo. |
|
|
|