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.

MSP-EXP430F5529LP: Handling of timer and button interruptions

Part Number: MSP-EXP430F5529LP
Other Parts Discussed in Thread: MSP430WARE,

Hi. I'm writing a program that should turn on and off a DC-DC converter through a push button on MSP430F5529LP. The button is associated with an interrupt routine. The PWM control function is executed within the TIMER_A5 ISR. My idea is to pause and start the timer from within the button's ISR. At startup the timer counter does not start automatically, the MSP gets LPM0, so I press the button and its ISR runs, Timer_A_startCounter() triggers the timer, and the ISR of the timer runs.

The problem is that pressing the button again does not bring the execution to the ISR of the button in order to turn the converter off. My error is in handling the interrupts. I don't know if it's a matter of priority.

Below is the code from which I removed some parts to facilitate your analysis.

Thank you.

int main(void)
{
    // lots of initialiation and DRV code....
    // Enable interrupts globally
    __enable_interrupt();  
    //Enter LPM0, enable interrupts
    __bis_SR_register(LPM0_bits + GIE);
    __no_operation();
    while(1)
    {
        __bis_SR_register(LPM0_bits + GIE);   // Enter LPM0 and wait for an interrupt
        __no_operation();

    };
}

#pragma vector=TIMER0_A1_VECTOR // Timer0_A5 CC1-4, TA
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(TIMER0_A0_VECTOR)))
#endif
void TIMER0_A1_ISR(void)
{
    //Any access, read or write, of the TAIV register automatically resets the
    //highest "pending" interrupt flag
    switch(__even_in_range(TA0IV,14))
    {
    case  0: break;                              //No interrupt
    case  2: break;                              //CCR1 not used
    case  4: break;                              //CCR2 not used
    case  6: break;                              //CCR3 not used
    case  8: break;                              //CCR4 not used
    case 10: break;                              //CCR5 not used
    case 12: break;                              //CCR6 not used
    case 14:
            moduladorPWM();
	    __bic_SR_register_on_exit(LPM0_bits + GIE);
	    break;
    default: break;
    }
}

#pragma vector=BUTTON1_VECTOR
__interrupt void Button1_ISR (void)
{
    WORD i;

    if (GPIO_getInterruptStatus (BUTTON1_PORT, BUTTON1_PIN)){
        for (i = 0x23FF; i > 0; i--){ //Cheap debounce.
        }
        if (GPIO_getInputPinValue(BUTTON1_PORT, BUTTON1_PIN)){
            bButton1Pressed = TRUE;
        }
    }

    // Turn on
    Timer_A_startCounter(TIMER_A0_BASE,TIMER_A_UPDOWN_MODE);
    // Liga o Led 2 Verde - porta 4.7
    GPIO_setOutputHighOnPin(4,0x80);
    // Enable DRV - MSP4305529LP P2.6 output-low
    GPIO_setOutputHighOnPin(2,0x40);

    // Turn off
    // Flag treatment
    // Timer_A_stop(TIMER_A0_BASE);

    GPIO_clearInterrupt(BUTTON1_PORT, BUTTON1_PIN);
    __bic_SR_register_on_exit(LPM0_bits + GIE);   //Wake main from LPMx
}
  • I'm afraid you might have cut out more code than you intended.

    As coded here, the action taken for each button press is the same, without any distinction between alternate (on/off) presses.

    Also, I'm guessing your button is active low, but bButtonPressed is only set if the pin goes back high within the debounce period.

    How long is the original code? Maybe it will fit.
  • Bruce McKenney47378 said:
    As coded here, the action taken for each button press is the same, without any distinction between alternate (on/off) presses.

    Yeah, it's the same for now. I unpacked the semaphore implementation with the bButtonPressed variable and other flags to track the code with breakpoints. In that case, it is not important to treat on / off for now, just enter the button's ISR to verify that it works.

    Bruce McKenney47378 said:
    Also, I'm guessing your button is active low, but bButtonPressed is only set if the pin goes back high within the debounce period.

    I do not see a problem with that. In the current version, the variable bButtonPressed is not used as a condition in any statement. As I said, in the first click the ISR of the button is executed, after the timer starts to run with interrupt, the button don't enter the ISR anymore.  

    Bruce McKenney47378 said:
    How long is the original code? Maybe it will fit. 

    The timer interrupt was made with extracts from the example codes: MSP430Ware_3_80_00_06 \ driverlib \ examples \ MSP430F5xx_6xx \ timer_a \
    timer_a_ex3_continousModeOperationWithTAIEInterrupt.c,
    timer_a_ex4_pwmMultipleUpDown.
     
    I am inserting the interrupt functions for button of code OutOfBox_EmulStorageKeyboard dedicated to MSP430F5529LP for USB communication:
    MSP430Ware_3_80_01_01 \ examples \ boards \ MSP-EXP430F5529LP \ MSP-EXP430F5529LP_Software_Examples \ Firmware \ Source \ OutOfBox_EmulStorageKeyboard.

  • Hi Rafael,
    Check you interrupt flags after the ISR, is the button's flag still high? If so, you may want to try clearing it before exiting the ISR.

**Attention** This is a public forum