How to get at the PWM signals of the MSP432 LaunchPad with TI-RTOS The TI-RTOS examples for the MSP432 LaunchPad all route the PWM signals to an RGB LED. That's ideal for examples. But what if you need the signals for something else? This blog shows how to connect PWM output to BoosterPack connector pins. |
What you need:
- MSP432 LaunchPad
- 1 micro-USB cable
- Code Composer Studio
- TI-RTOS for MSP43X
For your project, you may need PWM signals to control a motor, drive external LEDs, ...
By default, if you use TI-RTOS projects, there are two PWM sources defined. They both are linked to the on-board RGB LED.
To give your project PWM signals, it would be great to get them linked to pins on the BoosterPack connectors.
There's more than one way to get PWM access on those BoosterPack connectors.
We could add additional PWM definitions and leave the on-board RGB LED connected.
For this example I've taken another path: switch the existing PWM0 and PWM1 signal away from the RGB LED and route them to BoosterPack connector J4.
I'm choosing the second and third pin on P4, P2.6 and P2.4. You are free to choose other GPIO pins.
Start by loading the TI-RTOS PWM LED example. It's available via Resource Explorer, under the Driver examples for your LaunchPad.
Follow these steps to import the project:
Start Code Composer Studio.
Menu View -> Resource Explorer
Navigate to TI-RTOS for MSP43x -> Development Tools -> MSP-EXP432x -> PWM Examples -> PWM LED Example
Build and Run the example. You should see the RGB LED gradually increase brightness until maximum.
If you'd put a scope on the two rightmost jumpers above the LED, you 'd see signals like this, with a continuously changing duty cycle:
It's those signals that we want to move to the two BoosterPack pins.
All the work is done in the source file MSP_EXP432P401R.c.
We have to make two changes. The first one is to make P2.6 and P2.4 PWM pins, instead of the LED-connected pins P2.1 and P2.2
const PWMTimerMSP432_HWAttrsV1 pwmTimerMSP432HWAttrs[MSP_EXP432P401R_PWMCOUNT] = { { .timerBaseAddr = TIMER_A1_BASE, .clockSource = TIMER_A_CLOCKSOURCE_SMCLK, .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1, .gpioPort = GPIO_PORT_P2, .gpioPinIndex = GPIO_PIN6, .pwmMode = GPIO_PRIMARY_MODULE_FUNCTION }, { .timerBaseAddr = TIMER_A1_BASE, .clockSource = TIMER_A_CLOCKSOURCE_SMCLK, .compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_2, .gpioPort = GPIO_PORT_P2, .gpioPinIndex = GPIO_PIN4, .pwmMode = GPIO_PRIMARY_MODULE_FUNCTION } };
Then change the PWM port map for GPIO port 2. Connect timer signal TA1CCR1A to 2.6, 2A to P2.4.
You do that by setting in the map to what bit (= pin) of the port each of those signals goes.
/* * ======== MSP_EXP432P401R_initPWM ======== */ void MSP_EXP432P401R_initPWM(void) { /* Use Port Map on Port2 get Timer outputs on pins 2.4, 2.6) */ /* this is different then the standard mapping for the Launchpad * that puts Timer outputs on pins with LEDs (2.1, 2.2) * Board_PWM0 mapped to 2.6 * Board_PWM1 mapped to 2.4 */ const uint8_t portMap [] = { PM_NONE, PM_NONE, PM_NONE, PM_NONE, PM_TA1CCR2A, PM_NONE, PM_TA1CCR1A, PM_NONE }; /* Mapping capture compare registers to Port 2 */ MAP_PMAP_configurePorts((const uint8_t *) portMap, PMAP_P2MAP, 1, PMAP_DISABLE_RECONFIGURATION); PWM_init(); }
If you now Build and Run the program, the LED will no longer blink. You'll find your 2 PWM signals back on BoosterPack connector J2, P2.6 and P2.4.
You can check this with a logic analyzer or a scope, as in the picture below:
You can now use these signals to drive your project.
Top Comments