I am trying to time stamp rising edges using Timer1. I believe I have enabled interrupts on detection of the rising edges, and on overflow of the 16 bit counter. Overflow interrupt seems to be fine, but I don't seem to get any capture interrupts. When I waggle port B, least significant bit, marked as digital pin 8 on my Arduino Leonardo, I'm expecting the capture interrupt servicing routine to trigger, but diagnostic says that's not happening. Is there another I/O register bit that I have to write? It is OK to hit the pin with 0V & +5V, isn't it? I was driving it from a standard logic gate carrying a square wave, but have since resorted to touching the power rails. I was hoping to read PORTB as a straight digital input port to confirm arduino is seeing different input levels, but it doesn't seem to. I haven't blown the input buffers, have I? Here's my code:-
const float cfOverflowSecs = 0.032768;
const unsigned int cuPrintMax = 30;
volatile float fRunTime;
volatile unsigned int uPrintCount;
volatile float fLoopCount;
void setup()
{
fRunTime = 0.0;
uPrintCount = 0;
Serial.begin(9600);
TCCR1A = 0; // Normal counting mode
TCCR1B = B010; // Setup Prescale to 0.5usec per tick
bitSet(TCCR1B, 6); // Enable Input Capture
bitSet(TIMSK1, 0); // Enable Interrupt for Timer1 overflow
bitSet(TIMSK1, 5); // Enable Interrupt for Timer1 capture ???
}
void loop()
{
if(uPrintCount >= cuPrintMax)
{
uPrintCount -= cuPrintMax;
OneSecond();
fLoopCount = 0;
}
else
{
fLoopCount++;
}
}
ISR(TIMER1_OVF_vect)
{
uPrintCount++;
fRunTime += cfOverflowSecs;
}
ISR(TIMER1_CAPT_vect)
{
Serial.print(fRunTime);
Serial.print(" ");
Serial.println("Capture Event");
}
void OneSecond()
{
Serial.print(fRunTime);
Serial.print(" ");
Serial.print(fLoopCount);
Serial.print(" ");
Serial.print(DDRB);
Serial.print(" ");
Serial.print(PINB);
Serial.print(" ");
Serial.println("Hello World");
}