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.

msp430 3 different timer interrupt

Other Parts Discussed in Thread: MSP430F247

#include "in430.h"
#include "io430.h"

unsigned char i ;

void main( void )
{
  
  WDTCTL = WDTPW + WDTHOLD;
  DCOCTL=CALDCO_1MHZ;
  BCSCTL1=CALBC1_1MHZ;
  
  P1OUT = 0x00;
  P1DIR = 0xFF;
  P4OUT = 0x00;
  P4DIR = 0xFF;
  P2OUT = 0x00;
  P2DIR = 0xFF;
  P3OUT = 0x00;
  P3DIR = 0xFF;

  
  TBCCR0=20000;
  TBCCTL0=CCIE;
  TBCTL=TBSSEL_2 + MC_1 + TBIE;
  
  TA0CCTL0=CCIE;
  TA0CCR0=10000;
  TA0CTL=TASSEL_2 + MC_1 + TAIE;
  
  TACCTL1=CCIE;
  TACCR1=30000;
  TACTL=TASSEL_2 + MC_1 + TAIE;
  
  
  
  _BIS_SR(GIE);
   for(;;);
  
}


#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A0 (void)
{
i++;
if(i==100)
{
P1OUT_bit.P0 ^=1;
i=0;
}
TACTL_bit.TAIFG = 0;
}

#pragma vector=TIMERB0_VECTOR
__interrupt void Timer_B0 (void)
{
  
i++;
if(i==100)
{
  P4OUT_bit.P0 ^=1;
i=0;}

TBCTL_bit.TBIFG = 0;}

#pragma vector=TIMER0_A1_VECTOR
__interrupt void timera1 (void)
{
  switch (__even_in_range(TAIV, 10))
  {
     case  2: i++;
if(i==100)
{
P1OUT_bit.P2 ^= 1;
i=0;
}
 TACTL_bit.TAIFG = 0;break;}            
  
  
     
  }


I want to make 3 different timer interrupt...I' m trying this code for msp430f247..Also I practice in proteus..
TA0 and TB0 is working but TA1 not working..
But when I change the  TACCR1=30000;  as   TACCR1=10000;  only TA1 is working and the other timer interrupt not working...
How can I solve this problem??

  • In Up mode (MC_1), the counter only counts up to CCR0, so if CCR1 > CCR0, CCR1 will never trigger.

    You've enabled the TBCTL:TBIE interrupt, but I don't see TIMER0_B1_VECTOR. You're only succeeding by clearing the TBIFG in the CCR0 interrupt, effectively never using TBIE. I suggest you not set TBIE (or TAIE, for that matter) at all.


    More generally: You're mixing the "old" and "new" timer naming conventions. By convention TACTL is identical to TA0CTL, TACCR1 to TA0CCR1, and TIMERA0_VECTOR to TIMER0_A0_VECTOR. As a result, you have some redundant code, and you may be confusing yourself unnecessarily. I suggest you stick with one convention (I recommend the latter one).

  • When I was beginning to use Timer Interrupt Service Routines, this was always confusing to me too.

    It helped me the most to write down all the different Interrupts for the Timers, they are always mentioned in the first pages of your corresponding Datasheet.

    Timer0 ISR always triggers on the TCCR0, and the other capture compare Registers trigger the other Timer ISRs like TimerA1 , A2... corresponding to TCCR1, TCCR2 etc...

    One thing you can always do is write small programs and go in Debugview with breakpoints, then you will see easily what ISR you are triggering with what ControlRegister settings.

    I hope it gets a little clearer or at least a good starting point.

    seb

  • Can you send me true code with changing my code...Because I researched about different timer but I didnt find..Please help me..

  • I do not know which compiler you use and what the header files say.

    But it appears that you have enabled 6 interrupts. But depends on the header file, 2 of the 6 may be the same.

  • ali yilar said:
      ...
      TBCCR0=20000;
      TBCCTL0=CCIE;
      TBCTL=TBSSEL_2 + MC_1 + TBIE;
      
      TA0CCTL0=CCIE;
      TA0CCR0=10000;
      TA0CTL=TASSEL_2 + MC_1 + TAIE;
      
      TACCTL1=CCIE;
      TACCR1=30000;
      TACTL=TASSEL_2 + MC_1 + TAIE;
      ...
      
    

    TA0CTL may be the same as TACTL

  • I 'm using Iar embedded..

**Attention** This is a public forum