Help with interrupt driven ADC

Status
Not open for further replies.

aaaxon

Active member
I'd like to use the Teensy 3.1 onboard ADC's to read audio at a fairly slow rate (about 10ksps). Then I'd like to have the option for making minor adjustment to that sample rate occasionally within the main program. Could someone give me a few hints for setting up a timer-based interrupt to handle the sampling? I've worked with interrupts in the past on other chips, but not this one. But after looking through the samples and examples, I don't see a clear path for doing this.

Any help would be appreciated. Thanks in advance.
 
Check the IntervalTimer examples. A library included with the teensyduino. You can do exactly what you want, although changing the sample rate sounds a bit tricky. I imagine you'll have to keep track of the rates as you change them.
 
linuxgeek,

Thanks for the reply! I had found the IntervalTimer example and was concerned that this approach might introduce timing jitter. The example shows interrupts being deactivated, then reactivated, in order to read a variable. When the deactivation occurs, does this interfere with the timing interval in progress?

I was hoping to find a lead to some sort of periodic triggering of the ADC controlled directly by registers, assuming that would produce greater precision. Unfortunately, I need to update the sample rate without losing precision of the timing intervals.
 
You might be able to calculate the time passed and start the new IntervalTimer with the new sample rate at the next appropriate sampling point.

Maybe you could do something like you said with DMA. I don't know.
 
You might also be able to start a new IntervalTimer within the first interrupt.Would probably want to instantiate it beforehand to minimize delay.
You could have a check for a change in sample rate in the first interrupt, and if there is a change it starts the new IntervalTimer at the new sample rate. And then ends the first IntervalTimer.

You only need to deactivate/reactivate interrupts when you are accessing shared data, AFAIK.
 
Good idea. I didn't think about calling a second IntervalTimer from within the first. I would need to read a timing tick from this interrupt in the main program to control periodic frequency calculations. That's why I'm concerned about changes in the timing interval caused by deactivate/reactivate interrupts.
 
Status
Not open for further replies.
Back
Top