2

I'm using my ATmega328P to sample an analog signal in free running mode. The ADC clock frequency is set to ÷128. I've read that a single analog conversion lasts 13 clock cycles. I would like to know if the number of clock cycles changes if I make the ADC trigger an interrupt after every conversion (ADIE bit set to one). Or will the ADC still use 13 clock cycles and start again on the 14th?

If ADIE is set to zero (no interrupts) will the result of the conversion still be written to ADCL and ADCH? And at what time of the 13 clock cycles is this result written to those registers? This is important to me so I can calculate how much time I have to read those registers.

Would it be possible to set ADIE to zero and instead use a timer interrupt to read ADCL and ADCH every ~1 millisecond. Or am I missing something important?

  • What are you trying to achieve? 13 clock cycles are way below 1 ms. – Paul Dec 29 '15 at 0:21
  • Can no one answer these questions about the adc behavior (1. & 2.)? It isn't really made clear in the data sheet. I know that 13 clock cycles are below 1 ms but those questions are still important to me. – Alex Dec 29 '15 at 8:47
  • You might take a look at Amanda Ghassaei's tutorial on Arudino Frequency Detection, she has a neat trick where she toggles a pin in her ISR to get a mark on a scope trace which allows her to see the time interval between ADC conversions. – dlu Dec 29 '15 at 9:18
  • Yes, it would still be written to the ADCx registers, or just test it out? But why would you want to read out the ADC value if it hasn't changed? How you mean, how much time you have to read it out, these are two registers and could be read in like 2 or 3 cycles. Are you afraid the reading and writimg would be at the same time? – Paul Dec 29 '15 at 10:35
  • I want to sample with a constant rate of ~1000/500/200 Hz. The ADC runs in the background with a frequency of 9615 Hz, so I only need every ~10th/... result. I don't want to interrupt the processor everytime an conversion finished bc I don't need those results. That's why I want to set a timer interrupt to read those values from ADCL and ADCH with the right frequency. – Alex Dec 29 '15 at 11:34
1

You may want to take a look at Amanda Ghassaei's tutorials on Arduino DSP techniques or the FFT/FHT code at the Open Music Labs. Both use the Arduino ADC in free running mode. Amanda's code uses interrupts, the Open Music Lab code sits in a tight loop waiting for the conversion to complete.

Based on the Open Music Lab code I can say, yes, the conversion is still written to ADCL and ADCH regardless of the interrupt setting in ADIE. I can't tell from your question how concerned you are about cycle counts, but I don't think you'd see a significant change using interrupts (I'd expect it to be zero). But using interrupts you'll take a hit as you enter and return from the ISR.

As I mentioned in the comment, take a look at Amanda Ghassaei's code. She toggles pin 12 which creates a spike in the trace if you have a scope attached to pin 12 (or a logic analyzer). That will give you a very easy way to determine the actual time to handle the conversion.

  • So the result is written to ADCL and ADCH at some time (probably at the end) of these 13 clock cycles and I can read those registers until the same time in the next round (then they are overwritten)? – Alex Dec 29 '15 at 11:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.