How do I synchronizer an asynchronous timer to an external interrupt?
2012-06-08 by ejubenville
On a AT90USB646 chip, I'm trying to restart Timer0 during an external
interrupt, with the goal of synchronizing the subsequent timer
interrupts to the edge of the initial external interrupt. I need to
start a timing sequence following the external interrupt even, and I
need to get rid of the jitter caused by the asynchronous nature of the
timer interrupt.
My interpretation of the chip datasheet is that PSRSYNC is the register
bit that should reset the synchronous timing and achieve the
synchronization I desire, but that isn't working for me. I've also
played with TSM, but that didn't seem to help.
Here is the code for the external interrupt ISR. The timer interrupt
raises and lowers the same port D signal asserted here. I'm able to
watch that port bit on a scope and can see that the timer interrupt
remains asynchronous to the external interrupt.
What am I doing wrong? What is the proper technique to synchronize
the timer interrupt to an external interrupt?
BTW, Timer0 is set up for operation with no prescaler.
// External Interrupt Request 0 (Port Pin D0)
ISR(INT0_vect)
{
// assert port D7 to watch on a scope
PORTD |= (1 << 7);
GTCCR |= (1 << 7); // assert TSM
GTCCR |= (1 << 0); // assert PSRSYNC
GTCCR &= ~(1 << 0); // clear PSRSYNC
GTCCR &= ~(1 << 7); // clear TSM
// clear the interrupt
EIFR |= (1 << 0);
// deassert port D7
PORTD &= ~(1 << 7);
}
[Non-text portions of this message have been removed]