msp430 timer programming interrupt based


Basically msp4302xxx family has two 16-bit timers. Timer A and Timer B.

We will see today about Timer A.

Timer A can work in four modes based on the values of MCx in TACTL register

If MCx = 00 then it is in stop mode. It means the timer is stopped.

If MCx = 01 then it is in Up mode. It means the timer counts up to the value present in the TACCR0 register and goes to zero and repeats the cycle

If MCx = 10 then it is in Continuous mode,in which the timer counts up to the value  0xffff and jumps to zero and repeats the same.

If MCx = 11 then it is in Up/Down mode where the timer counts up to the value present in the TACCR0 and starts decrementing to zero and again starts from zero to TACCR0



The timer can be sourced from either ACLK,TACLK,SMCLK and INCLK with a divisor factor upt0 8 based on the values of TASSELx and IDx in the TACTL register


We will see how to program the timer A present in msp430. For programming we have to use the Timer A registers.

1) TAR: It is  a 16-bit register , whose value will be incremented for every rising edge of the clock cycle

2) TACTL :  It is a 16-bit register ,which is used basically to control the Timer A.It has settings to enable the Timer Overflow Interrupt,Select the clock source and its divisor and the mode of the timer operation.


There are other registers present which we will see later. But for starting a timer and generating a delay knowing these register is enough.


Code:



//step1: include the header file of microcontroller

#include <msp430f2618.h>
#include <msp430.h>


__attribute__((interrupt(TIMERA1_VECTOR)))
void Timer_A(void)
{


P3OUT ^= 1<<4;
}


int main(void)
{

// Stop the watchdog timer

WDTCTL = WDTPW+WDTHOLD;

// Setting the pin functionality

P3DIR  |= 1<<4; //setting the pin 3.4 as output

//Selecting the clock source to SMCLK,divider to zero,setting the mode to continuous,enabling the timer interrupt

TACTL |= TASSEL1|MC1|TAIE;

__eint();  //Enabling global interrupts

//while loop
while(1){}




return 0;

}

Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

PR, PN and PV Variable in Yocto