Shift register for lots of bits in Teensy 3.6?

Status
Not open for further replies.

shirriff

Member
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
 
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.
 
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.
 
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?
 
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.
 
Status
Not open for further replies.
Back
Top