I have an external interrupt that kick offs when a pin change occurs. In the the handler, I do timer1.getCount to determine the period and pulse width. The signal that I have as input is 1 kHZ 50% duty cycle. I set up the timer in the setup() as follows:
// ...
timer1.setChannel1Mode(TIMER_OUTPUT_COMPARE);
timer1.pause();
timer1.setCount(0);
timer1.setPrescaleFactor(72); //run at 72 MHz/72 = 1MHz count every 1us
timer1.setOverflow(65535);
timer1.setCompare1(1);
timer1.attachCompare1Interrupt(timer1_handler);
timer1.refresh();
timer1.resume();
Sample handler code:
void exti_handler()
{
timer1.pause();
CurrentCount = timer1.getCount();
val = digitalRead(0);
if (val == HIGH)
{
LowToHighCount++;
Period = CurrentCount;
timer1.setCount(0);
timer1.refresh();
}
else { // state must be LOW
HighToLowCount++;
PulseWidth = CurrentCount;
}
timer1.resume();
}
timer interrupt is just adding up a timercounter which does nothing
Any guidance or thoughts?