Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: Read 16 pins with DMA on 3.5/3.6

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    9

    Read 16 pins with DMA on 3.5/3.6

    I'm working on a 16x16 button grid using 595 shift registers but still need 16 input pins on the teensy. I can obviously do this a little more manually, and maybe even get lucky by aligning those 16 pins with 1 or more complete ports to be read directly. But I keep seeing that the Teensy 3.5/3.6 has a bunch of DMA channels which seems like it would be the most efficient way to very quickly read those 16 pins (please tell me if I completely misunderstand what DMA can do). But I can't find any real details on how to actually program the DMA channels anywhere. Are there any tutorials somewhere?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,929
    DMA can be tough to learn & troubleshoot. There aren't any great tutorials. There is quite a bit of info and code to help in DMAChannel.h. Libraries like Audio and OctoWS2811 have code you can read. There's also the chapter in the reference manual with all the detailed documentation.

    Unfortunately there aren't a full 16 bits of any port exposed, so you can't really get a simultaneous 16 bit read. You could configure the minor loop to perform two 8 bit reads from different ports, which would get those 2 reads very close together in time.

    The DMA controller spends many clock cycles setting up a transfer, and many more saving all the state. Multiple channels can be used to accomplish all sorts of wonderful things, but you can't get really rapid back-to-back transfers. There's always ~ 0.2 us latency between one channel to another, due to how the controller loads & saves the TCD parameters and does other setup and teardown work.

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    9
    Ah, interesting. Didn't realize that DMA required that many cycles just for setup. Then again my general understanding of it was more of the "magic" variety.
    Non-DMA should probably work fine, but are there 16 bits worth of ports (either 2 registers or 1 big one) that I could use for the 16 bit read? In AVR chips I'm used being able to just connect to pins that correspond to the contiguous bits of a single port register and then just read that 8bit register value instead of using digitalRead() 8 times.

  4. #4
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,002

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •