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 TI-RTOS PWM on TA0

Other Parts Discussed in Thread: MSPWARE

Good day! Please help me set up PWM on Timer_A0 using TI-RTOS APIs. Default PWM init on TA1 with port remapping on P2.1 and P2.2 (LED_GREEN and LED_BLUE for PWM examples). I want to use P2.4 and P2.5 (TA0.1 and TA0.2). I assume that it is necessary to make changes in Board.h, MSP_EXP432P401.h and MSP_EXP432P401.c files. But my program calls abort. Apparently I don't consider something.

I made the following changes:

Board.h
...
#define Board_PWM0                  MSP_EXP432P401R_PWM_TA0_1
#define Board_PWM1                  MSP_EXP432P401R_PWM_TA0_2
...

MSP_EXP432P401R.h
...
typedef enum MSP_EXP432P401R_PWMName {
    MSP_EXP432P401R_PWM_TA0_1 = 0,
    MSP_EXP432P401R_PWM_TA0_2,

    MSP_EXP432P401R_PWMCOUNT
} MSP_EXP432P401R_PWMName;
...

const PWMTimerMSP432_HWAttrs pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWMCOUNT] = {
    {
        .baseAddr = TIMER_A0_BASE,
        .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1
    },
    {
        .baseAddr = TIMER_A0_BASE,
        .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2
    }
};

MSP_EXP432P401R.c
...
void MSP_EXP432P401R_initPWM(void)
{
    /* Enable PWM output on GPIO pins */
    GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
        GPIO_PIN4 | GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);

    PWM_init();
}
...

Thanks!

  • Hi Artem,

    Can you post the abort message from your application? Also, which version of TI-RTOS are you using?

    Vikram
  • Yes, "Board_PWM0 did not open", TI-RTOS version is 2.16.00.08, MSPWare version is 3.10 and XDCtools version is 3.31.1.33. (CCS 6.1 is completely updated). Project is pwmled examle. I don't change the pwmled.c file.

  • Can you share your board files?

    Vikram
  • Yes of course. 7-zip archive with project folder.1106.pwmled_MSP_EXP432P401R_TI_MSP432P401R.7z

  • I was looking at the Clock configuration details in TI-RTOS, by default the Timer A0 is used to set-up Clock Timer. So the question - is running PWM on Timer A0 a requirement for your project? If yes, then you will need to update the Clock configuration in your application .cfg file to use a different Timer instead of Timer A0 for Clock operations.

    Vikram
  • Thank you very much! The problem has a simple solution.
  • Any chance you could elaborate on this, I'm working on a similar project where I'm using a altered version of the example to run pwm on a few motors.
  • Hello, Asmir. Sorry, but I do not understand your question. I used two PWM for motors control.
  • Hi, 

    I'm also using it for motor control. From the advise you received, how did you end up setting up the actual clock. Furthermore, how would I go about adding more GPIO ports to this code?

  • Ok, I will give an example for CCS 6.1.1 and TI-RTOS 2.16. The first thing you need to do is to determine what timers you'll use. So I used Timer A0 instead of Timer A1. By default the Timer A1 is used to set-up PWM, and the Timer A0 is used to set-up Clock Timer. So you need to update the Clock configuration in your application .cfg file to use a different Timer instead of Timer A0 for Clock operations:

    Double click on *.cfg, next click on 'TI-RTOS Kernel' -> 'Clock'. Change 'Timer Id' in 'Timer Control' field, save, close the file.

    Now open Board.h file and find next definition:

    #define Board_PWM0                  MSP_EXP432P401R_PWM_TA1_1
    #define Board_PWM1                  MSP_EXP432P401R_PWM_TA1_2

    Change to:

    #define Board_PWM0                  MSP_EXP432P401R_PWM_TA0_1
    #define Board_PWM1                  MSP_EXP432P401R_PWM_TA0_2

    If you need more PWMs, add definitions (here I'll use two additional PWMs on Timer A0):

    #define Board_PWM2                  MSP_EXP432P401R_PWM_TA0_3
    #define Board_PWM3                  MSP_EXP432P401R_PWM_TA0_4

    Ok, next. Open MSP_EXP432P401R.h file and find next definition:

    typedef enum MSP_EXP432P401R_PWMName {
        MSP_EXP432P401R_PWM_TA1_1 = 0,
        MSP_EXP432P401R_PWM_TA1_2,
    
        MSP_EXP432P401R_PWMCOUNT
    } MSP_EXP432P401R_PWMName;

    Change to:

    typedef enum MSP_EXP432P401R_PWMName {
        MSP_EXP432P401R_PWM_TA0_1 = 0,
        MSP_EXP432P401R_PWM_TA0_2,
    
        MSP_EXP432P401R_PWMCOUNT
    } MSP_EXP432P401R_PWMName;

    If you need more, add:

    typedef enum MSP_EXP432P401R_PWMName {
        MSP_EXP432P401R_PWM_TA0_1 = 0,
        MSP_EXP432P401R_PWM_TA0_2,
        MSP_EXP432P401R_PWM_TA0_3,
        MSP_EXP432P401R_PWM_TA0_4,
    
        MSP_EXP432P401R_PWMCOUNT
    } MSP_EXP432P401R_PWMName;

    Now toggle to MSP_EXP432P401R.c file. Find the PWM sector and change:

    /*
     *  =============================== PWM ===============================
     */
    /* Place into subsections to allow the TI linker to remove items properly */
    #if defined(__TI_COMPILER_VERSION__)
    #pragma DATA_SECTION(PWM_config, ".const:PWM_config")
    #pragma DATA_SECTION(pwmTimerMSP432HWAttrs, ".const:pwmTimerMSP432HWAttrs")
    #endif
    
    #include <ti/drivers/PWM.h>
    #include <ti/drivers/pwm/PWMTimerMSP432.h>
    
    PWMTimerMSP432_Object pwmTimerMSP432Objects[MSP_EXP432P401R_PWMCOUNT];
    
    const PWMTimerMSP432_HWAttrs pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWMCOUNT] = {
        {
            .baseAddr = TIMER_A0_BASE,
            .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1
        },
        {
            .baseAddr = TIMER_A0_BASE,
            .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2
        },
        {
            .baseAddr = TIMER_A0_BASE,
            .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_3
        },
        {
            .baseAddr = TIMER_A0_BASE,
            .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_4
        }
    };
    
    const PWM_Config PWM_config[] = {
        {
            .fxnTablePtr = &PWMTimerMSP432_fxnTable,
            .object = &pwmTimerMSP432Objects[0],
            .hwAttrs = &pwmTimerMSP432HWAttrs[0]
        },
        {
            .fxnTablePtr = &PWMTimerMSP432_fxnTable,
            .object = &pwmTimerMSP432Objects[1],
            .hwAttrs = &pwmTimerMSP432HWAttrs[1]
        },
        {
            .fxnTablePtr = &PWMTimerMSP432_fxnTable,
            .object = &pwmTimerMSP432Objects[2],
            .hwAttrs = &pwmTimerMSP432HWAttrs[2]
        },
        {
            .fxnTablePtr = &PWMTimerMSP432_fxnTable,
            .object = &pwmTimerMSP432Objects[3],
            .hwAttrs = &pwmTimerMSP432HWAttrs[3]
        },
        {NULL, NULL, NULL}
    };
    
    /*
     *  ======== MSP_EXP432P401R_initPWM ========
     */
    void MSP_EXP432P401R_initPWM(void)
    {
        /* Enable PWM output on GPIO pins */
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
            GPIO_PIN4 | GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);
    
        MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
            GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);
    
        PWM_init();
    }

    For example, how initialize PWM in your main *.c file of project, see: View -> Resource Explorer.