CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ADC readings fault

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Paolino



Joined: 19 Jan 2004
Posts: 42

View user's profile Send private message

ADC readings fault
PostPosted: Tue Jan 03, 2006 2:44 am     Reply with quote

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

View user's profile Send private message

Printf format?
PostPosted: Tue Jan 03, 2006 4:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 03, 2006 10:45 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Jan 03, 2006 2:36 pm     Reply with quote

did you setup the ADC?

setup_adc_ports();
setup_adc();
_________________
-Matt
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

Re: Printf format?
PostPosted: Tue Jan 03, 2006 5:27 pm     Reply with quote

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








PostPosted: Wed Jan 04, 2006 3:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jan 04, 2006 3:48 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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