How much time does getadc() command take?

Thread Starter

Ali Daneshmand

Joined Oct 21, 2016
12
Hi everybody,Can someone please tell me how much time does getadc(x) command(Basic language) take in microsecond? (8 Mhz oscillator Atmega8)
Thanks.
 

GopherT

Joined Nov 23, 2012
8,009
Hi everybody,Can someone please tell me how much time does getadc(x) command(Basic language) take in microsecond? (8 Mhz oscillator Atmega8)
Thanks.
Put a 50 consecutive getAdc(X) commands together and then toggle an LED on then another 50 reads and then toggle off (100 total per flash). If you can see individual flashes, use an oscilloscope. Adjust the number of reads between toggles.
 

Thread Starter

Ali Daneshmand

Joined Oct 21, 2016
12
Put a 50 consecutive getAdc(X) commands together and then toggle an LED on then another 50 reads and then toggle off (100 total per flash). If you can see individual flashes, use an oscilloscope. Adjust the number of reads between toggles.
Ingenious idea!Thanks, But There is no oscilloscope!Maybe I can use Incr variable in The loop and toggle pin after for Example var equal to 30 and divide total toggle time to 30.
 

GopherT

Joined Nov 23, 2012
8,009
Ingenious idea!Thanks, But There is no oscilloscope!Maybe I can use Incr variable in The loop and toggle pin after for Example var equal to 30 and divide total toggle time to 30.
There are lots of options, just develop one that works for you and the tools you have. Loops take a lot of time as well so make sure you account for the core (instruction set) level clock cycles needed for those as well.

I am surprised that documentation is not available for your question but it may be easier to measure. If you have enough program memory, you may be able to measure with a stopwatch to some reasonable level of accuracy. 5000 or 50000 ADC steps per LED toggle.
 

Thread Starter

Ali Daneshmand

Joined Oct 21, 2016
12
There are lots of options, just develop one that works for you and the tools you have. Loops take a lot of time as well so make sure you account for the core (instruction set) level clock cycles needed for those as well.

I am surprised that documentation is not available for your question but it may be easier to measure. If you have enough program memory, you may be able to measure with a stopwatch to some reasonable level of accuracy. 5000 or 50000 ADC steps per LED toggle.
Thankks,I am calculating the getadc duration with following code,but I think " incr" takes time too! Green indicates stopwatch start,Red incdicates stop.


dim w as word,n as long
red=0

Wait 6
Green = 1

Do
N = 0
Do
W = Getadc(0)
Incr N

Loop Until N > 200000
Toggle Red

Loop
 

Thread Starter

Ali Daneshmand

Joined Oct 21, 2016
12


$regfile = "m8adef.dat"
$crystal = 8000000
Config Adc = Single , Prescaler = Auto , Reference = Internal ' '
Enable Adc
Start Adc

Config Portd.4 = Output
Config Portd.3 = Output
Green Alias Portd.3
Red Alias Portd.4


Loop with getadc():

Wait 6
Green = 1
Do
N = 0
Do
W = Getadc(0)
Incr N
Loop Until N >= 500000
Toggle Red
Loop

Time to red on = 1: 54.00 = 114000000 us
114000000 / 500000 = 228 us (Each cycle takes)



Loop without getadc():

Wait 6
Green = 1
Do
N = 0
Do
Incr N
Loop Until N >= 500000
Toggle Red
Loop
Time to red on = 0 : 3.58 = 3580000 us
3580000 / 500000 = 7.16 us (Each cycle takes)


228 - 8 = 220 us Time getadc() takes

I did not think it takes such a long time!
 

MrChips

Joined Oct 2, 2009
30,808
Another way of finding the sampling rate, if you have the necessary equipment, is to determine the Nyquist frequency x 2.

Input a sine wave signal and observe the reconstructed waveform.
Starting at a low input frequency, say 100Hz, slowly increase the frequency until you observe that the reconstructed frequency reaches a maximum value and then diminishes to 0Hz, i.e. constant DC voltage. This frequency is equal to your sampling frequency.
 
Top