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

Thread: Clocking in Individual Bits

  1. #1
    Junior Member
    Join Date
    Apr 2016

    Clocking in Individual Bits

    I'm trying to clock in 61 bits which are purely multiplexed data (no communication protocol - pure bits). It has a corresponding clock signal. I've largely had success by running an interrupt routine by taking the clock rising edge and then reading the bit on DATA_PIN, but I fear it is not robust. I do get transients where bits seem to be a little garbled which is what I'm trying to fix.

    The clock runs at approximately 60 kHz. The teensy 3.2 is overclocked at 96MHz. This gives me approximately (1 / 60e3 ) / (1 / 96e6) = 1600 clock cycles to obtain the bit before the next rising edge occurs. I'm not entirely sure if this is sufficient.

    I know the Arduino has a ShiftIn() function in its API but I do not see one for the Teensy. Does anyone have suggestions for this?



  2. #2
    Senior Member
    Join Date
    Nov 2012
    1600 clock cycles is plenty.
    Do you know for sure that the data bit is valid on the rising edge? Maybe you should be using the falling edge?


  3. #3
    Senior Member Jp3141's Avatar
    Join Date
    Nov 2012
    What is the setup & hold time of your data bits ? -- how long between the change in a data bit and a (rising) clock edge ?

    Perhaps the Teensy is too fast - if the signal rise or fall times are too slow, then the Teensy may be reading the data while this signal is still changing. Try adding a small delay in the interrupt routine.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Maybe look at the PS2Keyboard library? It uses attachInterrupt() to listen for the clock edges, and then digitalRead to grab the data shortly after the clock changes.

    That might be a little slow for 60 kHz, but things like FASTRUN and digitalReadFast should help, if it can't keep up. But there's a good chance it'll be fast enough, so give it a try first...

Posting Permissions

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