This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Connecting the comparator to the timer MSP430G2553

Other Parts Discussed in Thread: MSP430G2553

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;
}
}

  • The G2553 has two timers, Timer0_A3 and Timer1_A3.

    Each timer has three capture/compare registers, the output signals of which are called TA0.0, TA0.1, TA0.2, TA1.0, TA1.1, and TA1.2.
    There are many similar names, but you always have to keep in mind whether a number specifies the timer or the CCR.

    Your code uses the registers of timer 1, but the interrupts and IV register of timer 0.

    Note: only timer 0 CCR 1 can be connected to the comparator.

  • Timer 1 was picked because the documentation for comparator only refers to CCI1B, and that name is not found in the header file or in any timer documentation. The '1' indicated this was timer '1', not timer '0' . Where do I find the right documentation?
  • The "1" in "CCI1B" refers to the "1" in "CCR1". (Please note that the name of this module input is the same for Timer0 and Timer1; this name must be seen in the context of a specific timer.)

    Page 16 of the MSP430G2553 datasheet shows that the only capture/compare input that CAOUT can be connected to is CCI1B of CCR1 of Timer0.

**Attention** This is a public forum