Teensy 3.6 ADC Speed and multiple analog signals

Not open for further replies.

I am rather new to microcontroller programming and electronics in general and would be very grateful for some help with a project I am working on.

I'm sorry if all if that has already been answered elsewhere, maybe I didn't search for the right terms.

I have three analog signals that I have to read with a frequency of about 10 kHz and a 12 bit resolution and I am worried about the time all of that takes.

For two signals, I should be able to use the two ADCs on the Teensy 3.6 to have two simultaneous conversions, right? But how simultaneous is that really? I always assumed that commands in the code were done sequentially. If I write two analogReads for different ADCs directly after one another, would the program wait the multiple clock cycles that the first conversion takes before initiating the second, or would the second one be started directly after the first, with their results coming in almost at the same time?

For the third signal, I would have to use another pin of an ADC that already converted one of the other two signals. Is that the fastest way to get all three signals or am I missing a better possibility I am missing? I have to do some calculations with the signals before the next ones come in and would love to spend as few clock cycles as possible on the signal reading.

Thanks to everyone in advance!
The "simple" analogRead() function is blocking. That means, code execution will only continue after the conversion is done and the result returned. That is ok for occasional readings but not for continuous sampling with precise timing.

You should consider looking at the ADC library, contributed by forum member Pedvide, which allows doing continuous multiple channel sampling in the background and to trigger either an interrupt or a DMA transfer when a reading sequence is fully accomplished or when the buffer is full. This allows to do your calculations with the previous readings while the new ones are acquired in the background.
Thank you for your response. I had already found Pedvide's library you mentioned, but it seems I haven't read it properly. I'll look through the documentation more thoroughly.
So in continuous mode I could basically set some kind of 10 kHz timer and read the values currently stored in the ADCs, even on multiple channels? In the case of two signals on different pins of the same ADC, the conversions would still be done sequentially, correct?
Yes and yes. You might also look for inspiration at the source code of the analog input objects in the audio library. Here, the PDB is used to trigger timed conversions (44.1kHz) with high precision.
Trying to do the same with 4 channels

Thank you again, I will look into that.


Were you able to develop your code? I am trying to do the same with Teensy 3.6. I have to use 4 channels rather than 3. Please let me know what you think?

I ended up not optimizing the adc input speed too much. After setting everything up I noticed that reading the data just with Pedvides adc library and using the fastest settings was quick enough for me.

Reading three pins takes a little under 10 ųs, which leaves me enough time to complete all my computations and still repeat everything with 20 kHz.

To ensure the correct timing, I check a variable of with type elapsedMicros. Since I know that one iteration takes 46 ųs at worst, I have the whole code inside an if statement, execute it only when the variable is >=50 and set the variable to 0 immediately. So far that seems to be fairly accurate.

I'm currently on my phone, so directly writing code here doesn't work well, but I can add some code snippets later, if you think you can use it.
No, there was no need for that.

My code is rather small and I don't need to save any data I read for very long. I start overwriting the oldest data after about half a second and the Teensys own memory is more than enough for my purposes.
Not open for further replies.