Home > Uncategorized > Understanding Timers in MS430 #2

Understanding Timers in MS430 #2

Add three more lines in the main programs ( highlighted in red).

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P6DIR |= 0x08; // P6.3 Set P6.3 to output
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 60000;
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
_BIS_SR(GIE); // Enable interrupt
}

Let is now try to understand the code one by one..

CCTL0 Register

If you plan to use a Timer, the first register that you need to set is CCTL0. It is a 16 bit register and settings of this register effects how we use the register. For our purpose we just tell it to enable the interrupt using

CCTL0 = CCIE;

Notice that we have not yet enabled the timer.

CCR0

This register will define the amount of time after which the timer event will occur. We have set it to

CCR0 = 60000;

TACTL

Bit 9-8 selects the source of the clock

The Possible values are

00 TACLK
01 ACLK
10 SMCLK
11 INCLK

We have basically selected the SMCLK which is a 4 MHz clock in our case.

The bits 5-4 selects how the counting. Possible values are

00 Stop mode: the timer is halted
01 Up mode: the timer counts up to TACCR0
10 Continuous mode: the timer counts up to 0FFFFh
11 Up/down mode: the timer counts up to TACCR0 then down to 0000h

We have selected 10 which makes the counter count upto 0FFFFh

Enable General Interrupt

Finally we have to enable the general interrupt using.

_BIS_SR(GIE);

This statements sets the GIE bit in the Status register which enables the interrupt. Notice that we have not yet defined the interrupt vector. We will do it in the next page. The code as of now will compile but will not produce any observable result.

Uncategorized

  1. No comments yet.
  1. No trackbacks yet.