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.

Using Timer B as a PWM

Other Parts Discussed in Thread: MSP430F2274, MSP430F2001, MSP430F2618

Hi, I need to run 2 PWM and they must not use the CPU, so I'm using the TimerA and TimerB.

On timer A, the PWM is perfect and during the program I just change the register TACCR1 to change the duty cycle. So I tried to do something like timer A, into timer B, but didn't work, I only changed the period, but not the duty cycle.

 

void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
P2DIR |= 0x0C;                            // P1.2 and P1.3 output
P2SEL |= 0x0C;                            // P1.2 and P1.3 TA1/2
TACCR0 = 0x9AB3 - 1;                         // PWM Period
TACCTL1 = OUTMOD_7;                       // TACCR1 reset/set
TACCR1 = 0;
// TACCR1 PWM duty cycle
TACTL = TASSEL_2 + ID_2 + MC_1;   

/*  What do I need to change below, to work the same way as Timer A (above)? */

P4DIR |= 0x0C;                           
P4SEL |= 0x0C;
TBCCR0 = 0x9AB3 - 1;                        
TBCCTL0 = OUTMOD_4;                      
TBCTL = TBSSEL_2 + ID_1 + MC_1 + CLLD_2; 

}

 

Thanks,

Lucas

  • P4DIR |= 0x02; // P4.1 output

    P4SEL |= 0x02; // P4.1 TB1

    TBCCR0 = ???? - 1; // Period

    TBCCTL1 = OUTMOD_7; // reset/set

    TBCCR1 = ???; // duty cycle

    TBCTL = TBSSEL_2 + ID_1 + MC_1;

  • Thanks, but this didn't work.

    I don't think it makes much diference, but I am using the eZ430 RF2500 (MSP430F2274).

    Is there any other options?

  • Where did you look for the output? (Which pin?)

  • I tested all the pins with an oscilloscope, but I just found the TimerA's PWM.

     

    Leaving the way below, it works but there is a square sign, changing the OUTMOD to 7, I see that the TimerB's output starts at 0 but do not change, if I change to set/reset, the same happens, it starts at 1, but do not change.

    (just to certify, I tested with a brand knew msp430f2274, and got the same results)

    P4DIR = 0x0C;

    P4SEL = 0x0C;

    TBCCR0 = 0x9AB3 - 1;

    TBCCTL1 = OUTMOD_4;

    TBCCR1 = 0x0700;

    TBCTL = TBSSEL_2 + ID_1 + MC_1;

     

  • You set up the wrong pins. You only need one pin and it is not included in your setup.

    See my reply on 9-15

    BTW, you also set up two pin for TimerA. In this case the pin you needed was included, thus it worked. Not so for TImerB.

  • Your first reply is perfect.

    Looking at eZ430 RF2500 User´s Guide, I didn´t find the pin P4.0 and P4.1. After I looked for these pins at MSP430F2274´s datasheet and they were there. So I looked for these pins at the eZ430 RF2500  board and these pins really exist, but they end at the microcontroller. So I tested with the oscilloscope and the PWM was there. Unfortunatelly there is no output for the pins P4.0 and P4.1 (it´s impossible to use that directly at the microcontroller).

    So the problem changed a little. How can I get the PWM at any other pins like P4.2 P4.3 or P4.4 ?

     

  • TI designed a collection of “modules” for the MSP430F2xx “family” of chips. Then they picked various subsets and combinations of these “modules” to implement various chips, such as MSP430F2001, MSP430F2618, etc. The details of these modules are described in the MSP430F2xx Family User’s Guide (slau144?.pdf where “?” is the version and is currently e). When you read this Guide, be aware that the particular chip you are using may not have the module you are reading. Even if that module is included, it may have additional limitations in that chip.

    Each module needs a number of input or output signals. How these signals are connected to other modules or the outside world are not (and cannot be) described in the Guide. The timing and electrical characteristics of the signals may also depends on the specific implementation of the chip. Thus all these chip specific information are described in the data-sheet of each chip. When you read the data-sheet, be aware that the details of the module are already included in the Guide and in most cases are not repeated in the data-sheet.

    When a MSP430F2xx is on a board, of course you need to know which pins are connected to what. Other than that, any additional information is a bonus but not a substitute of the Guide and the data-sheet.

    In your case:

    TA1 output can be set up to appear at P1.2 (used in your board to read a switch), P1.6 (not connected to anything), or P2.3 (connected to P6).

    TA2 output can be set up to appear at P1.3 (not connected to anything on your board), P1.7 (not connected to anything), or P2.4 (connected to P7).

    TB1 output can be set up to appear at P4.1 (not connected to anything) or P4.4 (connected to P9).

    TB2 output can be set up to appear at P4.2 (not connected to anything) or P4.5 (connected to P10).

    P1.1 and P4.0 are of no use to this kind of PWM.

**Attention** This is a public forum