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/MSP-EXP432P401R: tirtos - how to start pwm on p2.0 with TIMERA0?

Part Number: MSP-EXP432P401R

Tool/software: Code Composer Studio

By modifying pwmled2_MSP_EXP432P401R_tirtos_ccs example, I have got the P2.0 on-board led dim. What I exactly did is add items in PWMName in MSP_EXP432P401R.h and MSP_EXP432P401R.c by imitating exist ones.

typedef enum MSP_EXP432P401R_PWMName {
    MSP_EXP432P401R_PWM_TA1_1 = 0,
    MSP_EXP432P401R_PWM_TA1_2,
    MSP_EXP432P401R_PWM_TA1_3,

    MSP_EXP432P401R_PWMCOUNT
} MSP_EXP432P401R_PWMName;
const PWMTimerMSP432_HWAttrsV2 pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWMCOUNT] = {
    {
        .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
        .pwmPin = PWMTimerMSP432_P2_1_TA1CCR1A
    },
    {
        .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
        .pwmPin = PWMTimerMSP432_P2_2_TA1CCR2A
    },
    {
        .clockSource = TIMER_A_CLOCKSOURCE_SMCLK,
        .pwmPin = PWMTimerMSP432_P2_0_TA1CCR4A
    }
};

const PWM_Config PWM_config[MSP_EXP432P401R_PWMCOUNT] = {
    {
        .fxnTablePtr = &PWMTimerMSP432_fxnTable,
        .object = &pwmTimerMSP432Objects[MSP_EXP432P401R_PWM_TA1_1],
        .hwAttrs = &pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWM_TA1_1]
    },
    {
        .fxnTablePtr = &PWMTimerMSP432_fxnTable,
        .object = &pwmTimerMSP432Objects[MSP_EXP432P401R_PWM_TA1_2],
        .hwAttrs = &pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWM_TA1_2]
    },
    {
        .fxnTablePtr = &PWMTimerMSP432_fxnTable,
        .object = &pwmTimerMSP432Objects[MSP_EXP432P401R_PWM_TA1_3],
        .hwAttrs = &pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWM_TA1_3]
    }
};

Also, here is my version of pwmled2.c:

/*
 *  ======== pwmled2.c ========
 */
/* For usleep() */
#include <unistd.h>
#include <stddef.h>

/* Driver Header files */
#include <ti/drivers/PWM.h>

/* Example/Board Header files */
#include "Board.h"

/*
 *  ======== mainThread ========
 *  Task periodically increments the PWM duty for the on board LED.
 */
void *mainThread(void *arg0)
{
    /* Period and duty in microseconds */
    uint16_t   pwmPeriod = 3000;
    uint16_t   duty = 0;
    uint16_t   dutyInc = 100;

    /* Sleep time in microseconds */
    uint32_t   time = 50000;
    PWM_Handle pwm1 = NULL;
    PWM_Handle pwm2 = NULL;
    PWM_Handle pwm3 = NULL;
    PWM_Params params;

    /* Call driver init functions. */
    PWM_init();

    PWM_Params_init(&params);
    params.dutyUnits = PWM_DUTY_US;
    params.dutyValue = 0;
    params.periodUnits = PWM_PERIOD_US;
    params.periodValue = pwmPeriod;
    pwm1 = PWM_open(Board_PWM0, &params);
    if (pwm1 == NULL) {
        /* Board_PWM0 did not open */
        while (1);
    }

    PWM_start(pwm1);

    pwm2 = PWM_open(Board_PWM1, &params);
    if (pwm2 == NULL) {
        /* Board_PWM0 did not open */
        while (1);
    }

    PWM_start(pwm2);

    pwm3 = PWM_open(Board_PWM2, &params);
    if (pwm3 == NULL) {
        /* Board_PWM0 did not open */
        while (1);
    }

    PWM_start(pwm3);

    /* Loop forever incrementing the PWM duty */
    while (1) {
        PWM_setDuty(pwm1, duty);

        PWM_setDuty(pwm2, duty);
        PWM_setDuty(pwm3, duty);

        duty = (duty + dutyInc);

        if (duty == pwmPeriod || (!duty)) {
            dutyInc = - dutyInc;
        }

        usleep(time);
    }
}

Everything works well and then I wanted to try and dim the P2.0 led with another Timer, and by pressing F3 on PWMTimerMSP432_P2_0_TA1CCR4A, I found:

/*!
 *  @name Port 2, Pin 0 'pwmPin' setting variations
 *  @{
 */
#define PWMTimerMSP432_P2_0_TA0CCR1A   (PWMTimerMSP432_TA0CCR1 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA0CCR2A   (PWMTimerMSP432_TA0CCR2 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA0CCR3A   (PWMTimerMSP432_TA0CCR3 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA0CCR4A   (PWMTimerMSP432_TA0CCR4 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA1CCR1A   (PWMTimerMSP432_TA1CCR1 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA1CCR2A   (PWMTimerMSP432_TA1CCR2 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA1CCR3A   (PWMTimerMSP432_TA1CCR3 | 0x20) /*!< @hideinitializer */
#define PWMTimerMSP432_P2_0_TA1CCR4A   (PWMTimerMSP432_TA1CCR4 | 0x20) /*!< @hideinitializer */

So I wondered if I can dim it with Timer0 i.e. with TA0CCR4A. But as long as I replaced this item PWMTimerMSP432_P2_0_TA1CCR4A with PWMTimerMSP432_P2_0_TA0CCR4A. The program will somehow went into the while (1) loop after pwm3 = PWM_open(Board_PWM2, &params); Though I have found the TimerA0 seems not defined in this project and I tried to do that by adding entries in timerMSP432HWAttrs and Timer_config in the MSP-EXP432P401R.c file but things still not work for me. So, how can I generate PWM on the P2.0 pin with TIMERA0? Thanks

  • The resource, TimerA0, is being used by the SYSBIOS kernel for the RTOS clock. You will not be able to use timerA0 unless you define another resource for the RTOS clock.

    Regards,
    Chris

  • Okay. My original intention is generate different frequency PWM on P2.0, P2.1 and P2.2 and that's why I want to use TIMERA0. I had tried to add another PWM_Params with different periodValue and pass it to pwm3's PWM_open but only to find it went into while(1) loop. So is there other approach that I can do this with tirtos?
  • You cannot do this, since only timerA0 and timer A1 are available on Port 2.0 through port mapping. This would only allow you to generate 2 different frequencies. If the frequency is the same and the duty cycle is different, then you could create three PWMs with one timer. Each CCRx would define the duty cycle for the PWMs.

    Regards,
    Chris

**Attention** This is a public forum