NPEDUCATIONS, Electronic circuits development, electronics tutorials, microcontroller tutorials and projects, advanced microcontroller (ARM) based tutorials and projects, Embedded c development, Embedded c for ARM cortex M, Intel IoT based projects, IoT projects, CC3200 launch pad projects, MSP430 Launchpad tutorials and projects, Tiva C launch pad tutorials and projects, 8051 tutorials and projects, sensor interfacing with microcontroller tutorials, data communications and networking tutorials, peripheral interfacing with microcontroller, led message scrolling display, arduino based tutorials and projects, intel galileo based tutorials and project, ADC interfacing tutorials, LED Blinking, LCD interfacing, Embedded System tutorials and projects, projects, projects, online Embedded C training

Understanding Timers in MSP430 Launch pad

In this tutorial, I assume that you have an idea about the basic timers in 8051 or any other microcontroller. I am not going to define the timer’s definition and its applications. Here I just concentrate on programming aspects of the timers in MSP430 microcontroller.

Generally, first question arises in our mind about the timer’s in a microcontroller is
“How many timers are there in MSP430G2553”?
There are two 16-bit timers are available in MSP430G2553, excluding watch dog timer.
  •  Timer_A0
  •  Timer_A1

While doing applications using timers, I was a bit confused about the Timer_A and Timer_B. Finally a lot of search I found some important points regarding these timers.
Generally MSP430 family contains two categories of timers
  •  Timer_A
  •  Timer_B.

What is the difference between Timer_A and Timer_B ?
Both are same in its operation, but Timer_B is more sophisticated than Timer_A and it has many features available than compared with Timer_A. They are.

·         Bit-length of the timer is programmable as 8-bit, 10- bit, 12-bit, 16-bit.
·        Some Timers in B category have 7 CCR registers whereas the Timer_A contains three capture/compare registers.
·         It contains double-buffered CCR register.
·         CCR register can be grouped.

Note: MSP430G2553 contains only Timer_A as Timer_A0 and Timer_A1.

Each 16-bit timer starts counts from 0 to 0x0FFFF (0 to 65536) and they operate in four different modes.

·         Stop     --- Timer is in halt state or stops the timer.
·         UP        --- Timer counts up from zero to value stored in TACCR0 register (other than 0xFFFF) and roll 
                         over to zero after it reached the count value as shown in figure 1.1.
                         Generally this mode used to produce time delays.
·         Continuous --- it is same as UP mode but here Timer counts up from zero to maximum value 0xFFFFh and 
                                rolls over to zero after it reached 0xFFFF and keep going as shown in figure 1.1.
·         Up/Down --- in this mode time counts up from 0 to TACCR0 register and then counts down back to zero 
                            as shown in figure. It is good for generating PWM’s and driving motors.

Figure 1.1 shows the Different timing modes in MSP430 microcontroller.

Ok! We will switch over to Programming concepts in MSP430G2553. First of all we need to know the available special functions registers and bits that are used to configure the Timers in MSP430.

Figure 1.2 Shows the Timer register and its configurable bits.
 Three compare/capture registers CCR0, CCR1, CCR2 are used load the timer count. These registers can    
 also be referred as TACCR0, TACCR1, and TACCR2,  But in this tutorial we referred simply as CCR0,  
 CCR1 and CCR2.
·         TAR is the 16-bit timer register in which the count start increment/decrements value depends
                upon the timer mode settings.
·         CCIFG interrupt flag is set when the timer counts to the value stored in CCR0 register.
·         TAIFG interrupt flag is set when the timer count from CCR0 to zero.
·         TASSELx are the bits used to select one of the clock signals as shown in the figure 1.2.
·         IDx bit are used to divide the clock signal applied to timer as shown in the figure 1.2.
·         MCx bits are used select count mode as shown in figure 1.2.
·         TACLR bit clears the TAR register, clock divider and count direction (mode).

There are two interrupt flags (CCIFG and TAIFG) and its corresponding two interrupt vectors (TACCR0 and TAIV) available for Timers in MSP430 as shown in the figure 1.3.

Figure 1.3 shows Timer interrupts and its corresponding interrupt vectors in MSP430

C Program to generate 1 sec delay using Timer_A0 which is driven by ACLK and it is sourced by low frequency oscillator (VLO). Here in this program LED blinks for every one second.

           Step 1: Stop the watch dog timer, to avoid unnecessary resets of the microcontroller. We will discuss 
                       more on watch dog timer later.

                WDTCTL = WDTPW + WDTHOLD; // stop watch dog timer.

Step 2: make cpu to run with MCLK from DCO source

    BCSCTL1 = CALBC1_1MHZ;            
                DCOCTL = CALDCO_1MHZ;

Step 3: BCSCTL3 is used to low frequency crystal. LFXT1S_2 --> LFXT1 = VLO oscillator is 

BCSCTL3 |= LFXT1S_2;                     

Step 4: Configure the MCLK and SMCLK by setting proper bits BCSCTL2. SELM_0 -- selects 
            MCLK source from DCOCLK, DIVM_3 --> MCLK = DCO/8, We should remember  
            that "Up on reset, MCLK and SMCLK are source from 1.1MHz DCO clock source"  
            DIVS_3 --> SMCLK = DCO/8.

BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;

Step 5: Configure the TimerA to operate with ACLK which is source from VLO (12KHz) - 
            (TASSEL = 1) and in up mode (MC = 1)

                TACTL = TASSEL_1 + MC_1;

            Enable compare register interrupt in the CCTLO (capture compare control register)

    CCTL0 = CCIE;

Load the count 12000 in counter compare register  to generate 1 second delay (12000 * T) 
= 12000 * (1/12000) = 1sec;  T = 1/F = 1/12khz

 CCR0 = 12000;

Step 6:  Configure the GPIO port to blink the LED.
Make port1 bit 0 as output, which is connected to RED LED on the LAUNCH PAD board. 
This can be done by placing 1 on direction register (P1DIR).

                P1DIR = 0x01; // (output – 1, input – 0)

 place zero on the P1.0 pin, to make output zero.

                P1OUT = 0x00; // all port1 pins are at logic low.

Step 7: Enable the global interrupt in status register (SR) via Assembly call from C using following 


            Step 8: Use infinite loop or Lower power mode (LPM). We haven’t discussed about the low 
                        power mode, so I use infinite loop even though it wastages the CPU time.


Step 9: write ISR function for Timer_A0,

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
              P1OUT |= 0x01;
              P1OUT &= ~0x01;


A program generate 1 sec time day using Timers in MSP430 launch pad.


void Config_TimerA(void);
void Config_GPIO(void);

void main(void)

  WDTCTL = WDTPW + WDTHOLD; // Stop the Watch dog timer

 BCSCTL3 |= LFXT1S_2;                      // LFXT1 = VLO
 IFG1 &= ~OFIFG;                           // Clear OSCFault flag
 BCSCTL2 |= SELM_0 + DIVM_3 + DIVS_3;      // MCLK = DCO/8 , SMCLK = DCO/8


void Config_GPIO(void)
 P1DIR = 0x01;                             // MAKE P1.0 as output port
 P1OUT = 0x00;                             // MAKE ALL pins to logic low

void Config_TimerA(void)

 CCTL0 |= CCIE;  
 CCR0 = 12000;  


#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
 CCR0 =+ 12000;
 P1OUT |= 0x01;
 P1OUT &= ~0x01;


Thanks for visiting NPEDUCATIONS. We will contact you soon


Anonymous said...

Very good!!

Mallappa T said...

Why Images are not visible ?

Lovakiranvarma Myla said...

I will check out that problem! thank you!

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.

Powered by Blogger