Teensy 3.6 DMA to read multiple digital inputs on pin interrupt.

Status
Not open for further replies.

neltnerb

Well-known member
This thread is originally from https://forum.pjrc.com/threads/4811...rrupt-priorities-USB-transmit-buffer?p=160973 after Yannick's excellent insight that my problem may be solved best with DMA. I am creating a new one specifically about the possibility of using DMA.

What I have is a peripheral ADC which sends data to the Teensy by clocking out a serial clock along with eight parallel data lines. The peripheral is the serial master.

I am thinking now that what I need to do is connect the input signals to the Teensy such that the eight bits are aligned with a physical port, configure it to use DMA to transfer from the PORT to memory, and then set it up to trigger when it sees the edge of the incoming clock line.

I had never heard of DMA prior to today really, so I'd really appreciate some guidance on whether this makes sense and how to do it. I found:

https://github.com/PaulStoffregen/co...3/DMAChannel.h
https://forum.pjrc.com/threads/31541-Interrupt-Jitter

This look extremely promising, but I cannot seem to find documentation for the DMAChannel library and cannot quite follow how it works. It almost seems that if I do the pin connections right I can simply swap the source() and destination() when configuring the DMA and figure out what interrupt to assign to it for an edge trigger. But I don't understand what the transfer size and transfer count are.

I'm also curious if it is possible to turn off the DMA unless the data ready line from the peripheral is low. It uses that to indicate that it is sending data, so I should ignore clock signals if it is not pulled down. I was planning to just check that input pin inside an ISR that reads the input data into a buffer, but DMA is hardware and not sure if that still makes sense.
 
Hello Neltnerb,

to anderstand the lib the best is to read DMAChannel.h & cpp. I suppose that you already found them, if not you can find them there : C:\Program Files\arduino-1.8.5\hardware\teensy\avr\cores\teensy3
But I am not sure that the lib gives the possibility to do all that can be done with the DMA...
And even if yes, anyway, to use this library one must very well understand the DMA mecanic...
Read carrefully the chapters 23 & 24 of https://www.nxp.com/docs/en/reference-manual/K66P144M180SF5RMV2.pdf
One can find more pleasant doc with nice images..., but it is always the same story/music...
I am still reading it (time to time)... In fact, it seems rather "simple"...
The difficulty is that it is boring, see 24.3.4 the same page is repeated 32 times for each "TCD" and just after it is written for experts...
It exists subtil/powerfull mecanisms that provide you the possibility to reprogram by the way (while it works) the DMA module itself , for exemple "scatter/gather", or the source module registers by a DMA transfer from a linked channel...
See https://forum.pjrc.com/threads/3017...tiple-Channel-Acquisition?p=140300#post140300
https://community.nxp.com/servlet/J...configure the eDMA scatter-gather feature.pdf
You might be able to do what you want with this DMA and without cpu ISR...
Start playing with raw low level instructions like : DMA_TCD0_DADDR = (volatile void*) &buffer[n] ; Its is not "portable" but at least you know what you do...

Good luck, Y.
 
Status
Not open for further replies.
Back
Top