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.

MSP430FR2355: Set-up of Timer_B as a PWM

Part Number: MSP430FR2355

Greetings.

I am using a MSP430FR2355 LaunchPad board, and trying to set up a PWM output on P6.0 and P6.1

I found some example code in another forum post. It had to be modified to use different timer instances, so there is probably an error here.

Here is the code I am using:

    P6DIR = 0x03;               // make P6.0 and P6.1 as outputs. Values from table 6-68 in DS.
    P6SEL0 = 0x03;              // Connect P6.0 with TB3.1. Connect P6.1 with TB3.2

    // set-up from E2E support forum
    // e2e.ti.com/.../614877
    TB3CCR0 = 0;
    TB3CCR1 = 0;

    //TB0CCTL1 = CCLD_1 | OUTMOD 6;
    TB0CCTL1 = 0x02C0;

    //TB0CTL = TBSSEL_SMCLK + MC_UP + ID_2 + TBCLR;
    TB0CTL = 0x0254;

    TB3CCR0 = 100;
    TB3CCTL0 = CLLD_3;
    TB3CCR1 = 50;

The compiler was not seeing the definitions for items such as CCLD_1, OUTMOD6, ... so I hard-coded these on the line below

Thanks in advance for the help!

  • Hey Stephen,

    All MSP430FR2355 Code examples can be found in resource explorer.  You can access it via the web or in CCS.  Here they are:http://dev.ti.com/tirex/explore/node?node=ACqyBhoKY-mma1YuW1PofA__IOGqZri__LATEST

    This example outputs PWMs on P6.0-P6.3 and should be very close to what you need.  Try running it on your launchpad: http://dev.ti.com/tirex/explore/node?node=APK1q.nW0y7-SXlpQdIsRQ__IOGqZri__LATEST 

    Thanks,

    JD

  • The code example is great, and I am able to see the PWM toggle.

    The only issue is that the example code enters LPM3 and it seems to require LPM3 mode for the PWM to function.

        WDTCTL = WDTPW | WDTHOLD;                         // Stop WDT
    
        // Configure GPIO
        P6DIR |= BIT0 | BIT1 | BIT2 | BIT3;               // P6.0 P6.1 P6.2 P6.3 output
        P6SEL0 |= BIT0 | BIT1 | BIT2 | BIT3;              // P6.0 P6.1 P6.2 P6.3 options select
        P2SEL1 |= BIT6 | BIT7;                            // P2.6~P2.7: crystal pins
        do
        {
            CSCTL7 &= ~(XT1OFFG | DCOFFG);                // Clear XT1 and DCO fault flag
            SFRIFG1 &= ~OFIFG;
        }while (SFRIFG1 & OFIFG);                         // Test oscillator fault flag
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Setup Timer3_B
        TB3CCR0 = 100-1;                                  // PWM Period
        TB3CCTL1 = OUTMOD_7;                              // CCR1 reset/set
        TB3CCR1 = 80;                                     // CCR1 PWM duty cycle
        TB3CCTL2 = OUTMOD_7;                              // CCR2 reset/set
        TB3CCR2 = 50;                                     // CCR2 PWM duty cycle
        TB3CCTL3 = OUTMOD_7;                              // CCR3 reset/set
        TB3CCR3 = 30;                                     // CCR3 PWM duty cycle
        TB3CCTL4 = OUTMOD_7;                              // CCR4 reset/set
        TB3CCR4 = 20;                                     // CCR4 PWM duty cycle
        TB3CTL = TBSSEL_1 | MC_1 | TBCLR;                 // ACLK, up mode, clear TBR
    
        __bis_SR_register(LPM3_bits);                     // Enter LPM3
        __no_operation();                                 // For debug

    I don't want to enter LPM3 mode, so how can the PWM function with the part running in normal mode?

  • PWM doesn't require LPM3 to run. What that LPM3 line does is prevent your program from exiting. By replacing it with something like

    >     while (1) /*EMPTY*/;  // Spin forever

    you can get the same effect (only busier).

    That said: I don't see your symptom. The PWM (LED on P6.3) continues whether I use LPM3, while(1), or nothing. In the latter case it goes off to abort() and spins, but the PWM doesn't stop.

    If you pause in the debugger, where is your program executing?

  • Getting closer to figuring this one out. When I set up a comparator, the PWM stops functioning. I don't understand why this would happen, but I can duplicate it with the sample code.

    Please try running this code:

    #include <msp430.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;                         // Stop WDT
    
        // Configure GPIO
        P6DIR |= BIT0 | BIT1 | BIT2 | BIT3;               // P6.0 P6.1 P6.2 P6.3 output
        P6SEL0 |= BIT0 | BIT1 | BIT2 | BIT3;              // P6.0 P6.1 P6.2 P6.3 options select
        P2SEL1 |= BIT6 | BIT7;                            // P2.6~P2.7: crystal pins
        do
        {
            CSCTL7 &= ~(XT1OFFG | DCOFFG);                // Clear XT1 and DCO fault flag
            SFRIFG1 &= ~OFIFG;
        }while (SFRIFG1 & OFIFG);                         // Test oscillator fault flag
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Setup Timer3_B
        TB3CCR0 = 100-1;                                  // PWM Period
        TB3CCTL1 = OUTMOD_7;                              // CCR1 reset/set
        TB3CCR1 = 80;                                     // CCR1 PWM duty cycle
        TB3CCTL2 = OUTMOD_7;                              // CCR2 reset/set
        TB3CCR2 = 50;                                     // CCR2 PWM duty cycle
        TB3CCTL3 = OUTMOD_7;                              // CCR3 reset/set
        TB3CCR3 = 30;                                     // CCR3 PWM duty cycle
        TB3CCTL4 = OUTMOD_7;                              // CCR4 reset/set
        TB3CCR4 = 20;                                     // CCR4 PWM duty cycle
        TB3CTL = TBSSEL_1 | MC_1 | TBCLR;                 // ACLK, up mode, clear TBR
    
        // code which causes PWM to stop working.
        CP1INT = 0;             // clear interrupt flags.
        CP1CTL0 = 0x1016;       // set up comparator inputs.
        CP1CTL1 = BIT9;         // enable comparator.
        CP1DACCTL = 0x0080;     // turn on the DAC.
        CP1DACDATA = 0x2020;    // mid point for DAC output. This covers both DACBUF. 0x2020 is 1.65V
    
        while(1);
    }

    During the CP1 set-up, the PWM starts misbehaving, and putting out bad signals. After CP1 is set up, the PWM no longer comes out on P6.0

    Thanks for your help with this.

  • After setting up CP1, the PWM either doesn't come out, or is corrupted. This signal should be 80% duty cycle:

    It always works properly if I don't initialize CP1.

  • When CPOUT goes to 1, that triggers the disable (TBOUTH) signal to TB3 [Ref User Guide (SLAU445I) Sec 14.2.5]. Try:

    > SYSCFG2 |= TB3TRGSEL; // Force TB3OUTH source to External (no pin assigned)

    This switches the TB3OUTH source from the eCOMP1 CPOUT to an external pin (which conveniently doesn't exist). [Ref data sheet (SLASEC4B) Table 6-20]

  • This solved the problem - much Thanks!

**Attention** This is a public forum