Timer ISRs

Hello forum members,

I am using MSP430F1611 with CrossStudio. I want to use Timer B for generating a PWM as well as a counting a timeout value. The PWM code is as:

void ConfigTimerBCompare (void)

{

P4SEL &= ~0xA0;

P4SEL |= 0x20; // P4.5 - Select as TB5 functionality

P4DIR |= 0x20; // P4.5 - Select compare as output

TBCTL = MC_0 | TBCLR; // Stop Timer

TBCCTL5 = 0x00; // CAP = 0 - Compare mode

TBCCR0 = (1024 - 1); // PWM Period/2

TBCCTL5 = OUTMOD_7; // CCR5 Set/Reset

TBCCR5 = 0x00; // CCR5 PWM duty cycle - 0x00(0%), 0xFF(25%), 0x1FF(50%), 0x2FF(75%), 0x3FF(100%)

TBCTL = CNTL_0; // 16 bit format

TBCCR5 = 38;

TBCCTL5 = CCIE; // CCR5 interrupt enabled

TBCTL = TBSSEL_1 | ID_2 | MC_3; // Clock source=ACLK, Divide by 4, Start timer in up-down mode

}

The ISR for Timer changes PWM duty cycle:

void ISR_TimerB (void) INTERRUPT[TIMERB1_VECTOR]

{

TBCCR5 = g_DACCount; // CCR5 PWM duty cycle - 0x00(0%), 0xFF(25%), 0x1FF(50%), 0x2FF(75%), 0x3FF(100%)

g_Data_Bit_High = g_Data_Bit_High^0x01;

TBCCTL5 |= CCIE; // CCR5 interrupt enabled

}

Above code uses TimerB module 5 for generating PWM. Now I want to use TimerB module 1 for counting a value say a timeout count for other task. How I need to configure timer for this? How do I configure the ISR for reloading the timeout count to timer? I am confused of using various timer modules - Timer0 to Timer6 and their interrupts. Can anyone clarify or elaborate more on its use?

Thanks in advance.

I saw all kinds of questions. Does any body read the answers?

Hello OldCow,

I am bit surprised by your answer. I personally view and work on each and every answer not only mine but of others. This forum activity is very much helpful to avoid small mistakes while coding. May be because of some restrictions on use of internet, some delay happens.

Please keep helping…replying

Thanks in advance.

Assuming that you do not need to change the PWM period (TBCCR0) and only need to change the PWM duty (TBCCR5), then you can use other CCs as timers (or PWM with the same period but different duty).

You are currently using TBCTL up-down mode. This makes timer function a little more difficult to implement. You could use up mode instead and still use CC5 to generate PWM.

If the timeout interval is less than the up mode interval (TBCCR0), you simply set TACCR1 to the current reading of TBR + the number of cycles you want to timeout and set the CCIE of TABCCTR1. The next interrupt means timeout expired.

If the timeout interval is larger then TBCCR0, you need to set:

TBCCR5 = TBR + ( % TBCCR0);

The ( / TBCCRO)+1st interrupt means timeout expired.

(where % and / are integer modulus and divide)