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.

Question regarding using multiple timer interrupts



Hi Everyone,

I have try to setup some timers with interrupt routines to handle the output result.  But the timer didn't work as expected,   With a single interrupt it works fine(Timer0_A0_ISR), but when I try to add more timers with interrupt into the code, the new interrupt didn't work, even the original single one didn't work as well.   Is there anything I should be aware of?

#include <driverlib.h>
#include <msp430.h>

/***************************Timer Configuration Initialization********************************/
// TimerA0 UpMode Configuration Parameter A0 is for routine #0
Timer_A_initUpModeParam initUpParam_A0 =
{
        TIMER_A_CLOCKSOURCE_ACLK,               // ACLK Clock Source 32Khz
        TIMER_A_CLOCKSOURCE_DIVIDER_1,          // ACLK/4 = 8KHz
        120,                                    // timer period
        TIMER_A_TAIE_INTERRUPT_DISABLE,         // Disable Timer interrupt
        TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE ,    // Enable CCR0 interrupt
        TIMER_A_DO_CLEAR,                       // Clear value
        true                                    // Start Timer
};

// TimerA1 UpMode Configuration Parameter A1 is for routine #1
Timer_A_initUpModeParam initUpParam_A1 =
{
    TIMER_A_CLOCKSOURCE_ACLK,                // ACLK Clock Source
    TIMER_A_CLOCKSOURCE_DIVIDER_1,           // ACLK/4 = 8kHz
    2000,                                    // Timer period 0.25 s
    TIMER_A_TAIE_INTERRUPT_DISABLE,          // Disable Timer interrupt
    TIMER_A_CCIE_CCR0_INTERRUPT_ENABLE ,   	 // Disable CCR0 interrupt
    TIMER_A_DO_CLEAR,                        // Clear value
	true									 //start Timer
};

// TimerA2 UpMode Configuration Parameter A2 is for routine #2
Timer_A_initUpModeParam initUpParam_A2 =
{
    TIMER_A_CLOCKSOURCE_ACLK,               // ACLK Clock Source
    TIMER_A_CLOCKSOURCE_DIVIDER_1,          // ACLK/4 = 8kHz
    16,                                     // Timer period output 
    TIMER_A_TAIE_INTERRUPT_DISABLE,         // Disable Timer interrupt
    TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE ,   // Disable CCR0 interrupt
    TIMER_A_DO_CLEAR,                       // Clear value
	true
};


int main(void) {

	WDT_A_hold(WDT_A_BASE);

	PMM_unlockLPM5();

    // Initializations
       GPIO_setAsOutputPin(GPIO_PORT_P2, GPIO_PIN1);  //set as output pin for scope monitoring   
       GPIO_setAsOutputPin(GPIO_PORT_P1, GPIO_PIN0);  //setup for the two output on Luachpad
       GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_PIN7);

       Timer_A_initUpMode(TIMER_A0_BASE, &initUpParam_A0);
       Timer_A_initUpMode(TIMER_A1_BASE, &initUpParam_A1);
       Timer_A_initUpMode(TIMER_A2_BASE, &initUpParam_A2);
    __enable_interrupt();

    while(1){
    	 
    	//__bis_SR_register(LPM3_bits | GIE);   // Enter LPM3, interrupts enabled

    }
   return (0);
}

// Timer A1 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer0_A0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer0_A0_ISR (void)
#else
#error Compiler not supported!
#endif
{
 GPIO_toggleOutputOnPin(GPIO_PORT_P2, GPIO_PIN1);      //Generate Waveform output 
__bic_SR_register_on_exit(LPM3_bits);                //exit LPM3
}

#pragma vector = TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR (void)
{
   GPIO_toggleOutputOnPin(GPIO_PORT_P1, GPIO_PIN0);  //flash LED1
   __bic_SR_register_on_exit(LPM3_bits);                // exit LPM3
}

#pragma vector = TIMER2_A0_VECTOR
__interrupt void TIMER2_A0_ISR (void)
{
   GPIO_toggleOutputOnPin(GPIO_PORT_P9, GPIO_PIN7);  //flash LED2
   __bic_SR_register_on_exit(LPM3_bits);                // exit LPM3
}

The code is running based on MSP430FR6989, CCS6.0 environment.

Thanks ahead!

  • I do not understand why you want the ISR to wake-up the main() which immediately goes back to sleep again. But that is my problems, not yours.

    I suspect your problem is, in effect you only have one ISR, and that ISR is for TIMER1_A0. I cannot follow the rituals of the c compiler and the library you are using. (Again, my problem, not yours.) But the MSP430 chip you are using cannot either. What matters to the chip (and I) is the object code you loaded into the Flash memory. I suspect that you have only one Interrupt Vector in the object code.
  • Hi old_cow_yellow,
    Thank you for the information, I double checked the vector files and the chip definition file, its a little confusing at first but I think now I understand it better. U r right, I did made a mistake by using non-exist vector name.
    After add in the vector in the header file: TIMER1_A0_VECTOR and TIMER2_A0_VECTOR, it is working correct now.

**Attention** This is a public forum