Other Parts Discussed in Thread: MSP430F2272
Greetings,
I am trying to measure a 1Hz signal to the full resolution of the 16MHz clock on a MSP430F2272. My code looks like this (I have omitted the setup, which I got Grace to do for me anyway).
uint16_t ovf_counter;
uint32_t prev_a;
uint32_t period_a;
int main(int argc, char *argv[]) {
CSL_init(); // Activate Grace-generated configuration
ovf_counter = 0;
prev_a = 0;
period_a = 0;
__enable_interrupt(); // Set global interrupt enable
sciPrintf("\nPPS pulse comparator.\n\n");
while(1) {
if(period_a) {
printf("A: %lu\n", period_a);
period_a = 0;
}
}
}
void intrTaComp0(void) {
const uint32_t t = (((uint32_t)ovf_counter) << 16) | TACCR0;
period_a = t - prev_a;
prev_a = t;
}
void intrTAOvf(void) {
++ovf_counter;
P1OUT ^= 1;
}
As you can see I count overflows in one handler, and handle captures with the other. However, every so often, a period reading is exactly 1 overflow period out. I think that this is because the capture interrupt is running after an overflow but before the overflow interrupt handler has incremented the overflow counter. How can I check if there is a pending non-handled overflow interrupt? There isn't a specific flag for it, as TAIFG is shared between CCR1, CCR2 and OVF.