Posted: Sun Apr 03, 2022 6:21 pm Post subject: Perplexity on the ADC
Hello everyone.
I need to measure for 10 times an analog level that is generated when timer2 expires and that remains constant for 250usec followed by a pause of another 250usec.
I was thinking of setting a flag in the routine that serves the timer when it determines the start of the level to be measured. The flag should launch the GETADC command in the main loop to have a single conversion each time by exploiting also the short delay for re-entering the loop (due to registers retrieval) which would allow the level to stabilize.
The clock frequency is 16MHz while that of the ADC is 125KHz. The micro is ATmega328.
Can I be sure that I have reliable and relevant data every time to the constant level in the 250usec?
From the datasheet can be deduced that the first conversion requires 25 clock cycles after the start and therefore the time would be enough even if I used the stop after each conversion. Does GETADC consider conversion time, in other word, it wait for "conversion complete"?
Yes, it waits and even start another one and wait again.
This is because if you change MUX then first read can`t be trusted so Bascom always measure it twice (compiler dont know if you change MUX or not).
This is some waste of time/overhead if you measure only one input...
When you have one input only then starting and reading single conversion i quite easy:
Code:
Dim Adc_read AsWord
Adc_read =Getadc(0)'dummy read simply set the proper MUX if you dot want to do this on the regs.
Do
Set ADCSRA.6 'start new conversion Bitwait ADCSRA.6 , Reset'wait till conversion ends
Adc_read = ADC 'read it
GetADC() does internally two measurements to make sure the second is correct.
You'll do better if you do sampling by directly using registers.
One conversion takes 13 ADC-cycles, if using the same channel and one dummy sample was done in front.
That means 104us per sample, which is well within 250us.
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 You cannot attach files in this forum You cannot download files in this forum