View previous topic :: View next topic |
Author |
Message |
doryme
Joined: 16 Oct 2010 Posts: 20
|
how can i be sure that adc is doing well? |
Posted: Sat Oct 23, 2010 6:06 pm |
|
|
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
|
|
Posted: Sat Oct 23, 2010 6:29 pm |
|
|
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
|
|
Posted: Sat Oct 23, 2010 7:43 pm |
|
|
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. |
|
|
|