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.

MSP430F2013 Timer Control

Other Parts Discussed in Thread: MSP430F2013, MSPWARE, MSP430WARE

I am figuring i am missing something small here. I am using code composer V6 with an MSP430F2013 chip. i am simply trying to create a clock using an internal counter and it seems to work however the interrupts seem to fail.

for my clock i have DCOCLK as MCLK running at 16MHz. my SMCLK is set as DCOCLK / 4 = 4MHz.

My Timer A source is SMCLK / 8 = 500kHz = 500 ticks/ms

i set TACCR0 = 500 so as to create an interrupt every ~1ms and have a counter incremented. [timer_a_milliseconds++]

it never registers the interrupt and goes into the interrupt path. here is my interrupt setup

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void){
     timer_a_milliseconds++;
TACTL |= TACLR; }

I am using the MCx MODE UP. so i am generating 2 interrupts a CCIFG and a TAIFG. the CCIFG appears to clear when i go into the interrupt but the TAIFG does not even though i do TACTL |= TACLR.

even though in debug mode i can see TAR counting up and resetting when it reaches 500, the TAIV register never clears the TAIFG flag so TAIV register always reads 0x0A. then it loops into a state of i am doing doing nothing about it. is there something tricky about a simple timer interrupt using code composer?

  • The ‘trick’ is reading the User’s Guide until you understand everything you want to work with.

    You don’t show your Timer setup code, but I guess you enables both CCR0-CCIE and TAIE. This requires two ISR’s (Interrupt Service Routine).

    This “TACTL |= TACLR” does not work as you expect, re-read the User’s Guide about this.
  • truly maybe the word tricky was the wrong word. However your condencending answer makes me reluctant to a) use this forum anymore and b) use TI anymore.

    to imply i have not been reading is a wrong statement on your part. i apologize i am not a super tech guru as yoursaelf with your 19k points of you are awesome, but considering the guide does not correlate the code composer interrupt vector definitions with the interurpts needed it makes it difficult. the only thing in the .h file is a timer0_a1_vector and a Timer0_a0_vector. interesting enough i see neither timer0_a0_vector in theTI document i have nor do i find a TAIV_Vector in the .h file.

    there are no samples for me to peruse with regard to this in the code composer example set and googling for it has proven fruitless.

    even without your ridiculous comment which i wish you would have kept to yourself instead of exposing your blantant impatience and intolerance for being an, i am assuming, a paid TI employee with points like that. who knows maybe you are trying to get fired? i was able to come to some sort of understanding and move forward and get it to tick away properly.

    however now i have a different issue as even though i can count up and the interrupts are working properly it never leaves the interrupt routine to move on through the other code. it just stops. but do not trouble yourself with anymore commentary. i didnot need your worthless advice before an i do not need more of it. but thanks for your unhelpfulness
  • dominic leone said:
    i was able to come to some sort of understanding and move forward and get it to tick away properly. however now i have a different issue as even though i can count up and the interrupts are working properly it never leaves the interrupt routine to move on through the other code. it just stops.

    Are you putting the MCU into a low power mode at the same time that you enable interrupts? At the end of the ISR the status register will be reset to whatever it was before the ISR triggered. That means the MCU will automatically return to the power mode it was in before the interrupt. To avoid this you can use _bic_SR_register_on_exit to clear the LPM flags, allowing the MCU to stay awake and resume the main program after the ISR is exited.

  • Hello Dominic,

    Sorry you are having issues currently. Since you didn't post the Timer initialization code I cannot be 100% sure what your issue is, but it does seem you did not enable the appropriate Timer interrupt during initialization. For using CCR0 Overlfow interrupt, you will need to enable it be setting the CCIE bit in the CCTL0 register to 1. An example of using the Timer A CCR0 Register Overflow ISR in Up Mode can be viewed within CCS in MSPware. In CCS navigate to TI Resource Explorer -> MSP430ware -> Devices -> MSP430F2xx -> Code Examples -> MSP430F20x3. From here please chose the msp430x20x3_ta_05 example (Timer_A, Toggle P1.0, CCR0 Up Mode ISR, 32kHz ACLK). This example can show you how to configure the Timer_A registers for exactly what you want to do. From here you can add your additional application code to reach your goal.

    Hope this helps!

    Regards,
    JH

  • “the only thing in the .h file is a timer0_a1_vector and a Timer0_a0_vector”
    These two names are a bit ‘tricky’ but you didn’t ask about or meant these otherwise I would guide you.

    “interesting enough i see neither timer0_a0_vector”
    You just meant its existence here above.

    “nor do i find a TAIV_Vector in the .h file”
    This vector is explained in the User’s Guide, and is not a direct Address but a Register to compose an Address.

    “there are no samples for me to peruse with regard to this in the code composer”
    Try MSPWare.

    “a paid TI employee with points like that”
    This is an open E(ngineers) 2(to) E(ngineers) forum with all unpaid hobbyist’s. And we all start with making failures, and for some (includes me) when we start there wasn’t such forum to ask people for help only some User’s Guide and some Data Sheet, reading until the pages are burned into your eyes (and still are).
  • Thank you for the example file. my code composer did not come with that. all it has is a bunch of grace examples which were of zero help for me. grace does something to simplify it in the end but i just want basic code. i was able to google that file and see what it is.

    Also i found the actual issue which had nothing to do with my timer a interrupts.

    I am also using the SD16 and USI interrupts. The SD16 interrupt is fine. But when i enabled the USI interrupt i went into an unhandled isr loop condition.
  • Thanks for your response. I am not putting it into power save mode. i do not care about power save mode for my application. i am just going to run it full tilt all the time.

    Here is timer setup complete

    #pragma vector = TIMER0_A0_VECTOR
    __interrupt void Timer_ccifg(void){
      timer_a_milliseconds++;
    }
    
    #pragma vector = TIMER0_A1_VECTOR
    __interrupt void Timer_taifg(void){
    
    }
    
    main(){
      WDTCTL = WDTPW | WDTHOLD;
    
      TACTL = 0x02c2;
      TACCTL0 = 0x0034;
      TACCTL1 = 0x0100;
    
      TACCR0 = 500;
      TACTL |= MCX_UP_MODE;
    
      __bis_SR_register(GIE);
    
      while(1){
         update_timer();
      }
    }

    Issued turned out ot be the USI interrupt going into a massive loop

  • Dominic,

    it would be much easier if you would use the register #defines from the header file / the user's guide. I don't think anyone knows what 0x02C2 in TACTL does. Why do you want to use two interrupts for generating one event to increment a variable? I would recommend to use the timer in continuous mode, adding time (ticks) to the CCRx register inside the ISR that generates the next interrupt and so on.

    Dennis

**Attention** This is a public forum