# Teensy 4, 4.1 or 3.6 - DMA 4 (multiple) channel ADC 9.6 khz

Status
Not open for further replies.

#### Qar

##### Member
I am searching for an easy way to double buffer four channels (or more) using DMA like in the ADC_timer_dma example (at 9600hz).

I am not a programmer so it would probably take me a few weeks to be able to realise it myself. I hope someone already written a library, modified pedvide's library or can give me a hint what to do? My current solution is a cheap arduino as a sidekick, but that's not very elegant and a waste of money.

It may depend on what you really need, like do you need for all 4 to be read at the same time?
I will try explain by example: I have code that I have played with to try to understand when any of 4 electrical circuits are active by using a simple sensor (coil) wrapped around some AC circuits (Well pumps), and when it is running it creates an AC like signal converted to analog voltage... So I do samples of the circuits Lets say (60*50) times per second speed I may do reads of each of the 4 for maybe a tenth of a second, 5 full 60hz cycles and do a quick RMS calculation to know if that circuit is active and about how much current.... But only 2 ADCs and I want to do 4...
So I alternate every 10th second or so between each of two sets... Which for my usage is more than frequent enough...
That is one approach...

There is another approach and we have/had examples of this (@mjs513), which we never fully integrated into the ADC library. We started off rolling our own version (ADCL_t4) it is up on github... But not a completed project, it was used by a few us to understand enough of ADC stuff to be able to help people migrate to T4 who used the ADC library... But then Pedvide worked with us to integrate most of the support directly into the main ADC library.

Again it has been awhile, but our DMA code I believe already works using the ADC_ETC code, where you can setup a trigger chain. More or less we are setup to a trigger chain of 1 item (the ADC pin)
but I believe for each of the two ADC channels you can set up a chain of like 8 analog pins (or touch controller)...

So if I remember @mjs513 example we setup a chain with reading multiple pins by updating registers like: ADC_ETC_TRIG0_CHAIN_1_0
plus you need to setup some other registers for what these are and... All of this is in chapter 66 of the T4 manual... Warning after reading through these chapters (also the ADC), XBAR, ... several dozen times, it is still clear as mud to me.

Thank you for your answer. I just need to have the CPU free for calculations, so microseconds delay in between doesn't matter. But it sounds quite complicated and that explains why there is no library available.

But in general; It is technically possible to read 16 channel with 2 adcs at 9.6khz each with a teensy 4.1, using a timer to trigger the adc, starting the chain about every 100µs?

But I guess i have to use an external adc or an arduino for additional channels.

A simple collection routine to get 4 channels from the Teensy 4.X ADC channels at 9600 samples per second with an Intervaltimer should consume only about 2% of the CPU resources (~2 microseconds out of every 104 microseconds). If your CPU resources are so tight that you are using 98% of the cycles on things other than collecting ADC values, I suggest you review your algorithms! ;-)

What you didn't tell us in your initial post are the resolution and signal-to-noise levels that you need and the type of sensors you will be sampling. These are critical items when designing a data collection scheme.

Status
Not open for further replies.