EmbeddedRelated.com
Forums

PWM using TimerB in Continuous mode

Started by ti2tt September 2, 2009
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.

Beginning Microcontrollers with the MSP430

Read and think about what is happening in the different timer modes
(up and continuous, in this case). What happens in UP mode when the
timer register counts to the value specified in TBCCR0? What happens
in continuous mode when the same happens?

- Bart

On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> 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.
Thanks Bart for your reply.!! I tried to look for the different mode configurations but alas.

Does anyone have solution for this? I really need the same very much as project work is held up. I request all forum members for the same. Thanks in advance.

--- In m..., Bart Oegema wrote:
>
> Read and think about what is happening in the different timer modes
> (up and continuous, in this case). What happens in UP mode when the
> timer register counts to the value specified in TBCCR0? What happens
> in continuous mode when the same happens?
>
> - Bart
>
> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> >
> >
> > 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.
> >
>

You'll find it in the MSP430x2xx Family User Guide, specifically chapter 12.

http://www.ti.com/litv/pdf/slau144e

- Bart

On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
> Thanks Bart for your reply.!! I tried to look for the different mode
> configurations but alas.
>
> Does anyone have solution for this? I really need the same very much as
> project work is held up. I request all forum members for the same. Thanks in
> advance.
>
> --- In m..., Bart Oegema wrote:
>>
>> Read and think about what is happening in the different timer modes
>> (up and continuous, in this case). What happens in UP mode when the
>> timer register counts to the value specified in TBCCR0? What happens
>> in continuous mode when the same happens?
>>
>> - Bart
>>
>> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
>> >
>> >
>> > 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.
>> >
>> >
>>
Hello Bart,

I read this chapter 13 for TimerB (chapter 12 is for Timer A), but I was unable to find why the continuous mode is not generating the PWM. The PWM generation is possible in continuos mode even. Please let me know what exactly is going wrong with my code.

Thanks in advance.
--- In m..., Bart Oegema wrote:
>
> You'll find it in the MSP430x2xx Family User Guide, specifically chapter 12.
>
> http://www.ti.com/litv/pdf/slau144e
>
> - Bart
>
> On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
> >
> >
> > Thanks Bart for your reply.!! I tried to look for the different mode
> > configurations but alas.
> >
> > Does anyone have solution for this? I really need the same very much as
> > project work is held up. I request all forum members for the same. Thanks in
> > advance.
> >
> > --- In m..., Bart Oegema wrote:
> >>
> >> Read and think about what is happening in the different timer modes
> >> (up and continuous, in this case). What happens in UP mode when the
> >> timer register counts to the value specified in TBCCR0? What happens
> >> in continuous mode when the same happens?
> >>
> >> - Bart
> >>
> >> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> >> >
> >> >
> >> > 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.
> >> >
> >> >
> >>
> >
>

To basically repeat my question from earlier, what happens in each of
the timer modes? Back off from trying to create a PWM output for the
moment, and think about how the module functions.

To give you part of the solution to get you started a bit further in
the direction I'm thinking, in UP mode the timer counts up to the
value set in TBCCTL0, after which it rolls over to zero and starts
counting up again.

What happens (and what are you depending on in your timeout routines)
in continuous mode? When you're producing PWM outputs in UP mode as
expected, what is happening? When the timeouts are working in
continuous mode, what is happening?

- Bart

On Sun, Sep 6, 2009 at 10:25 PM, ti2tt wrote:
> Hello Bart,
>
> I read this chapter 13 for TimerB (chapter 12 is for Timer A), but I was
> unable to find why the continuous mode is not generating the PWM. The PWM
> generation is possible in continuos mode even. Please let me know what
> exactly is going wrong with my code.
>
> Thanks in advance.
> --- In m..., Bart Oegema wrote:
>>
>> You'll find it in the MSP430x2xx Family User Guide, specifically chapter
>> 12.
>>
>> http://www.ti.com/litv/pdf/slau144e
>>
>> - Bart
>>
>> On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
>> >
>> >
>> > Thanks Bart for your reply.!! I tried to look for the different mode
>> > configurations but alas.
>> >
>> > Does anyone have solution for this? I really need the same very much as
>> > project work is held up. I request all forum members for the same.
>> > Thanks in
>> > advance.
>> >
>> > --- In m..., Bart Oegema wrote:
>> >>
>> >> Read and think about what is happening in the different timer modes
>> >> (up and continuous, in this case). What happens in UP mode when the
>> >> timer register counts to the value specified in TBCCR0? What happens
>> >> in continuous mode when the same happens?
>> >>
>> >> - Bart
>> >>
>> >> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
>> >> >
>> >> >
>> >> > 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.
>> >> >
>> >> >
>> >>
>> >
>> >
>>
Hello Bart / Forum members,

Thank you for your guidance to understant the UP/Continuous mode.

I am now able to generate the PWM in continuous mode and can vary the PWM duty cycle from 0% to 100%. Here I have observed that the PWM duty cycle deviates to 100% at lower values i.e. at 0 to 10%. Does anyone have observed the same? Does anyone have solution for the same? This happens at some regular interval. This interval instance could be the TBR overflow, but I am not sure. Does anyone has similar observation? Please provide me solution for this.

Thanks in advance.
--- In m..., Bart Oegema wrote:
>
> To basically repeat my question from earlier, what happens in each of
> the timer modes? Back off from trying to create a PWM output for the
> moment, and think about how the module functions.
>
> To give you part of the solution to get you started a bit further in
> the direction I'm thinking, in UP mode the timer counts up to the
> value set in TBCCTL0, after which it rolls over to zero and starts
> counting up again.
>
> What happens (and what are you depending on in your timeout routines)
> in continuous mode? When you're producing PWM outputs in UP mode as
> expected, what is happening? When the timeouts are working in
> continuous mode, what is happening?
>
> - Bart
>
> On Sun, Sep 6, 2009 at 10:25 PM, ti2tt wrote:
> >
> >
> > Hello Bart,
> >
> > I read this chapter 13 for TimerB (chapter 12 is for Timer A), but I was
> > unable to find why the continuous mode is not generating the PWM. The PWM
> > generation is possible in continuos mode even. Please let me know what
> > exactly is going wrong with my code.
> >
> > Thanks in advance.
> > --- In m..., Bart Oegema wrote:
> >>
> >> You'll find it in the MSP430x2xx Family User Guide, specifically chapter
> >> 12.
> >>
> >> http://www.ti.com/litv/pdf/slau144e
> >>
> >> - Bart
> >>
> >> On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
> >> >
> >> >
> >> > Thanks Bart for your reply.!! I tried to look for the different mode
> >> > configurations but alas.
> >> >
> >> > Does anyone have solution for this? I really need the same very much as
> >> > project work is held up. I request all forum members for the same.
> >> > Thanks in
> >> > advance.
> >> >
> >> > --- In m..., Bart Oegema wrote:
> >> >>
> >> >> Read and think about what is happening in the different timer modes
> >> >> (up and continuous, in this case). What happens in UP mode when the
> >> >> timer register counts to the value specified in TBCCR0? What happens
> >> >> in continuous mode when the same happens?
> >> >>
> >> >> - Bart
> >> >>
> >> >> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> >> >> >
> >> >> >
> >> >> > 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.
> >> >> >
> >> >> >
> >> >>
> >> >
> >> >
> >>
> >
>

Let me guess, it only happens when you are lowering the DC but not when you're increasing it? Classic mistake, think about it.

Hint: What happens when TAR is nearing TACCRx and you write a new value to TACCRx that is lower than the actual count of TAR.

TACCRx is 1000 and TAR is 900.
You write TACCRx = 800.
What happens next?

Regards,
Michael K.

--- In m..., "ti2tt" wrote:
>
> Hello Bart / Forum members,
>
> Thank you for your guidance to understant the UP/Continuous mode.
>
> I am now able to generate the PWM in continuous mode and can vary the PWM duty cycle from 0% to 100%. Here I have observed that the PWM duty cycle deviates to 100% at lower values i.e. at 0 to 10%. Does anyone have observed the same? Does anyone have solution for the same? This happens at some regular interval. This interval instance could be the TBR overflow, but I am not sure. Does anyone has similar observation? Please provide me solution for this.
>
> Thanks in advance.
> --- In m..., Bart Oegema wrote:
> >
> > To basically repeat my question from earlier, what happens in each of
> > the timer modes? Back off from trying to create a PWM output for the
> > moment, and think about how the module functions.
> >
> > To give you part of the solution to get you started a bit further in
> > the direction I'm thinking, in UP mode the timer counts up to the
> > value set in TBCCTL0, after which it rolls over to zero and starts
> > counting up again.
> >
> > What happens (and what are you depending on in your timeout routines)
> > in continuous mode? When you're producing PWM outputs in UP mode as
> > expected, what is happening? When the timeouts are working in
> > continuous mode, what is happening?
> >
> > - Bart
> >
> > On Sun, Sep 6, 2009 at 10:25 PM, ti2tt wrote:
> > >
> > >
> > > Hello Bart,
> > >
> > > I read this chapter 13 for TimerB (chapter 12 is for Timer A), but I was
> > > unable to find why the continuous mode is not generating the PWM. The PWM
> > > generation is possible in continuos mode even. Please let me know what
> > > exactly is going wrong with my code.
> > >
> > > Thanks in advance.
> > > --- In m..., Bart Oegema wrote:
> > >>
> > >> You'll find it in the MSP430x2xx Family User Guide, specifically chapter
> > >> 12.
> > >>
> > >> http://www.ti.com/litv/pdf/slau144e
> > >>
> > >> - Bart
> > >>
> > >> On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
> > >> >
> > >> >
> > >> > Thanks Bart for your reply.!! I tried to look for the different mode
> > >> > configurations but alas.
> > >> >
> > >> > Does anyone have solution for this? I really need the same very much as
> > >> > project work is held up. I request all forum members for the same.
> > >> > Thanks in
> > >> > advance.
> > >> >
> > >> > --- In m..., Bart Oegema wrote:
> > >> >>
> > >> >> Read and think about what is happening in the different timer modes
> > >> >> (up and continuous, in this case). What happens in UP mode when the
> > >> >> timer register counts to the value specified in TBCCR0? What happens
> > >> >> in continuous mode when the same happens?
> > >> >>
> > >> >> - Bart
> > >> >>
> > >> >> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> > >> >> >
> > >> >> >
> > >> >> > 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.
> > >> >> >
> > >> >> >
> > >> >>
> > >> >
> > >> >
> > >>
> > >
> > >
>

Hello,

Thanks Michael.

I am trying to locate the "Classic mistake". What is the way out to avoid this mistake? Your example clears the point where the mistake is occurring.

Thanks in advance.
--- In m..., "tintronic" wrote:
>
> Let me guess, it only happens when you are lowering the DC but not when you're increasing it? Classic mistake, think about it.
>
> Hint: What happens when TAR is nearing TACCRx and you write a new value to TACCRx that is lower than the actual count of TAR.
>
> TACCRx is 1000 and TAR is 900.
> You write TACCRx = 800.
> What happens next?
>
> Regards,
> Michael K.
>
> --- In m..., "ti2tt" wrote:
> >
> > Hello Bart / Forum members,
> >
> > Thank you for your guidance to understant the UP/Continuous mode.
> >
> > I am now able to generate the PWM in continuous mode and can vary the PWM duty cycle from 0% to 100%. Here I have observed that the PWM duty cycle deviates to 100% at lower values i.e. at 0 to 10%. Does anyone have observed the same? Does anyone have solution for the same? This happens at some regular interval. This interval instance could be the TBR overflow, but I am not sure. Does anyone has similar observation? Please provide me solution for this.
> >
> > Thanks in advance.
> > --- In m..., Bart Oegema wrote:
> > >
> > > To basically repeat my question from earlier, what happens in each of
> > > the timer modes? Back off from trying to create a PWM output for the
> > > moment, and think about how the module functions.
> > >
> > > To give you part of the solution to get you started a bit further in
> > > the direction I'm thinking, in UP mode the timer counts up to the
> > > value set in TBCCTL0, after which it rolls over to zero and starts
> > > counting up again.
> > >
> > > What happens (and what are you depending on in your timeout routines)
> > > in continuous mode? When you're producing PWM outputs in UP mode as
> > > expected, what is happening? When the timeouts are working in
> > > continuous mode, what is happening?
> > >
> > > - Bart
> > >
> > > On Sun, Sep 6, 2009 at 10:25 PM, ti2tt wrote:
> > > >
> > > >
> > > > Hello Bart,
> > > >
> > > > I read this chapter 13 for TimerB (chapter 12 is for Timer A), but I was
> > > > unable to find why the continuous mode is not generating the PWM. The PWM
> > > > generation is possible in continuos mode even. Please let me know what
> > > > exactly is going wrong with my code.
> > > >
> > > > Thanks in advance.
> > > > --- In m..., Bart Oegema wrote:
> > > >>
> > > >> You'll find it in the MSP430x2xx Family User Guide, specifically chapter
> > > >> 12.
> > > >>
> > > >> http://www.ti.com/litv/pdf/slau144e
> > > >>
> > > >> - Bart
> > > >>
> > > >> On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
> > > >> >
> > > >> >
> > > >> > Thanks Bart for your reply.!! I tried to look for the different mode
> > > >> > configurations but alas.
> > > >> >
> > > >> > Does anyone have solution for this? I really need the same very much as
> > > >> > project work is held up. I request all forum members for the same.
> > > >> > Thanks in
> > > >> > advance.
> > > >> >
> > > >> > --- In m..., Bart Oegema wrote:
> > > >> >>
> > > >> >> Read and think about what is happening in the different timer modes
> > > >> >> (up and continuous, in this case). What happens in UP mode when the
> > > >> >> timer register counts to the value specified in TBCCR0? What happens
> > > >> >> in continuous mode when the same happens?
> > > >> >>
> > > >> >> - Bart
> > > >> >>
> > > >> >> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> > > >> >> >
> > > >> >> >
> > > >> >> > 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.
> > > >> >> >
> > > >> >> >
> > > >> >>
> > > >> >
> > > >> >
> > > >>
> > > >
> > > >
> > >
>

Hello Michael,

With ref to your example, the ON or OFF time will change and in turn the duty cycle of PWM will change. But how to avoid it? What could be the remedy for classic mistake?

Thanks in advance.
--- In m..., "ti2tt" wrote:
>
> Hello,
>
> Thanks Michael.
>
> I am trying to locate the "Classic mistake". What is the way out to avoid this mistake? Your example clears the point where the mistake is occurring.
>
> Thanks in advance.
> --- In m..., "tintronic" wrote:
> >
> > Let me guess, it only happens when you are lowering the DC but not when you're increasing it? Classic mistake, think about it.
> >
> > Hint: What happens when TAR is nearing TACCRx and you write a new value to TACCRx that is lower than the actual count of TAR.
> >
> > TACCRx is 1000 and TAR is 900.
> > You write TACCRx = 800.
> > What happens next?
> >
> > Regards,
> > Michael K.
> >
> > --- In m..., "ti2tt" wrote:
> > >
> > > Hello Bart / Forum members,
> > >
> > > Thank you for your guidance to understant the UP/Continuous mode.
> > >
> > > I am now able to generate the PWM in continuous mode and can vary the PWM duty cycle from 0% to 100%. Here I have observed that the PWM duty cycle deviates to 100% at lower values i.e. at 0 to 10%. Does anyone have observed the same? Does anyone have solution for the same? This happens at some regular interval. This interval instance could be the TBR overflow, but I am not sure. Does anyone has similar observation? Please provide me solution for this.
> > >
> > > Thanks in advance.
> > > --- In m..., Bart Oegema wrote:
> > > >
> > > > To basically repeat my question from earlier, what happens in each of
> > > > the timer modes? Back off from trying to create a PWM output for the
> > > > moment, and think about how the module functions.
> > > >
> > > > To give you part of the solution to get you started a bit further in
> > > > the direction I'm thinking, in UP mode the timer counts up to the
> > > > value set in TBCCTL0, after which it rolls over to zero and starts
> > > > counting up again.
> > > >
> > > > What happens (and what are you depending on in your timeout routines)
> > > > in continuous mode? When you're producing PWM outputs in UP mode as
> > > > expected, what is happening? When the timeouts are working in
> > > > continuous mode, what is happening?
> > > >
> > > > - Bart
> > > >
> > > > On Sun, Sep 6, 2009 at 10:25 PM, ti2tt wrote:
> > > > >
> > > > >
> > > > > Hello Bart,
> > > > >
> > > > > I read this chapter 13 for TimerB (chapter 12 is for Timer A), but I was
> > > > > unable to find why the continuous mode is not generating the PWM. The PWM
> > > > > generation is possible in continuos mode even. Please let me know what
> > > > > exactly is going wrong with my code.
> > > > >
> > > > > Thanks in advance.
> > > > > --- In m..., Bart Oegema wrote:
> > > > >>
> > > > >> You'll find it in the MSP430x2xx Family User Guide, specifically chapter
> > > > >> 12.
> > > > >>
> > > > >> http://www.ti.com/litv/pdf/slau144e
> > > > >>
> > > > >> - Bart
> > > > >>
> > > > >> On Fri, Sep 4, 2009 at 11:34 PM, ti2tt wrote:
> > > > >> >
> > > > >> >
> > > > >> > Thanks Bart for your reply.!! I tried to look for the different mode
> > > > >> > configurations but alas.
> > > > >> >
> > > > >> > Does anyone have solution for this? I really need the same very much as
> > > > >> > project work is held up. I request all forum members for the same.
> > > > >> > Thanks in
> > > > >> > advance.
> > > > >> >
> > > > >> > --- In m..., Bart Oegema wrote:
> > > > >> >>
> > > > >> >> Read and think about what is happening in the different timer modes
> > > > >> >> (up and continuous, in this case). What happens in UP mode when the
> > > > >> >> timer register counts to the value specified in TBCCR0? What happens
> > > > >> >> in continuous mode when the same happens?
> > > > >> >>
> > > > >> >> - Bart
> > > > >> >>
> > > > >> >> On Wed, Sep 2, 2009 at 7:57 AM, ti2tt wrote:
> > > > >> >> >
> > > > >> >> >
> > > > >> >> > 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.
> > > > >> >> >
> > > > >> >> >
> > > > >> >>
> > > > >> >
> > > > >> >
> > > > >>
> > > > >
> > > > >
> > > >
> > >
>