This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Timer_B PWM with long periods not working

Other Parts Discussed in Thread: MSP-EXP430F5529LP, MSP430F5529

Using the MSP-EXP430F5529LP, I was trying to verify timer_B operation by observing a PWM output. I had timer_B in continuous mode and was not getting anywhere. So I pasted code from timer_b_ex3_pwm (which has timer_B in up mode) into my project, then modified the timer_B period and duty cycle for longer and longer periods. I found that setting timer_B period to 0x8FFF will kill the PWM output, but a period of 0x7FFF will not. (I had the duty cycle widened, as well) I don't know why, because timer_B is 16-bit, so the period should extend to 0xFFFF.

Further experimenting, I found that setting the period to 0x1FFF and the duty cycle to 0x0800, the pulses come in threes, with an equal amount of dead time between groups of pulses.

I inserted a 

TIMER_B_clear (TIMER_B0_BASE);

statement at the beginning to make sure all 16 bits are active, but it makes no difference.


I know PWM (albeit slow) is possible in continuous mode, but if PWM will not even operate past 0x7FFF period, I can't see how this will happen. Any ideas?

  • Otto Hunt said:
    period to 0x8FFF will kill the PWM output, but a period of 0x7FFF will not

    It looks like you have a mixed environment with ‘unsigned’ and ‘signed’ integers, here you should use only ‘unsigned int’.

    If you would post your current code and the time interval in mS (or whatever) you need, we probably could give you more help.

  • This code produces a 0.5sec pulse every 2.0sec at P3.6/TB0.6 pin.

    #include "msp430f5529.h"

    void main( void )
    {
      WDTCTL = WDTPW + WDTHOLD;
      P3DIR = P3SEL = BIT6;     // TB0.6
      TB0CCR0 = 0xFFFF;
      TB0CCR6 = 0x4000;
      TB0CCTL6 = OUTMOD_7;      // Reset/Set
      TB0CTL = TBSSEL_1 | MC_1; // ACLK, Up-mode
      while (1);                // do nothing
    }

  • Thanks, Leo,

    i tried sticking an unsigned variable into timer_B_ex4_UpmodeOperation, but it had no effect, AND I can have any period I want. It was when I pasted that code into my larger project that I got such weird behavior. I got it resolved now, using a different approach, but I will remember your suggestion.

    Thanks for the tidy little code, old_cow_yellow, it works great. It is a hand test of timer operation.

  • In cont mode, you can’t set the period. CCR0 is then no different than the other CCRs. The period is always 0x10000.
    It is UP mode where CCR sets the period.
    As for the group of three, I don’t know. Without touching the timer, the outcome must be a simple periodic signal, not a structured one. So I guess other parts of your code are also messing with the timer.

  • Useful information. Thanks, Jens-Michael.

**Attention** This is a public forum