![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
tmach
Joined: 20 Dec 2003 Posts: 14
|
A/D conversion time accuracy |
Posted: Sun Jan 25, 2004 11:01 am |
|
|
Hello!
I am using the A/D functionality in 16F874A. I am trying to exactly determine the A/D conversion time by using timer 0 reading. Please advice me if my calculations are right. I am using 20MHz oscillator, which means timer increments at the rate of .2 us (1/(20000000*4)). My code follows,
***********************************************************
#include <16f874A.h>
#device ADC=10;
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
#int_ad
toggle_incr()
{
toggle = 1;
}
#int_timer0
timer0_isr()
{
timer_overflow++;
}
int8 timer_overflow = 0; //number of times the counter has overflown in between A/D conversion
main()
{
int8 seconds = 0;
setup_adc_ports(ALL_ANALOG);
setup_adc( ADC_CLOCK_DIV_32 );
set_timer0(0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1); //count 256
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_AD);
while(TRUE) // Main program loop
{
set_timer0(0);
timer_overflow = 0;
seconds = get_timer0(); //get initial count
A2D(); //calls A/D routine. Not included in code
seconds -=get_timer0(); //get final count
printf("%02u %02u \n",seconds, timer_overflow);
}
***********************************************************
seconds gives the counter reading and timer_overflow gives number of timer overflows. So the total A/D coversion is:
(timer_overflow * 256 + seconds) * 0.2 us + 50 * .2 us
The 50 is included to account for the interrupt routine time lapse. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: A/D conversion time accuracy |
Posted: Sun Jan 25, 2004 3:54 pm |
|
|
tmach wrote: | Hello!
I am using the A/D functionality in 16F874A. I am trying to exactly determine the A/D conversion time by using timer 0 reading. Please advice me if my calculations are right. I am using 20MHz oscillator, which means timer increments at the rate of .2 us (1/(20000000*4)). My code follows,
***********************************************************
#include <16f874A.h>
#device ADC=10;
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=20000000)
#use rs232(baud=115200, xmit=PIN_C6, rcv=PIN_C7)
#int_ad
toggle_incr()
{
toggle = 1;
}
#int_timer0
timer0_isr()
{
timer_overflow++;
}
int8 timer_overflow = 0; //number of times the counter has overflown in between A/D conversion
main()
{
int8 seconds = 0;
setup_adc_ports(ALL_ANALOG);
setup_adc( ADC_CLOCK_DIV_32 );
set_timer0(0);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1); //count 256
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
enable_interrupts(INT_AD);
while(TRUE) // Main program loop
{
set_timer0(0);
timer_overflow = 0;
seconds = get_timer0(); //get initial count
A2D(); //calls A/D routine. Not included in code
seconds -=get_timer0(); //get final count
printf("%02u %02u \n",seconds, timer_overflow);
}
***********************************************************
seconds gives the counter reading and timer_overflow gives number of timer overflows. So the total A/D coversion is:
(timer_overflow * 256 + seconds) * 0.2 us + 50 * .2 us
The 50 is included to account for the interrupt routine time lapse. |
Don't waste so much effort. Have no 'carry' counter, set the timer to 0, trigger the conversion, and read the counter when it finishes. Total clocks=counter*4.
This will include the overhead of reading the bytes, from the AD, and the counter.
The ADC conversion time, is Tad*12, plus the time taken to trigger the conversion, and the time taken to read it. Typically perhaps 15 instructions. Tad, is 1/625000 second (20000000/32). A total of about 450 clocks, which will give a count of about 112. Hence a 'carry' is not needed.
Best Wshes |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|