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(¶ms); params.dutyUnits = PWM_DUTY_US; params.dutyValue = 0; params.periodUnits = PWM_PERIOD_US; params.periodValue = pwmPeriod; pwm1 = PWM_open(Board_PWM0, ¶ms); if (pwm1 == NULL) { /* Board_PWM0 did not open */ while (1); } PWM_start(pwm1); pwm2 = PWM_open(Board_PWM1, ¶ms); if (pwm2 == NULL) { /* Board_PWM0 did not open */ while (1); } PWM_start(pwm2); pwm3 = PWM_open(Board_PWM2, ¶ms); 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, ¶ms); 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