what's the most efficient way to sample continuously from 4 analog pins on teensy 3.6

Status
Not open for further replies.

mmalex

Member
hi! I have a project where I want to sample continuously (at a few khz sample rate) from 4 analog pins on a teensy 3.6. I realise there are only 2 ADCs in it, so at the moment I have an IntervalTimer (with priority set high) running at double my sample rate, which does roughly:
Code:
volatile int tick=0; // toggles on each tick
const static int pins[4]={... my 4 analog pins }
volatile int results[4]; // really a buffer, but for the sake of example...
void intervaltimer() {
results[tick]=adc.readSingle(0);
results[tick+2]=adc.readSingle(1);
tick=1-tick;
adc.startSingleRead(pins[tick],0);
adc.startSingleRead(pins[tick+2],1);
}

in other words, it reads from 2 out of the 4 pins on alternating 'ticks', manually.
this works fine, but I was wondering if there was some clever combination of the DMA, perhaps PTC / PDB units to orchestrate this kind of 'dma mux toggling' automagically, without having to burden the CPU.

any ideas? the PTC/PDB's finer abilities still escape me a bit :)
many thanks in advance.
 
Status
Not open for further replies.
Back
Top