I have a pin that will receive a clock pulse. I need to identify when the clock is pulsing, and when the clock isn't pulsing.
Can someone offer a suggestion on the best way to identify if my pin is pulsing or not? Additionally I'd like the state change to trigger an interrupt if at all possible.
Sounds like an unusually tough homework assignment. Are you expecting any particular duty cycle at the pin and what do you want to do in the interrupt service routine ?
Not homework. Just another angle of attack on a project that's been stumping me for 2 weeks.
The clocks are very regular with a duty cycle close to 50% and a period of just over 7us.
Ultimately, I want to know when the clock has finished pulsing so I can reset counters and other associated variables that are being used in the clock pins ISR.
I am trying to emulate the receiving end of a very unique serial protocol that does not fit anything that currently exists. Despite many suggestions to try SPI, it simply doesn't work for this.
The clock will pulse for X time, but in the first 8 pulses, I need to poll the data line for its state, therefor capturing a byte. Then after the clock stops pulsing, I need to set some flags, clear some counters, and then prepare to drive the data line when the clock starts pulsing again, therefor sending a byte back to the original sender.
If you must know, I'm attempting to hack the cd-changer network of an ancient model Clarion Head unit. I have a very good document explaining the protocol, and so far the data I've sniffed is consistent with the documents descriptions.
I know it can be done, because i've seen it in a video, and of course there's this document, but the document is explaining the bitwise serial transfers, and the command byte protocols, but doesn't go in to any detail about code or example routines or anything. So i'm on my own.
That does sound more interesting than homework. If I was doing this for an Arduino, and the frequency was not so high (it looks like you are working with around 140 KHz ) , I'd consider doing something like this:
volatile unsigned long pulseCount = 0 ;
volatile unsigned long pulseReceivedMicros = 0 ;
ISR() {
// ISR triggered on riding edge
pulseReceivedMicros = micros() ;
if pulseCount < 8 {
// handle pulses 0 .. 7
}
else if ( pulseCount == 8 ) {
// handle pulse 8
}
else {
// pulses > 8
}
pulseCount ++ ;
}
void loop() {
if ( micros() - pulseReceivedMicros > 20 && pulseCount > 0 ) {
// detected 20 uS pause in pulses. Handle end of pulse burst
pulseCount = 0;
}
}
I don't know the 32bit Arm processor you are using, but that might handle the frequency. I guess there are also other options like using an external chip to count the first 8 pulses.