Trying to time a race. The timing ends when the comparator goes low.
The comparator works. The timer A1 starts just fine. I can catch the comparator going low with code in a loop, and look at the count of the timer. I have set up the timer CCTL1 to catch the timer edge going low. The interrupts are not triggered either.
Is somethign missing? Followed the manual, but could not find any example code.
Thanks.
--------------------------------
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_16MHZ; // Set range 16MHz
DCOCTL = CALDCO_16MHZ; // Set DCO step and modulation
P1DIR |= BIT5+BIT7; // BIT5 for charging cap. BIT7 output of comp
CACTL1 |= CARSEL+CAREF_3 +CAIES+CAIE+CAON; // Diode, falling edge, interrupt enable, on
CACTL2 |= P2CA4; // input select
CAPD |= CAPD1; // disable input buffer on pin
// timer1 to catch comparator P2.2/TA1 CCI1B
TA1CCTL0 = OUTMOD_0 + CCIE; // CCR1 toggle, interrupt enabled
TA1CTL = TASSEL_2 + MC_2 + TAIE; // SMCLK, Contmode, int enabled
TA1CCTL1 = CCIS_1 + SCS + CAP + CCIE; // listen to comparator
TA1CCTL1 |= CM_2; // enable neg edges
while (1) {
P1OUT |= BIT5; //0x10; Output is high
__delay_cycles(40000); // divide by MHz to get us. 8000cyc = 500us
P1OUT &= ~BIT5; // Output is low
// reset timer to 0.
TA1R = 0;
// Enter LPM0 w/ interrupt
//__bis_SR_register(LPM0_bits + GIE); // Wait with this until bugs fixed
i = DELAY;
while(i--) {
if ((CAOUT & CACTL2))
P1OUT |= BIT7; // if CAOUT set, set P1.7
else {
P1OUT &= ~BIT7; // else reset
count = DELAY-i;
timer[j++ ] = TA1R;// TA1CCR1;
j %= TSIZE-1;
i = 0;
}
}
}
return 0;
}
// Timer A0 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A0 (void)
#else
#error Compiler not supported!
#endif
{
CCR0 += 200; // do something
}
// Timer_A1 Interrupt Vector (TA0IV) handler
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer_A1(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) Timer_A1 (void)
#else
#error Compiler not supported!
#endif
{
itimer = TA1CCR1;
switch( TA0IV )
{
case 2: CCR1 += 1000; // Add Offset to CCR1
break;
case 10: P1OUT ^= 0x01; // Timer_A3 overflow
break;
}
}