Part Number:MSP432P401R
Tool/software: Code Composer Studio
hello,
I modified successfully a demo MSP432P401R code, originally called timer_a_pwm_mode.c (relevant section copied below).
I would like to extend this code to generate a 2nd PWM output on P2.5, which is Table 6-45 Default Mapping (Port Mapping Controller/Port Mapping Definitions)
PDF SLAS826G –MARCH 2015–REVISED SEPTEMBER 2017
"MSP432P401R, MSP432P401M SimpleLink™ Mixed-Signal Microcontrollers" indicated as:
PIN NAME | PxMAPy MNEMONIC | INPUT PIN FUNCTION | OUTPUT PIN FUNCTION |
P2.5/PM_TA0.2 | PM_TA0CCR2A | TA0 CCR2 capture input CCI2A | TA0 CCR2 compare output Out2 |
P2.4/PM_TA0.1(1) | PM_TA0CCR1A | TA0 CCR1 capture input CCI1A | TA0 CCR1 compare output Out1 |
So I am confused here (please help): How does one practically use DriverLib to define Capture-and-Count Register 2 (the 2nd one) and generate a 2nd type of PWM signal unrelated to the first PWM signal except for phase and route it to P2.5 ?
Is it necessary to define a new "Timer_A_PWMConfig" as pwmConfig2 and then invoke "MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig2)" ? But does that mean we have to repeat the values of : clockSource, clockSourceDivider, timerPeriod; dutyCycle ? Can they be different between PWMs ?
Thanks.
/*******************************************************************************
* MSP432 Timer_A - Variable PWM
*
* Description: In this example, the Timer_A module is used to create a precision
* PWM with an adjustable duty cycle. The PWM initial period is 200 ms and is
* output on P2.4. The initial duty cycle of the PWM is 10%, however when the
* button is pressed on P1.1 the duty cycle is sequentially increased by 10%.
* Once the duty cycle reaches 90%, the duty cycle is reset to 10% on the
* following button press.
*
* MSP432P401
* ------------------
* /|\| |
* | | |
* --|RST P1.1 |<--Toggle Switch (increase duty cycle by 10%)
* | P1.4 |<--Toggle Switch (decrease duty cycle by 10%)
* | |
* | P2.4 |--> Output PWM
* | |
* | |
*
* **SH 1/22/19 ** When P1.4 SW is pressed LED is toggled
*
*******************************************************************************/
/* DriverLib Includes */
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
/* Standard Includes */
#include <stdint.h>
#include <stdbool.h>
//![Simple Timer_A Config]
/* Timer_A PWM Configuration Parameter */
/* Configuring Timer_A to have a period of approximately 500ms and
* an initial duty cycle of 10% of that (3200 ticks) */
Timer_A_PWMConfig pwmConfig =
{
TIMER_A_CLOCKSOURCE_SMCLK,
TIMER_A_CLOCKSOURCE_DIVIDER_1,
32000,
TIMER_A_CAPTURECOMPARE_REGISTER_1,
TIMER_A_OUTPUTMODE_RESET_SET,
3200
};
//![Simple Timer_A Config]
int main(void)
{
/* Halting the watchdog */
MAP_WDT_A_holdTimer();
//![Simple Timer_A Example]
/* 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);
/* Configuring GPIO2.4 as peripheral output for PWM and P1.1 for increase button
* interrupt and P1.4 for decrease button interrupt */
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,
GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN4);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN4);
MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1 | GPIO_PIN4);
/* **SH** Configure GPIO1.0 (RED LED) as indicator */
// Set P1.0 to output direction
GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN0
);
/* 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_BASE, &pwmConfig);
//![Simple Timer_A Example]
/* 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();
}
}
/* Port1 ISR - This ISR will progressively step up the duty cycle of the PWM
* on a button press
*/
void PORT1_IRQHandler(void)
{
uint32_t status = MAP_GPIO_getEnabledInterruptStatus(GPIO_PORT_P1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, status);
if (status & GPIO_PIN1)
{
if(pwmConfig.dutyCycle == 28800)
pwmConfig.dutyCycle = 3200;
else
pwmConfig.dutyCycle += 3200;
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
}
if (status & GPIO_PIN4)
{
if(pwmConfig.dutyCycle == 3200)
pwmConfig.dutyCycle = 28800;
else
pwmConfig.dutyCycle -= 3200;
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig);
// Toggle P1.0 output
GPIO_toggleOutputOnPin(
GPIO_PORT_P1,
GPIO_PIN0
);
}
}