Clocking in Individual Bits

Status
Not open for further replies.

anikhanj

New member
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?

Thanks,

Amar
 
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?

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