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 CCS Technical Support

18F87K22 A/D

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



Joined: 19 May 2018
Posts: 27

View user's profile Send private message

18F87K22 A/D
PostPosted: Sat Jul 27, 2019 2:18 pm     Reply with quote

It appears i need a delay between a/d reads, is this normal?
the code below gives correct read for a but b is way off!


a=read_adc();
delay_ms(0);
b=read_adc();

results are a = 228 b = 2.

if i change delay to 1 ms
results are a= 228 b = 228
why is a delay needed? how much time is needed between reads?
int oscillator 32000000

adc clock = int
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jul 27, 2019 3:20 pm     Reply with quote

Yes normal... have a read of the ADC section of the datasheet. It explains most of what you need to know and there's a chart that will show VALID ADC setups depending on PIC clock speed.
For more detailed information, go to Microchip's website, find the 'application notes', look for ADC related articles.
If you expect to get good, repeatable readings pay attention to board layout, filter caps, Vref, and external wiring. All are necessary for 10 or more bit ADC.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Sat Jul 27, 2019 10:39 pm     Reply with quote

The ADC has to acquire between readings.
So, yes a delay is normal.
However you can program the ADC to automatically perform the
acquisition delay when it is read. Setting this is down to your setup.
Many of the older more basic ADC's don't allow this, but yours does.
The datasheet has a section explaining this, and also giving the limits
on the source impedance that is required to give accurate readings.
If you are having to wait longer than the datasheet describes for this
your source does not have a low enough impedance, and results will
always be poor.
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