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.

MSP430F247 : TimerB in capture mode for 3 inputs



Hi,

I've a board with 3 signals connected on P4.1, P4.2 and P4.3.

I want to measure frequency of these signals, by configuring 3 intputs in compare mode, with interrupt on rising edge.

If I understand, there's only one interrupt (TimerB1_Vector)

My code doesn(t work, i never go in interrupt, signal is present and toggle (scope), but MSP430 doesn't see rising edge :

COuld you help me by reviewing following code? Is there an example somewhere with more than one signal used in capteur mode?

Thanks in advance

Init code :

P4DIR = 0x00;

P4SEL = 0x0E

TB0CCTL1 = CM_2 + CCIS_1 + CAP + CCIE;

TB0CCTL2 = CM_2 + CCIS_1 + CAP + CCIE;

TB0CCTL3 = CM_2 + CCIS_1 + CAP + CCIE;

Interrupt Code :

#pragma vector = TIMERB1_VECTOR
    __interrupt void Timer_B1 (void)
    {
        switch(TBIV)
         {
                  case  TBIV_NONE: break;              // Vector  0:  No interrupt
                  case  TBIV_TBCCR1:                   // Vector  2:  TBCCR1 CCIFG
                      // Rising Edge was captured
                      if (!Count1)
                      {
                          R1Edge1 = TB0CCR1;
                         Count1++;
                      }
                     else
                     {
                         R1Edge2 = TB0CCR1;
                         Count1=0x0;
                    }
                  break;
                  case  TBIV_TBCCR2:                   // Vector  3:  TBCCR2 CCIFG
                      // Rising Edge was captured
                      if (!Count2)
                      {
                          R2Edge1 = TB0CCR2;
                         Count2++;
                      }
                     else
                     {
                         R2Edge2 = TB0CCR1;
                         Count2=0x0;
                    }

                  default:     break;
              }
    }

  • What is the settings in TB0CTL register?
    Is GIE bit in SR set?
  • Without initializing TB0CTL, the timer does not run.
  • I've initialized Timer B in running mode,using SMCLK, continuous mode

    TBCTL = TBSSEL_2 + MC_2;

    Isn't enough?

    I consider an interrupt arriving each new edge detected, and after input recognition by using switch (TBIV), I'll copy value of TB register.

    Still doesnt' work, any idea, or sample code?

  • Are there any other parts of the init code you have not shown, or does your code actually not set the GIE bit?
  • After initialisation, enabling Interrupt is done :

    _BIS_SR(GIE);
  • CM_2 is falling edge, but this should not matter.
    Do you get an interrupt if you try to raise one manually by toggling between CCIS_2 and CCIS_3?
  • I never see interrupt rising on TimerB !! Physical signal is arriving, around 5kHZ on P4.1, P4.2, P4.3

    Here is all my code : I just init timer A to have 100ms scheduler for led toggle. Led Toggle is OK, Timer A is OK, but TimerB NOT!!!! No interrupt rising

    volatile uint16_t tick_100ms = 0, tick_1ms = 0;
    void main(void) {
    uint16_t temp_u16, NbCycles100ms;

    //disable_watchdog();
    WDTCTL = WDTPW+WDTHOLD;

    //Clock configuration : External 8MHz Crystal on XT2 and ACLK = VLO
    BCSCTL1 = 0x0A; //XT2 = ON + XTS = LF + DIVA = 0 + RSELx = A
    BCSCTL2 = 0x88; //SELMx = 10 + DIVMx = 0 + SELS = 1 + DIVSx = 0 + DCOR = 0
    BCSCTL3 = 0xA0; //XT2Sx = 10 (3 to 16 MHz) + LFXT1S = 10 (VLOCK) + XCAPx = 00 + XT2OF = 0 + LFXT1OF = 0

    // P3.1 et P3.2 as output : toggle Led
    P3DIR = 0x06;

    P4SEL = 0x0E; //Pin 4.1, 4.2 et 4.3 special function enable
    P4DIR = 0x0; //As input

    // TimerA Init (1kHz base time)
    TACTL = TASSEL_2 + MC_1 + TAIE; // SMCLK, upmode, interrupt
    TACCR0 = 0x1F40;
    // TimerB : input frequency measurement
    TB0CCTL1 = CM_2 + CCIS_1 + CAP + CCIE;
    TB0CCTL2 = CM_2 + CCIS_1 + CAP + CCIE;
    TB0CCTL3 = CM_2 + CCIS_1 + CAP + CCIE;

    TBCTL = TBSSEL_2 + MC_2;
    _BIS_SR(GIE); //Enable interrupts

    //Main loop
    while (1)
    {
    temp_u16 = tick_100ms;
    NbCycles100ms++;
    if (NbCycles100ms%2) {
    P3OUT &= ~0x06;
    }
    else{
    P3OUT |= 0x02;
    }
    while (temp_u16 == tick_100ms){}; //Wait until end of current cycle
    }
    }
    //END main

    #pragma vector = TIMERA1_VECTOR
    __interrupt void Timer_A(void)
    {
    switch( TAIV ){
    case 2: break; //CCR1 not used
    case 4: break; //CCR2 not used
    case 10: {

    tick_1ms += 1;

    if (tick_1ms == 99){
    tick_1ms = 0;
    tick_100ms += 1;
    }
    } break;

    default: break;
    }
    }

    #pragma vector = TIMERB1_VECTOR
    __interrupt void Timer_B1 (void)
    {
    switch(TBIV){
    case TBIV_NONE: break; // Vector 0: No interrupt

    case TBIV_TBCCR1: // Vector 2: TBCCR1 CCIFG
    // Rising Edge was captured
    if (!Count1)
    {
    R1Edge1 = TB0CCR1;
    Count1++;
    }
    else
    {
    R1Edge2 = TB0CCR1;
    Count1=0x0;
    }
    break;
    case TBIV_TBCCR2: // Vector 3: TBCCR2 CCIFG
    // Rising Edge was captured
    if (!Count2)
    {
    R2Edge1 = TB0CCR2;
    Count2++;
    }
    else
    {
    R2Edge2 = TB0CCR1;
    Count2=0x0;
    }
    break;

    default: break;
    }
    }
  • ANy idea, or sample Code?

    Is there somebody using capture mode?

**Attention** This is a public forum