EmbeddedRelated.com
Forums
Memfault Beyond the Launch

PWM using TimerB in Continuous mode

Started by ti2tt September 2, 2009
I think you're still missing it. You're both lengthening and
shortening the duty cycle in your application, but this only happens
when you're making the duty cycle shorter. Look closely at Michael's
example and hint.

- Bart

On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
>
> 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.
> > > > > >> >> >
> > > > > >> >> >
> > > > > >> >>
> > > > > >> >
> > > > > >> >
> > > > > >>
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >

Beginning Microcontrollers with the MSP430

Hello Bart / Michael,

The user guide slau144e.pdf - pg no 13-8 states, "When the sum of the previous TBCLx value plus tx is greater than the TBCL0 data, TBCL0+1 must be subtracted to obtain the correct time interval". Are you both pointing to same? I think this is what the code is missing. Please guide me in detail.

Thanks in advance.
--- In m..., Bart Oegema wrote:
>
> I think you're still missing it. You're both lengthening and
> shortening the duty cycle in your application, but this only happens
> when you're making the duty cycle shorter. Look closely at Michael's
> example and hint.
>
> - Bart
>
> On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> >
> >
> >
> > 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.
> > > > > > >> >> >
> > > > > > >> >> >
> > > > > > >> >>
> > > > > > >> >
> > > > > > >> >
> > > > > > >>
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):

Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.

It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.

Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
while (value > (TAR-20) // Check if new value is too close or past TAR.
; //Wait until TAR rolles over
TACCR = value;

Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.

__interrupt void TimerA1 (void)
{
switch (TAIV)
{
case TACC_x:
TACCRx = Period;
break;
}
}

I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.

Best Regards,
Michael
--- In m..., Bart Oegema wrote:
>
> I think you're still missing it. You're both lengthening and
> shortening the duty cycle in your application, but this only happens
> when you're making the duty cycle shorter. Look closely at Michael's
> example and hint.
>
> - Bart
>
> On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> >
> >
> >
> > 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.
> > > > > > >> >> >
> > > > > > >> >> >
> > > > > > >> >>
> > > > > > >> >
> > > > > > >> >
> > > > > > >>
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Hello Michael,

Thanks for your kind help. I am still to get the classic mistake cleared. I hope you will be kind enough to give me the right solution. Your earliest help will be highly appreciated. Thanks in advance.
--- In m..., "Michael" wrote:
>
> At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):
>
> Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.
>
> It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.
>
> Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
> while (value > (TAR-20) // Check if new value is too close or past TAR.
> ; //Wait until TAR rolles over
> TACCR = value;
>
> Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.
>
> __interrupt void TimerA1 (void)
> {
> switch (TAIV)
> {
> case TACC_x:
> TACCRx = Period;
> break;
> }
> }
>
> I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.
>
> Best Regards,
> Michael
> --- In m..., Bart Oegema wrote:
> >
> > I think you're still missing it. You're both lengthening and
> > shortening the duty cycle in your application, but this only happens
> > when you're making the duty cycle shorter. Look closely at Michael's
> > example and hint.
> >
> > - Bart
> >
> > On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> > >
> > >
> > >
> > > 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.
> > > > > > > >> >> >
> > > > > > > >> >> >
> > > > > > > >> >>
> > > > > > > >> >
> > > > > > > >> >
> > > > > > > >>
> > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > >
>

Hello Forum members,

Has anyone experienced similar issues with PWM? Please share your views. I am in desperate need for the solution. Request you all for the help.

Thanks in advance.
--- In m..., "ti2tt" wrote:
>
> Hello Michael,
>
> Thanks for your kind help. I am still to get the classic mistake cleared. I hope you will be kind enough to give me the right solution. Your earliest help will be highly appreciated. Thanks in advance.
> --- In m..., "Michael" wrote:
> >
> > At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):
> >
> > Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.
> >
> > It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.
> >
> > Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
> > while (value > (TAR-20) // Check if new value is too close or past TAR.
> > ; //Wait until TAR rolles over
> > TACCR = value;
> >
> > Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.
> >
> > __interrupt void TimerA1 (void)
> > {
> > switch (TAIV)
> > {
> > case TACC_x:
> > TACCRx = Period;
> > break;
> > }
> > }
> >
> > I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.
> >
> > Best Regards,
> > Michael
> >
> >
> > --- In m..., Bart Oegema wrote:
> > >
> > > I think you're still missing it. You're both lengthening and
> > > shortening the duty cycle in your application, but this only happens
> > > when you're making the duty cycle shorter. Look closely at Michael's
> > > example and hint.
> > >
> > > - Bart
> > >
> > > On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> > > >
> > > >
> > > >
> > > > 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.
> > > > > > > > >> >> >
> > > > > > > > >> >> >
> > > > > > > > >> >>
> > > > > > > > >> >
> > > > > > > > >> >
> > > > > > > > >>
> > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
>

What have you tried from what Michael suggested? We don't have any
idea what you've tried or what your code looks like at this point, so
we couldn't help you if we wanted to.

- Bart

On Thu, Sep 24, 2009 at 11:20 PM, ti2tt wrote:
>
> Hello Forum members,
>
> Has anyone experienced similar issues with PWM? Please share your views. I am in desperate need for the solution. Request you all for the help.
>
> Thanks in advance.
> --- In m..., "ti2tt" wrote:
> >
> > Hello Michael,
> >
> > Thanks for your kind help. I am still to get the classic mistake cleared. I hope you will be kind enough to give me the right solution. Your earliest help will be highly appreciated. Thanks in advance.
> > --- In m..., "Michael" wrote:
> > >
> > > At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):
> > >
> > > Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.
> > >
> > > It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.
> > >
> > > Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
> > > while (value > (TAR-20) // Check if new value is too close or past TAR.
> > > ; //Wait until TAR rolles over
> > > TACCR = value;
> > >
> > > Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.
> > >
> > > __interrupt void TimerA1 (void)
> > > {
> > > switch (TAIV)
> > > {
> > > case TACC_x:
> > > TACCRx = Period;
> > > break;
> > > }
> > > }
> > >
> > > I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.
> > >
> > > Best Regards,
> > > Michael
> > >
> > >
> > > --- In m..., Bart Oegema wrote:
> > > >
> > > > I think you're still missing it. You're both lengthening and
> > > > shortening the duty cycle in your application, but this only happens
> > > > when you're making the duty cycle shorter. Look closely at Michael's
> > > > example and hint.
> > > >
> > > > - Bart
> > > >
> > > > On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> > > > >
> > > > >
> > > > >
> > > > > 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.
> > > > > > > > > >> >> >
> > > > > > > > > >> >> >
> > > > > > > > > >> >>
> > > > > > > > > >> >
> > > > > > > > > >> >
> > > > > > > > > >>
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> >
I really can't tell you anything more. I think I made it quite clear what your problem is and how to solve it, even babystep guided you. If you still can't make it work, the only advice I have left would be a change of career.

Regards,
Michael K.

--- In m..., "ti2tt" wrote:
>
> Hello Forum members,
>
> Has anyone experienced similar issues with PWM? Please share your views. I am in desperate need for the solution. Request you all for the help.
>
> Thanks in advance.
> --- In m..., "ti2tt" wrote:
> >
> > Hello Michael,
> >
> > Thanks for your kind help. I am still to get the classic mistake cleared. I hope you will be kind enough to give me the right solution. Your earliest help will be highly appreciated. Thanks in advance.
> > --- In m..., "Michael" wrote:
> > >
> > > At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):
> > >
> > > Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.
> > >
> > > It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.
> > >
> > > Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
> > > while (value > (TAR-20) // Check if new value is too close or past TAR.
> > > ; //Wait until TAR rolles over
> > > TACCR = value;
> > >
> > > Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.
> > >
> > > __interrupt void TimerA1 (void)
> > > {
> > > switch (TAIV)
> > > {
> > > case TACC_x:
> > > TACCRx = Period;
> > > break;
> > > }
> > > }
> > >
> > > I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.
> > >
> > > Best Regards,
> > > Michael
> > >
> > >
> > > --- In m..., Bart Oegema wrote:
> > > >
> > > > I think you're still missing it. You're both lengthening and
> > > > shortening the duty cycle in your application, but this only happens
> > > > when you're making the duty cycle shorter. Look closely at Michael's
> > > > example and hint.
> > > >
> > > > - Bart
> > > >
> > > > On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> > > > >
> > > > >
> > > > >
> > > > > 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.
> > > > > > > > > >> >> >
> > > > > > > > > >> >> >
> > > > > > > > > >> >>
> > > > > > > > > >> >
> > > > > > > > > >> >
> > > > > > > > > >>
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > >
>

Below is the code for this PWM,

Timer Initialisation -
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
}

PWM initialisation -
void ConfigTimerB5_PWM (void)
{
P4SEL &= ~0xA0;
P4SEL |= 0x20; // P4.5 - Select as TB5 functionality
P4DIR |= 0x20; // P4.5 - Select compare as output

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_3 = Set/Reset
//CCIE = Enable interrupt
//OUT = Output high on pin
TBCCTL5 = (CM_0 | CCIS_1 | SCS | CLLD_0 | OUTMOD_3 | CCIE | OUT);
TBCCR5 = DACOUT; //PWM Duty cycle
}

The ISR for TimerB -
void ISR_TimerB (void) INTERRUPT[TIMERB1_VECTOR]
{
switch (TBIV)
{
case TBIV_TBCCR1:
break;

case TBIV_TBCCR5:
TBCCTL5 &= ~CCIFG; //Clear interrupt flag
// TBCCR5 += DACOUT;
TBCCR0 = (TBCCR5 + DACOUT);
if (DACOUT < 150)
{
if (TBCCR5 > TBCCR0)
{
TBCCR5 += (PWM_Period - (TBCCR0+1));
}
else
{
TBCCR5 += PWM_Period;
}
}
else
{
TBCCR5 += PWM_Period;
}
break;

case TBIV_TBCCR4:
break;
case TBIV_TBCCR6:
break;
}
}

I have tried to implement the guidelines from Michael but still the PWM is missing at the lower values. May be my implementation is different than what Michael suggested, so there could be a mistake. Please guide me to correct the mistake for this code.

Thanks in advance.
--- In m..., Bart Oegema wrote:
>
> What have you tried from what Michael suggested? We don't have any
> idea what you've tried or what your code looks like at this point, so
> we couldn't help you if we wanted to.
>
> - Bart
>
> On Thu, Sep 24, 2009 at 11:20 PM, ti2tt wrote:
> >
> >
> >
> > Hello Forum members,
> >
> > Has anyone experienced similar issues with PWM? Please share your views. I am in desperate need for the solution. Request you all for the help.
> >
> > Thanks in advance.
> > --- In m..., "ti2tt" wrote:
> > >
> > > Hello Michael,
> > >
> > > Thanks for your kind help. I am still to get the classic mistake cleared. I hope you will be kind enough to give me the right solution. Your earliest help will be highly appreciated. Thanks in advance.
> > > --- In m..., "Michael" wrote:
> > > >
> > > > At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):
> > > >
> > > > Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.
> > > >
> > > > It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.
> > > >
> > > > Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
> > > > while (value > (TAR-20) // Check if new value is too close or past TAR.
> > > > ; //Wait until TAR rolles over
> > > > TACCR = value;
> > > >
> > > > Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.
> > > >
> > > > __interrupt void TimerA1 (void)
> > > > {
> > > > switch (TAIV)
> > > > {
> > > > case TACC_x:
> > > > TACCRx = Period;
> > > > break;
> > > > }
> > > > }
> > > >
> > > > I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.
> > > >
> > > > Best Regards,
> > > > Michael
> > > >
> > > >
> > > > --- In m..., Bart Oegema wrote:
> > > > >
> > > > > I think you're still missing it. You're both lengthening and
> > > > > shortening the duty cycle in your application, but this only happens
> > > > > when you're making the duty cycle shorter. Look closely at Michael's
> > > > > example and hint.
> > > > >
> > > > > - Bart
> > > > >
> > > > > On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> > > > > >
> > > > > >
> > > > > >
> > > > > > 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.
> > > > > > > > > > >> >> >
> > > > > > > > > > >> >> >
> > > > > > > > > > >> >>
> > > > > > > > > > >> >
> > > > > > > > > > >> >
> > > > > > > > > > >>
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Hello Michael,

Sorry to keep pestering you.

Below is my understanding for continous mode of TimerB.

In continuous mode for TimerB to generate the PWM,TBCCR0 and TBCCR5 will come into picture. TBCCR5 is my code requirement while the TBCCR0 is default. I have selected the output mode 3 which is set/reset. When TBR=TBCCR5, the EQUx event will set the pin and when TBR=TBCCR0, EQUx event will reset the pin. So I need to handle both the TBCCR0 and TBCCR5.

Please clarify if I am wrongly interpreting the continuous mode.

Thanks in advance.
--- In m..., "Michael" wrote:
>
> I really can't tell you anything more. I think I made it quite clear what your problem is and how to solve it, even babystep guided you. If you still can't make it work, the only advice I have left would be a change of career.
>
> Regards,
> Michael K.
>
> --- In m..., "ti2tt" wrote:
> >
> > Hello Forum members,
> >
> > Has anyone experienced similar issues with PWM? Please share your views. I am in desperate need for the solution. Request you all for the help.
> >
> > Thanks in advance.
> > --- In m..., "ti2tt" wrote:
> > >
> > > Hello Michael,
> > >
> > > Thanks for your kind help. I am still to get the classic mistake cleared. I hope you will be kind enough to give me the right solution. Your earliest help will be highly appreciated. Thanks in advance.
> > > --- In m..., "Michael" wrote:
> > > >
> > > > At this point you really should have enought data to arrive at the right conclusion and be able to solve your problem. But to not be cruel and spare you the suffering (althought Onestone may say the contrary ;-) ):
> > > >
> > > > Your problem is that by changing TACCRx to a lower value than the present count of TAR, you are missing that periods EQUx event, thus only after TAR rolles over will the EQUx event (TACCRx = TAR) occur and change the pin state. Remember the Compare Module only looks for the event in which TACCRx is equal to TAR, setting the EQUx internal signal, which in turn affects the OUTPUTx unit. EQUx sets only while TACCRx = TAR, not while TACCRx >= TAR. Understanding this is the center of your issue.
> > > >
> > > > It will be helpful for you to read the timerB chapter. Timer B has additional options to solve this problem on the hardware level, automatically choosing when to load the real (and hidden) compare register TBCLx with the value in TBCCRx.
> > > >
> > > > Short answer, you need to check if TAR is still lower than the new value of TACCRx you want to write:
> > > > while (value > (TAR-20) // Check if new value is too close or past TAR.
> > > > ; //Wait until TAR rolles over
> > > > TACCR = value;
> > > >
> > > > Better yet, don't change TACCRx directly. Instead use a global variable, for example PERIOD, and use TACCRx interrupt to write that value into TACCRx. As long as you aren't using a bit toggle mode, but reset/set or set/reset, all should work fine.
> > > >
> > > > __interrupt void TimerA1 (void)
> > > > {
> > > > switch (TAIV)
> > > > {
> > > > case TACC_x:
> > > > TACCRx = Period;
> > > > break;
> > > > }
> > > > }
> > > >
> > > > I hope I was not too condescending in giving you the answer instead of leading you to it as I first intended and tried.
> > > >
> > > > Best Regards,
> > > > Michael
> > > >
> > > >
> > > > --- In m..., Bart Oegema wrote:
> > > > >
> > > > > I think you're still missing it. You're both lengthening and
> > > > > shortening the duty cycle in your application, but this only happens
> > > > > when you're making the duty cycle shorter. Look closely at Michael's
> > > > > example and hint.
> > > > >
> > > > > - Bart
> > > > >
> > > > > On Wed, Sep 16, 2009 at 12:28 AM, ti2tt wrote:
> > > > > >
> > > > > >
> > > > > >
> > > > > > 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.
> > > > > > > > > > >> >> >
> > > > > > > > > > >> >> >
> > > > > > > > > > >> >>
> > > > > > > > > > >> >
> > > > > > > > > > >> >
> > > > > > > > > > >>
> > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
>

> When TBR=TBCCR5, the EQUx event will set the pin and when
> TBR=TBCCR0, EQUx event will reset the pin. So I need to handle both
> the TBCCR0 and TBCCR5.

Yes... almost. Only EQUx doesn't use TBCCRx but TBCLx, which is an internal (invisible) register. You can control when TBCLx is automatically loaded with the value in TBCCRx by means of the CLLDx bits in TBCCTLx register. Any mode but CLLD_0 will solve your problem and you won't have missed EQUx events, so no jumps to DC0% when changing to a lower DC.

Michael K.

--- In m..., "ti2tt" wrote:
>
> Hello Michael,
>
> Sorry to keep pestering you.
>
> Below is my understanding for continous mode of TimerB.
>
> In continuous mode for TimerB to generate the PWM,TBCCR0 and TBCCR5
> will come into picture. TBCCR5 is my code requirement while the
> TBCCR0 is default. I have selected the output mode 3 which is
> set/reset. When TBR=TBCCR5, the EQUx event will set the pin and when
> TBR=TBCCR0, EQUx event will reset the pin. So I need to handle both
> the TBCCR0 and TBCCR5.
>
> Please clarify if I am wrongly interpreting the continuous mode.
>
> Thanks in advance.


Memfault Beyond the Launch