Hello Friends/Members,
I am using MSP430F2418 device and want to generate the PWM on pin TB5 using
continuous mode of TimerB. I am using this timer - module 4 and module 6 - for
two different timeout values. I want to generate a PWM of 50% duty cycle and a
period of 150Hz using module 5 which in turn will output a PWM on TB5. I am
using ACLK=1MHz. Below is the code, I have written to configure TimerB and
corresponding modules:
void Init_TimerB (void)
{
TBCTL = (TBCLR | MC_0); //Individual compare latch / Clear TimerB / Stop
TimerB
TBCTL = (CNTL_0 | TBSSEL_1 | ID_1); //16bit / ACLK / Divide by 2 / Stop
TBCTL &= ~(TBIE | TBIFG); //Disable TBIV and flag
TBCTL = (CNTL_0 | TBSSEL_1 | ID_1 | MC_2); //16bit / ACLK / Divide by 2 /
Continuous
}
void ConfigTimerB4_Timeout (UINT tout)
{
TBCCTL4 &= ~CCIE; //Disable interrupt
TBCCTL4 &= ~CAP; //Compare mode
//CM_0 = No Capture
//CCIS_1 = Capture/Compare input is TB4
//SCS = Synchronous capture
//CLLD_0 = Load compare latch (TBCLx) when TBCCRx
is written
//OUTMOD_0 = output value of OUT on pin
//CCIE = Enable interrupt
//OUT = Output high on pin
TBCCTL4 = (CM_0 | CCIS_1 | SCS | CLLD_0 | OUTMOD_0 | CCIE | OUT);
TBCCR4 = (TBR + tout);
}
void ConfigTimerB6_Timeout (UINT tout)
{
TBCCTL6 &= ~CCIE; //Disable interrupt
TBCCTL6 &= ~CAP; //Compare mode
//CM_0 = No Capture
//CCIS_1 = Capture/Compare input is TB6
//SCS = Synchronous capture
//CLLD_0 = Load compare latch (TBCLx) when TBCCRx
is written
//OUTMOD_4 = Toggle TB6
//CCIE = Enable interrupt
//OUT = Output high on pin if OUTMOD_0
TBCCTL6 = (CM_0 | CCIS_1 | SCS | CLLD_0 | OUTMOD_4 | CCIE | OUT);
TBCCR6 = (TBR + tout);
}
void ConfigTimerB5_PWM (void)
{
P4SEL &= ~0xA0;
P4SEL |= 0x20; // P4.5 - Select as TB5 functionality
P4DIR |= 0x20; // P4.5 - Select compare as output
TBCCR0 = 0;
TBCCTL5 &= ~CCIE; //Disable interrupt
TBCCTL5 &= ~CAP; //Compare mode
//CM_0 = No Capture
//CCIS_1 = Capture/Compare input is TB4
//SCS = Synchronous capture
//CLLD_0 = Load compare latch (TBCLx) when TBCCRx is
written
//OUTMOD_0 = output value of OUT on pin
//CCIE = Enable interrupt
//OUT = Output high on pin
TBCCTL5 = (CM_0 | CCIS_1 | SCS | CLLD_0 | OUTMOD_3 | CCIE | OUT);
TBCCR5 = (1660);
}
I am not sure of module 5 configuration. Please guide me to get the PWM in continuous mode. If I use UP mode for timer, then I am able to generate the PWM properly but failing to get required timeouts. Is it possible to use timer either in Up or Continuous mode to generate both PWM as well as timeouts? Please help me for this. Your earliest help in this regard will be highly appreciated. Thanks in advance.