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

how can i be sure that adc is doing well?

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



Joined: 16 Oct 2010
Posts: 20

View user's profile Send private message

how can i be sure that adc is doing well?
PostPosted: Sat Oct 23, 2010 6:06 pm     Reply with quote

Hello
This is my code to convert analog signal at RA0 to digital then send it via serial port to my pc

Code:
#INCLUDE <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#USE DELAY (CLOCK=10000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
int16 adc_value;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_4);
set_adc_channel(0);
delay_us(20);
while(1){
adc_value = read_adc();
putc(adc_value);
}
}



I run simulation on Proteus and it works with no errors but my question how to know that my output is true? i get ones and zeros but i don't know if they are correct conversion or not! I need something to convert these ones and zeros again to analog!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 23, 2010 6:29 pm     Reply with quote

Quote:
#USE DELAY (CLOCK=10000000)

setup_adc(ADC_CLOCK_DIV_4);

You are not using the correct ADC clock divisor for your oscillator
frequency. Look at this table in the 16F877A data sheet:
Quote:
TABLE 11-1: TAD vs. MAXIMUM DEVICE OPERATING FREQUENCIES (STANDARD DEVICES (F))

That table lists the correct divisor to use. Edit your setup_adc()
statement to use the correct divisor.
http://ww1.microchip.com/downloads/en/devicedoc/39582b.pdf
The data sheet says this:
Quote:
For correct A/D conversions, the A/D conversion clock
(TAD) must be selected to ensure a minimum TAD time
of 1.6 μs.

So your current divisor of 4 will give inaccurate A/D results.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Oct 23, 2010 7:43 pm     Reply with quote

To know if your A/D is working just measure the analog input with a voltmeter and calculate what the digital value should be. If you don't know how to calculate that you should read the A/D section of the datasheet for your PIC.

Once you know it works for DC values, you may want to check that it works AC values too. For that you will need a scope or some other way to accurately measure the analog input. You will also probably want the PIC to generate a pulse on a pin so you can see on your scope WHEN the A/D is reading so you can read the scope value at the same time.
_________________
The search for better is endless. Instead simply find very good and get the job done.
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