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.

CCS/MSP430F2619: could not capture higher than 20KHz

Part Number: MSP430F2619

Tool/software: Code Composer Studio

Dear team

The MSP-TS430PN80 target motherboard uses the MSP430F2619 chip with 4M external crystal oscillator.

The timer timerB cannot accurately capture frequencies exceeding 20K.

Please help

void SetupClock()
    uint16_t tmpv;
    BCSCTL1 &= ~XT2OFF;         
    BCSCTL3 |= XT2S_2;         
        IFG1 &= ~OFIFG;           
        for (tmpv = 0xff; tmpv > 0; tmpv--);
    while((BCSCTL3 & XT2OF) == 1);    
    BCSCTL2 |= SELM_2+SELS;           

void Capture_Pos(void)//TIMER_B  
    TB0CTL |= TBSSEL_2 + ID_0 + MC_2 + TBCLR + TBIE;

#pragma vector = TIMERB0_VECTOR
__interrupt void Timer_B0 (void)
    static double Pre_T_Frequency = 0;
    if(TBCCTL0 & CM0)
        if(T_CaptureNum == 1)
            T_cap_count_first = TBCCR0;
        }else if(T_CaptureNum >= 2)
            T_cap_count_second = TBCCR0;
                T_count_num = T_cap_count_second-T_cap_count_first;
                T_count_num = 0xFFFF+T_cap_count_second-T_cap_count_first;
            T_Frequency = ((float)4000000)/T_count_num;
            T_CaptureNum = 0;

            if(T_Frequency != Pre_T_Frequency)
                Pre_T_Frequency = T_Frequency;


  • 1) What speed is the crystal? That's what decides how fast SMCLK is.

    2) This ISR is very heavyweight, and is probably overrunning at high signal frequencies. Just fetch the new CCR0, do the subtraction and store the result in a global, and return. Let main do the rest of the arithmetic. You may miss a few results (step response), but the ISR won't miss any captures.

    > new = TBCCR0;

    > result = new - previous;

    > previous = new;

    3) If you store T_cap_count_first/_second (and T_count_num) in uint16_t (unsigned int) variables, you can just subtract them without worrying about wrapping. Unsigned-underflow will do the right thing.


    >    while((BCSCTL3 & XT2OF) == 1);

    This condition is always false, since XT2OF==2. I expect you intended something like:

    >    while((BCSCTL3 & XT2OF) == XT2OF);

  • Bruce McKenney47378 said:
    1) What speed is the crystal? That's what decides how fast SMCLK is.


  • OK. As I said in the other thread, I think 80kHz with a 4MHz clock is feasible, with careful coding. Above that you probably want to consider frequency counting with TBCLK. Don't forget to leave some CPU time to actually do something with the result.

    You should make sure the crystal oscillator is actually engaging, since the fault-reset loop may be exiting early. (I forget what the F2 does in this case.)

    Also, I suggest using scaled-integer arithmetic rather than floating point. 32-bit arithmetic is pretty fast, particularly compared to float.

  • Hello Susan,

    please let us know, in case you still need support on this. Many thanks in advance.

    Best regards