sampling arbitrary analog input at fixed samplerate

lokki

Well-known member
hi there,

this might be pretty basic, but every search points me to the audio library which I think is not the way to go here (but maybe it still is)

I want to read an analog signal on a teensy 4.1 which has no audio shield and most pins already used. I don't need audio out, but I need a constant sampling frequency from that analog input. It would be great to get 44.1khz or 48khz sampling rate and I could work on the samples every 16th run. (a "buffer size" of 16 samples)

I guess this is something that is best done with an interrupt? I would be very glad for a little example of how to setup such an interrupt on teensy 4.1

cheers
 
Best done with DMA, although more complex to setup - interrupts are subject to timing variation from other interrupts, critical sections etc.

The Audio library analog input class might be a source of inspiration.
 
thanks, I found the adc examples in teensyduino, don't know why I did not see them before...
 
@MarkT wrote: Best done with DMA, although more complex to setup - interrupts are subject to timing variation from other interrupts, critical sections etc
Not entirely true. If you use the ADC timer functions in the ADC library, ADC Collection is started by the hardware. The response to the interrupt and the processing and storage of the results may be delayed a bit by other interrupts, but the sampling is good to a few CPU Clock cycles of jitter.

There's a long thread from a few years ago on the topic of fast ADC collection, timing and jitter. A souce code example is here:

FAST ADC
 
Back
Top