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.