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

Thread: Reading and writing words on Teensy 4.0

  1. #1

    Reading and writing words on Teensy 4.0

    I have to use an external 10 bit A/D on my project because the internal one is not fast enough. I was going to have the A/D stuff data into a FIFO memory but I am finding that these chips are difficult to work with and do not have 10 bits. So I want to create a little test code to see how fast I can read a 10 bit word off the data bus, 20 times, and put those in a 20 word array in RAM. I am guessing that writing to RAM will be the fastest way to do this (vs EEPROM or FLASH). I need to do all 20 reads and writes in 2 us. to make this work.
    Also, I know there are some added commands for Teensy such as digitalwritefast. Is there a listing somewhere of all these extra commands? I don't see any 16 bit word commands in the Arduino code, just byte and bit commands.
    Thanks, I have only minimal C experience.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,699
    Follow the links in this post - one should demo a port read of all the pins on that port :: Teensy-4-1-8-Bit-Parallel-I-O

    That post is from mid 2020 - there may be other newer posts but IIRC at least one demonstrated reading as desired.

    On Teensy 4.x port reads are 32 bit reads - all I/O on that port - where you want to pick one with 10 on the same port - if possible or two as may be needed on T_4.0.

    Pins are distributed across the board for the function they provide - not by Port association. There are tables of association or reading the T_4.0 schematic will show the port index bit going to pins.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,699
    There is this page with a sample sketch that should run and provide a table of the PIN to PORT mapping :: TeensyUser/doc/wiki/Mapping-Pins-to-Ports

    Look around there perhaps for port read usage? I didn't see it showing up ...

    @luni - is there a section with demo of parallel port read and write on Teensy 4.x?

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,699
    Found this newer post that may work as a faster example: Teensy-4-0-PORT-manipulation-to-read-write-data-to-multiple-pins

    Shows port read from ordered pins and masking to get the value. Post #9 there noted it takes 9 cpu cycles - including the masking the bits into place,

  5. #5
    @defragster Thanks for the quick and detailed response. There is a lot going on here. I will have to study the code and try a few examples.
    If it takes 9 cycles, how long is that at 600 MHz clock speed? Is it 1/600 million seconds per cycle?

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    897
    The T4 is a dual issue processor so you can get upto 1200 million instruction cycles per second with luck,
    but yes the clock period is 1.67ns = 1/600000000s, so 9 clocks is 15ns

Posting Permissions

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