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.

MSP430G2333: Access Independent Timer interrupts for TA0 and TA1, CCR0 & CCR1 & CCR2 & overflow

Part Number: MSP430G2333

Hi,

I'm trying to create independent timer interrupts for TA0 CCR0,1,2 and overflow.  I'm aiming to learn all 8 timer interrupts of timer0_A3 and timer1_A3. I have tried to get 4 interrupts ( ccr0,ccr1,ccr2, overflow ) with timer0 and have not received the TA0CCR2 interrupt. I have used separate pinouts for verification and used this for educational purposes. The code is as follows.

#include <msp430.h>

volatile int k=0;


void main(void){

	WDTCTL = WDTPW | WDTHOLD;		// stop watchdog timer
	P1DIR |= 0xEF;					// configure P1.7 as input
	P2DIR |= 0x01;

    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;

//Timer0...................................................................................
	TA0CCTL2 |= CCIE;                //Timer 1 CCR2 interrupt enabled
	TA0CCR2 = 30000;
    TA0CCTL1 |= CCIE;                // CCR1 interrupt enabled
    TA0CCR1 = 40000;
    TA0CCTL0 |= CCIE;                // CCR0 interrupt enabled
    TA0CCR0 = 5000;
	TA0CTL = TASSEL_2 + MC_2 + ID_3 + TAIE; //overflow enabled
	
//Timer1...................................................................................
    TA1CCTL0 = CCIE;                // timer 2 CCR0 interrupt enabled
    TA1CCR0 = 60000;
    TA1CTL = TASSEL_2 + MC_2 + ID_3;
    
//Port_Interrupt...................................................................................
	P2IES &= (~0x80);               // rising Edge
	P2IFG &= (~0x80);               // Clear interrupt flag for P1.1 and P1.2
	P2IE  |= (0x80);                 //Enable interrupt for P1.3

    _enable_interrupt();


	while(1);
	}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0(void){ //TA0CCR0

    P1OUT ^= 0x01;

}


#pragma vector=TIMER0_A1_VECTOR
__interrupt void Timer0_A1(void){  //TA0CCR1 + TA0CCR2 + OVERFLOW

    switch( TA0IV )
    {
    case  0X0002:
      {
          P1OUT ^= 0x08;
          break;}

    case  0X0004:
    {
          P1OUT ^= 0x10;
          break;}

    case 0x000A:
    {
          P1OUT ^= 0x40;
          break;}

   }

}

#pragma vector = TIMER1_A0_VECTOR  // TA1CCR0
__interrupt void Timer_A1 (void){

    P2OUT ^= 0x01;

}

I want to know the reason for not occurring the ccr2 interrupt. Don't mind about the port interrupt. Any kind of help will be much appreciated. 

  • How do you tell that the CCR2 interrupt doesn't occur?

    I don't have a G2333, but this code operates as expected (including P1.4 wiggling) on a G2553.

    --------------------

    Unsolicited: If you don't have a PORT2_VECTOR, you shouldn't set P2IE. With the pins floating, you may end up in the default ISR, which will get in the way of your experiment.

    Also, be careful with P2.7 (and P2.6) since it's set to an alternate function at reset.

  • Hello Bruce,

    I have attached the port 1 0x10 pin for a LED. When TA0CCR2 occurred, then the 0x10 pin should toggle. The other 3 interrupts (Overflow, TA0CCR0, TA0CCR1) have occurred perfectly as expected. I don't know the reason for not occurring the CCR2. 

    -----------------------------------------------------------------

    P2.6 and P2.7 are used to connect the 32kHz watch crystal. But I do not intend to use ACLK. An important task was assigned to me and because of that, I'm in a tough schedule.  Also, I have used the port 2 interrupt for edge detection purposes and it isn't in float. I updated the code as follows.

    #include <msp430.h>
    
    void Set_DCO(unsigned int Delta);
    #define DELTA_1MHZ    244                   // 244 x 4096Hz = 999.4Hz
    
    volatile int edgedetect=0;
    volatile unsigned int turnoff=0;
    
    void main(void){
    
    	WDTCTL = WDTPW | WDTHOLD;		// stop watchdog timer
    	P1DIR |= 0xEF;					// configure P1.0 as output
    	P2DIR |= 0x01;
    
        BCSCTL1 = CALBC1_1MHZ;
        DCOCTL = CALDCO_1MHZ;
    
    //Timer0...................................................................................
    	TA0CCTL2 |= CCIE;                //Timer 1 CCR2 interrupt enabled
    	TA0CCR2 = 30000;
        TA0CCTL1 |= CCIE;                // CCR1 interrupt enabled
        TA0CCR1 = 40000;
        TA0CCTL0 |= CCIE;                // CCR0 interrupt enabled
        TA0CCR0 = 5000;
    	TA0CTL = TASSEL_2 + MC_2 + ID_3 + TAIE;
    
    //Timer1...................................................................................
       // TA1CCTL0 = CCIE;                // timer 2 CCR0 interrupt enabled
    	TA1CCTL0 = (~CCIE);
    	TA1CCR0 = 62500;
    	TA1CTL = TASSEL_2 + MC_1 + ID_3;
    
    //Port_Interrupt...................................................................................
    	P2IES &= (~0x80);               // rising Edge
    	P2IFG &= (~0x80);               // Clear interrupt flag for P1.1 and P1.2
    	P2IE  |= (0x80);                 //Enable interrupt for P1.3
    
        _enable_interrupt();
    
    
    	while(1);
    	}
    
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer0_A0(void){ //TA0CCR0
    
        P1OUT ^= 0x01;
    
    }
    
    
    #pragma vector=TIMER0_A1_VECTOR
    __interrupt void Timer0_A1(void){  //TA0CCR1 + TA0CCR2 + OVERFLOW
    
        switch( TA0IV )
        {
        case  0X0002:
          {
              P1OUT ^= 0x08;
              //CCTL1 &= ~CCIFG;
              break;}
    
        case  0X0004:
        {
              P1OUT ^= 0x10;
              //CCTL2 &= ~CCIFG;
              break;}
    
        case  0x000A:
        {
              P1OUT ^= 0x40;
              break;}
    
       }
    
    }
    
    #pragma vector = TIMER1_A0_VECTOR  // TA1CCR0
    __interrupt void Timer_A1 (void){
    
        turnoff++;
        if(turnoff==6){
            P2OUT |= 0x01;
        turnoff = 0;}
    
    }
    
    
    
    #pragma vector=PORT2_VECTOR
    __interrupt void Port_2(void)
    {
    	    if(edgedetect % 2 == 0){
    	       
    	        TA1CCTL0 = CCIE;           //RISING EDGE DETECTION.
    	        TA1CCR0 = 62500;
    	        TA1CTL = TASSEL_2 + MC_1 + ID_3;
    	        TA1R = 0;
    
    	    }else{
    	        TA1R = 0;
    	        P2OUT = 0x00;
    	        turnoff = 0;
    	        TA1CCTL0 = (~CCIE);       //FALLING EDGE DETECTION.
    
    	    }
    	    P2IES ^= 0x80;      // edge detection toggle
    	    P2IFG &= ~(0x80);
    	    edgedetect++;
    	}
    
    
    
    
    

    Need to know about the CCR2 problem. Thank you for the reply. 

  • Twiddling an output pin is a pretty simple thing to do but I wouldn't jump straight to why didn't the interrupt happen. First I would set a breakpoint in the ISR to see if it happened but the pin didn't toggle or if for some reason a debugger isn't available, swap pins.

  • For P1DIR |= 0xEF; it seems not enable the out put for P1OUT ^= 0x10;. 

**Attention** This is a public forum