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

Thread: Shift register for lots of bits in Teensy 3.6?

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    13

    Shift register for lots of bits in Teensy 3.6?

    I want to shift out thousands of bits from a Teensy 3.6 at 1.6 MHz (to simulate a disk drive). Is there a more convenient way to do this than bit-banging? I've been looking at the manual and it seems that the UART only handles 9 bits, but SPI might work. I'm not particularly looking for code right now, but more looking for advice if SPI is the right way to do this or if there's a better option.
    Thanks,
    Ken

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,216
    I2S might be a good option. The audio library has well tested code for both master & slave modes.

    If you need to sync to an external clock, then obviously you'll want slave mode so Teensy accepts the external BCLK and you'll need to add a divide-by-16 circuit to create LRCLK.

    For master mode, you may or may not be able to get exactly 1.6 MHz on BCLK. The older boards use a combination of limited resolution integer multiply & divide of the CPU clock. If you need finer grain control of the clock speed, using Teensy 4.0 might be a better choice. The newer boards have a dedicated PLL for audio with a 30 bit mult & div which allows for extremely fine control of the audio clock frequency.

  3. #3
    Junior Member
    Join Date
    May 2021
    Posts
    13
    Thanks! I'll give it a try. I definitely wouldn't have thought of using the audio interface :-)

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,216
    One issue you may face is the current audio library code transmits 32 bit words, where we put the 16 bit audio sample into the top half and zeros get sent for the lower half.

    Very old versions of the audio library (still in the github history) used actual 16 bit word size on I2S. Turns out some chips like MEMS mics only work if the BLCK to LRCLK ratio is 64. So the change to 32 bit word size was made for compatibility with those parts.

    If you're looking to just send a continuous stream of bits, you might want to initialize the hardware using that older code.

  5. #5
    Junior Member
    Join Date
    Jun 2021
    Location
    Santa Cruz, CA
    Posts
    1
    Interestingly, I was just contemplating using a Teensy 4.1 for a very similar purpose.

    While I have not implemented anything yet, my current thinking (on the Teensy 4.1) is to use one of the LPSPI interfaces in slave mode, with an external clock to get the exact bit rate required, and a DMA channel to feed the data to it.

    Out of curiosity, what type of disk are you trying to emulate?

  6. #6
    Junior Member
    Join Date
    May 2021
    Posts
    13
    I'm trying to emulate a 1970s-era Diablo 33 disk drive for the Xerox Alto. The bit rate is 3.3 MHz, so hopefully the Teensy 3.6 can handle it. I did some experiments today and bit-banging seems sufficient for shifting the bits out, as long as I disable interrupts. Next step is figuring out how to receive bits.

Posting Permissions

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