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.

MSP432 driverlib pwm

Other Parts Discussed in Thread: ENERGIA

Hi everyone,

I got some troubles with the function: Timer_A_generatePWM(). The code compile well, but my led doesn't light up. 

Here is my code:

int main(void)
{
    /* Stop Watchdog  */
	WDT_A_holdTimer();

    MAP_SysTick_enableModule();
    MAP_SysTick_setPeriod(600000);
    MAP_SysTick_enableInterrupt();
    MAP_Interrupt_enableMaster();
    MAP_SysTick_registerInterrupt(SysTick_isr);

    Timer_A_PWMConfig pwmConfig =
    {
    	TIMER_A_CLOCKSOURCE_SMCLK,
	TIMER_A_CLOCKSOURCE_DIVIDER_1,
	300, 
	TIMER_A_CAPTURECOMPARE_REGISTER_0,
	TIMER_A_OUTPUTMODE_RESET_SET,
	150
    };

    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, GPIO_PIN6, GPIO_PRIMARY_MODULE_FUNCTION);
    Timer_A_generatePWM(TIMER_A0_MODULE, &pwmConfig);

    uint16_t compt = 0;

    for(compt = 0; compt < 300; compt++)
    {
    	pwmConfig.dutyCycle = compt;
    	Timer_A_generatePWM(TIMER_A0_MODULE, &pwmConfig);
    	delay(20);
    }
}

Even the example of driverlib, copied and pasted, doesn't work. the hardware seems to be ok because the pwm works when i have tried it using energia IDE and the function AnalogWrite().

what did i forget ?

I am out of ideas, any help would be welcome.

I thank you in advance.

  • Louis Bazin said:
    The code compile well, but my led doesn't light up.

    Can you clarify which pin your LED is connected to?

    The reason is that the GPIO_setAsPeripheralModuleFunctionOutputPin function call specifies P5.6, yet the Timer_A_generatePWM function call is configuring TA0.0 as the output and the default output pin for TA0.0 is P7.3

    The Port Mapping Controller in the MSP432P401R allows the Timer Compare outputs to be mapped to any pin on ports P2, P3 and P7.

    The MSP-EXP432P401R LaunchPad has the RGB LED connected to P2.0, P2.1 and P2.2. The following modification to the main function in the timer_a_pwm_mode MSPware Driver Library example maps the TA0.0 timer output to all three pins P2.0, P2.1 and P2.2 via a call to MAP_PMAP_configurePorts. This causes the timer PWM output to flash the RGB LED as white:

    int main(void)
    {
    	/* Port mapper configuration register */
    	const uint8_t port_mapping[] =
    	{
    	//Port P2:
        PM_TA0CCR0A, PM_TA0CCR0A, PM_TA0CCR0A, PM_NONE, PM_NONE, PM_NONE, PM_NONE, PM_NONE
    	};
    
    	/* Halting the watchdog */
        MAP_WDT_A_holdTimer();
    
        /* Setting MCLK to REFO at 128Khz for LF mode
         * Setting SMCLK to 64Khz */
        MAP_CS_setReferenceOscillatorFrequency(CS_REFO_128KHZ);
        MAP_CS_initClockSignal(CS_MCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
        MAP_CS_initClockSignal(CS_SMCLK, CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_2);
        MAP_PCM_setPowerState(PCM_AM_LF_VCORE0);
    
        /* Remapping TACCR0 to P2.0 */
        MAP_PMAP_configurePorts((const uint8_t *) port_mapping, P2MAP, 1, PMAP_DISABLE_RECONFIGURATION);
    
        /* Configuring GPIO2.0, GPIO2.1 and GPIO2.2 as peripheral output for PWM  and P1.1 for button
         * interrupt */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN0 | GPIO_PIN1 | GPIO_PIN2,
                GPIO_PRIMARY_MODULE_FUNCTION);
        MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
        MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
        MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
    
        /* Configuring Timer_A to have a period of approximately 500ms and
         * an initial duty cycle of 10% of that (3200 ticks)  */
        MAP_Timer_A_generatePWM(TIMER_A0_MODULE, &pwmConfig);
    
        /* Enabling interrupts and starting the watchdog timer */
        MAP_Interrupt_enableInterrupt(INT_PORT1);
        MAP_Interrupt_enableSleepOnIsrExit();
        MAP_Interrupt_enableMaster();
    
        /* Sleeping when not in use */
        while (1)
        {
            MAP_PCM_gotoLPM0();
        }
    }
    

  • hi Chester,

    thank you for your prompt reply. You are right for the port mapping, my code works much better.
    thank you very much.
  • You mention " Timer_A_generatePWM function call is configuring TA0.0 as the output and the default output pin for TA0.0 is P7.3

    The Port Mapping Controller in the MSP432P401R allows the Timer Compare outputs to be mapped to any pin on ports P2, P3 and P7."

    I've searched around but I can't find information on what the default output pins are for the various timers and their registers or how to map those to other pins. Can you cite a reference where I can find that information for the MSP432?

    Thanks!
  • Ron Gans said:
    I've searched around but I can't find information on what the default output pins are for the various timers and their registers or how to map those to other pins. Can you cite a reference where I can find that information for the MSP432?

    1) Section 6.8.2 Port Mapping Controller (PMAPCTL) of the MSP432P401x Mixed-Signal Microcontrollers datesheet SLAS826A defines:
    - Which digital functions can be mapped to different pins

    - The default pin mapping

    2) Section 11 Port Mapping Controller (PMAP) of the MSP432P4xx Family Technical Reference Manual SLAU356A defines the registers used to change the mapping.

  • That's what I was looking for. Thanks.

**Attention** This is a public forum