# How much time does getadc() command take?

Discussion in 'Digital Circuit Design' started by Ali Daneshmand, Oct 21, 2016.

1. ### Ali Daneshmand Thread Starter New Member

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

2. ### GopherT AAC Fanatic!

Nov 23, 2012
7,983
6,786
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.

Ali Daneshmand likes this.
3. ### Ali Daneshmand Thread Starter New Member

Oct 21, 2016
12
2
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.

4. ### GopherT AAC Fanatic!

Nov 23, 2012
7,983
6,786
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.

Ali Daneshmand likes this.
5. ### Ali Daneshmand Thread Starter New Member

Oct 21, 2016
12
2
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
Incr N

Loop Until N > 200000
Toggle Red

Loop

6. ### Ali Daneshmand Thread Starter New Member

Oct 21, 2016
12
2

\$crystal = 8000000
Config Adc = Single , Prescaler = Auto , Reference = Internal ' '

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

Wait 6
Green = 1
Do
N = 0
Do
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)

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!

GopherT likes this.
7. ### Ali Daneshmand Thread Starter New Member

Oct 21, 2016
12
2
I forgot to dimension variables in previous post

GopherT likes this.
8. ### MrChips Moderator

Oct 2, 2009
19,051
6,121
Digitize a 500Hz square wave signal and see how many high samples you get in 1ms duration.

9. ### Ali Daneshmand Thread Starter New Member

Oct 21, 2016
12
2
0.5 cycle and 1 peak

Oct 21, 2016
12
2

Oct 2, 2009
19,051
6,121