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.

CCS/MSP430FR4133: PWM for P1.0 or P4.0

Part Number: MSP430FR4133


Tool/software: Code Composer Studio

int main(void) {
		WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
		P1DIR |= 0x00; //Set pin 1.0 to the output direction.
	    P1SEL0 |= 0x00; //Select pin 1.0 as our PWM output.
	    TA0CCR0 = 1000-1; //Set the period in the Timer A0 Capture/Compare 0 register to 1000 us.
	    TA0CCTL1 = OUTMOD_7;
	    TA0CCR1 = 800; //The period in microseconds that the power is ON. It's half the time, which translates to a 50% duty cycle.
	    TA0CTL = TASSEL_2 + MC_1; //TASSEL_2 selects SMCLK as the clock source, and MC_1 tells it to count up to the value in TA0CCR0.
	    __bis_SR_register(LPM0_bits); //Switch to low power mode 0.
}

The LED 1.0 doesn't work in PWM-mode. Also if I change the code to:

int main(void) {
		WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
		P1DIR |= 0x04; //Set pin 1.2 to the output direction.
	    P1SEL0 |= 0x04; //Select pin 1.2 as our PWM output.
	    TA0CCR0 = 1000-1; //Set the period in the Timer A0 Capture/Compare 0 register to 1000 us.
	    TA0CCTL1 = OUTMOD_7;
	    TA0CCR1 = 800; //The period in microseconds that the power is ON. It's half the time, which translates to a 50% duty cycle.
	    TA0CTL = TASSEL_2 + MC_1; //TASSEL_2 selects SMCLK as the clock source, and MC_1 tells it to count up to the value in TA0CCR0.
	    __bis_SR_register(LPM0_bits); //Switch to low power mode 0.
}

...there is no function of the connected LED.

Does the MSPFR4133 supports the PWM-mode to this qutputs?
  • As I read the data sheet, P1.0 is not connected to any timer, and so can't be used for (hardware) PWM output.

    P4.0 is TA1.1, i.e. it is controlled using TA1CCR1/TA1CCTL1, and connected to TimerA1 by setting BIT0 of P4DIR and P4SEL0 (per SLAS865B Table 6-17):

    TA1CCR0 = 1000-1;
    TA1CCTL1 = OUTMOD7; // TA1.1
    TA1CCR1 = 800;
    TA1CTL = TASSEL_2 | MC_1;
    P4DIR |= BIT0; // P4.0
    P4SEL0 |= BIT0;

  • Thx for your reply, but it didn't work. Maybe I should try P1.5 tp P1.7 according to Table 6-14 with TA0-1....
  • Oh, I forgot

    PM5CTL0 &= ~LOCKLPM5;

    I was reminded of this by the example code; there's a link to it on the product page.
  • Hi Bruce,
    here is my full code, but even with your last hint it didn't work. The only thing what happened was P4.0 is activated and remains in this state.

    #include <msp430fr4133.h>
    #include <driverlib.h>
    #include "main.h"
    #include "hal_LCD.h"
    #include <stdio.h>
    #include <stdlib.h>

    void main(void)
    {
    while(1)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    PM5CTL0 &= ~LOCKLPM5;

    TA1CCR0 = 512-1;
    TA1CCR1 = 200;
    TA1CTL = TASSEL_2 | MC_1;
    TA1CCTL1 = OUTMOD_7;

    P4DIR |= BIT0; // P4.0
    P4SEL0 |= BIT0;
    __bis_SR_register(LPM0_bits); //Switch to low power mode 0.
    }
    }
  • I'm not sure what you expect to happen.

    I expect that the P4.0 LED will come on at about 40% (200/512) brightness and stay there indefinitely. It sounds as though that is what is happening.

    If you want the LED brightness to vary, you need to change TA1CCR1.
  • Here is my code, what increase the brightness. I have had a wrong understanding of PWM with a LED.

    #include <msp430fr4133.h>
    #include <driverlib.h>
    #include "main.h"
    #include "hal_LCD.h"
    #include <stdio.h>
    #include <stdlib.h>
    
    void main(void)
    {
    while(1)
    	{
    	WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    	PM5CTL0 &= ~LOCKLPM5;
    
    	TA1CCR0 = 1000-1;
    	TA1CCR1 = 0;
    	TA1CTL = TASSEL_2 | MC_1;
    	TA1CCTL1 = OUTMOD_7;
    
    	P4DIR |= BIT0; // P4.0
    	P4SEL0 |= BIT0;
    
    	while (TA1CCR1<900)
    	{
    		TA1CCR1 ++;
    		_delay_cycles(80000);
    	}
    	//__bis_SR_register(LPM0_bits); //Switch to low power mode 0.
    	}
    }
    

**Attention** This is a public forum