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.

Timer_A interrupts

Other Parts Discussed in Thread: MSP430F2274

Hi, I am very new to programming microcontrollers. I tried to do an LED blink code with the help of Timer_A interrupts of EZ430-RF2500 wireless development tool (msp430f2274) by using msp430 toolchain in eclipse (Indigo version) enivronment.

#include "msp430f2274.h"
#include "bsp_msp430_defs.h"
#include "bsp.h"
#include "mrfi.h"
#include "bsp_leds.h"
#include "bsp_buttons.h"
#include "signal.h"

void main(void)
{


  WDTCTL = WDTPW + WDTHOLD;                // Stop watchdog timer
  P1DIR |= 0x01;                                                   // Set P1.0 to output direction
  P1OUT = 0x00;                                                   //Initial Condition
  TACCTL0 = CCIE;                                              // TACCR0 interrupt enabled
  TACCR0 = 12000;                                              // ~1 second
  TACTL = TASSEL_1 + MC_1;                           // ACLK, upmode
  __enable_interrupt();

}

#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  P1OUT ^= 0x01;
}


The LED was supposed blink continuously, but didn't happenTo verify whether the interrupt flag of the Timer_A is working, I used the following  code.

#include "msp430f2274.h"
#include "bsp_msp430_defs.h"
#include "bsp.h"
#include "mrfi.h"
#include "bsp_leds.h"
#include "bsp_buttons.h"
#include "signal.h"

void main(void)
{


  WDTCTL = WDTPW + WDTHOLD;                // Stop watchdog timer
  P1DIR |= 0x01;                           // Set P1.0 to output direction
  P1OUT = 0x00;                            //Initial Condition
  TACCTL0 = CCIE;                          // TACCR0 interrupt enabled
  TACCR0 = 12000;                          // ~1 second
  TACTL = TASSEL_1 + MC_1;                 // ACLK, upmode
  __enable_interrupt();

for (;;)
{
  for (i=10; i>0 ; )
	{
		if (TAIV == 0x0A)
		{

			P1OUT ^= 1;
			i--;
		}
        }
  for (i=10; i>0; )
	{
		if (TAIV == 0x0A)
		{

			P1OUT ^= !P1OUT;
			i--;
		}
         }
}

Here the interrupt flag was working fine. So I guess the problem is the way I called the interrupt function. I looked into many examples. I am not able to understand the problem with my first code. Please help. Thanks in advance

  • I think you have to put your controller into a sleep mode from where it can be woken up to handle the interrupt, or you have to add an endless-loop where the MCU is doing nothing. Your program just ends after your initialization.

  • Felix,

    What Dennis said. After your enable_interrupts(); line, the program exits. You need to hang around in main to allow the Timer to do it's thing.

    Add this code at the end of main in place of the __enable_interrupts() call:

      while(1)
      {  
        _bis_SR_register(LPM0_bits+GIE);
      }
    
    

    :

  • Thank You Brian, that worked. I have a doubt regarding the low power mode. Hope its not too much trouble for you. In LPM0, the CPU is inactive. My doubt is, what kind of tasks can be done when the CPU is inactive? Or to frame it right, during the LPM0, does the execution of the program completely stop?

  • One thing i noticed was that you code is written as:

    __enable_interrupt();

    Is this correct, in CCS I use:

    _enable_interrupts();

    Notice the 's' on the end and CCS highlights it as it recognizes it as an intrinsic.

    To do some 'work' at a fixed interval you can do the following (or similar) which will disable the CPU, wake it at a fixed interval, allow you to do some work and then loop around to the beginning:

    _enable_interrupts();	// Enable interrupts					
    for(;;)		        // Trap forever												
    {
          LPM0;		// Enter low power mode 0
          //Do something, toggle LED, kick watchdog etc
    }
    
    #pragma vector=TIMERA0_VECTOR
    __interrupt void Timer_A (void)
    {
      LPM0_EXIT;            // Wake up on ISR exit
    }											
  • Felix George said:
    In LPM0, the CPU is inactive.

    Yes. That is true.

    Felix George said:
    what kind of tasks can be done when the CPU is inactive?

    The CPU can't do anything. But the peripherals can keep operating (like the timer). And they can generate an interrupt to the CPU, and an interrupt will bring the CPU out of LPM and allow it to execute the ISR. At the end of the ISR, the CPU goes back to sleep (unless the LPMx_EXIT; macro is used). That is why your program now works with the changes.

  • I would also suggest reading the chapter in the User's Guide about the low power modes.

  • Hi Steve, Thanks for the reply. I use eclipse, Indigo version. I was not able to compile any of the header file using eclipse. I had made some changes to these header files and included few headerfiles from the msp toolchains too. The error in my code was that it did not have an infinite loop and thus the execution stops. Now I am getting a better grip and trying to include more peripherals and functions.

**Attention** This is a public forum