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.

Timer works in Debug mode only

My goal right now is to have a push button trigger an interrupt to turn on the LED for a certain period of time. So I need a timer to shut off the LED once the timer has ran to 0. For some reason my code works like planned in debug mode on CCS, but when I get off debug mode it doesn't work. It seems like the timer interrupt is never called. I am using TIMER0_A0 which I believes clears the source of the interrupt by itself.

Does anyone know what flag I would have reset for this type of timer?

This makes it very frustrating to debug because I can't step through the code.

If any wants to see the code I can provide my program, which is pretty short.

  • Debug operation influences some things on the target MSP. Mainly the clocks. And of course the overall timing.

    Things like LPM work differently when under debugger control. Maybe you're disabling the timer clock and therefore the timer can't run, but in debug mode, the debugger prohibits the clock being disabled?

    Only your code can tell.

  • I don't believe I'm disabling the timer. The only code I have that has to do with the timer is:

    I also increment CCR0 when I enter the interrupt triggered by my pushbutton.

    CCTL0 = CCIE;   //enabling the interrupt

    CCR0 = 50000;

    TACTL = TASSEL_1 + MC_2;    //count down and 12khz

    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer0_A (void) {              

    flag = 0

    }

  • So I fixed the problem, but I am not exactly sure why it works. I switched the timer from ACLK @ 12KHz. to SMCLK @ 1MHz. I did this by switching TASSEL_1 to TASSEL_2. Now  the timer can operate outside of debug mode.

    TACTL = TASSEL_2 + ID_3 + MC_2;

    Thanks.

  • Kim Liu said:
    flag = 0

    Did you declare this ‘volatile’ (volatile unsigned char flag;)?

  • No I just declared i an int flag. I changed the timer, that was the issue of the problem. Now my code works like planned.

  • Then you are lucky but that can change when you alter the program, it should be declared volatile when also used (external) inside an ISR.

  • > I switched the timer from ACLK @ 12KHz.

    maybe aclk is not running.

    Did you select aclk to use internal vlo?

                BCSCTL3 needs LFXT1S_2 to be set

    BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO

    • BCSCTL2 needs to be set

    BCSCTL2 |= SELM_3 + SELS;            // SMCLK  = MCLK = VLO = 12Khz

    • Clear OSC fault flag

    IFG1 &= ~OFIFG;                               // Clear OSCFault flag

    • Turn off DCO if not used

    _BIS_SR(SCG1 + SCG0);                 // Stop DCO

  • Kim Liu said:
    I don't believe I'm disabling the timer.

    Not the timer itself, but the clock that lets the timer tick. If it gets 0Hz clock frequency, it won't count, even if 'running'.

    ACLK is by default running from XT1. No XT1, no ACLK. To use 12Mhz VLO, you'll have to switch ACLK to VLO as described above. However, I'm not sure why it is running then with the debugger attached.

    By switching the timer from ACLK to SMCLK (which is sourced by DCO by default, which is always running), you do provide a clock signal and the timer will count.

  • I'm using the MSP-EXP430F5438 and had a similar problem. Turns out LPM4 works fine in debugger mode but not otherwise. I put the controller in LPM0 mode and now the code works just fine when not in debugger mode.

  • Sudeep Nayak said:

    I'm using the MSP-EXP430F5438 and had a similar problem. Turns out LPM4 works fine in debugger mode but not otherwise.

    Sudeep, I'd describe this situation the other way around:

    In debug mode the MCU is prevented from entering LPM4, so the program appears to work correctly because it is effectively in one of the higher-power modes.

    Without the debugger attached the MCU enters LPM4 as expected. Then whatever bug exists in the program that makes it fail in LPM4 is exposed.

**Attention** This is a public forum