Tool/software: Code Composer Studio
Hi all,
So after tinkering for a while with the timer_a_pwm_mode project, I was successfully able to drive a brushless motor at varying speeds.
However, when I attempt to do the same for 4 different pins, only the first pin set as a peripheral output actually generates a PWM signal.
As shown in the code below (highlighted yellow), I have attempted to use a different base for timer A configuration as well as the seconday module, but that yielded no changes.
// DriverLib Includes
#include <ti/devices/msp432p4xx/driverlib/driverlib.h>
// Standard Includes
#include <stdint.h>
#include <stdbool.h>
// Timer_A PWM Configuration Parameter
Timer_A_PWMConfig pwmConfig0 =
{
TIMER_A_CLOCKSOURCE_SMCLK,
TIMER_A_CLOCKSOURCE_DIVIDER_1,
1280, // this num/ 64k = period OG 32000
TIMER_A_CAPTURECOMPARE_REGISTER_1,
TIMER_A_OUTPUTMODE_RESET_SET,
64 // 5% or 1ms duty cycle OG 3200
};
// Timer_A1 PWM Configuration Parameter
Timer_A_PWMConfig pwmConfig1 =
{
TIMER_A_CLOCKSOURCE_SMCLK,
TIMER_A_CLOCKSOURCE_DIVIDER_1,
1280, // this num/ 64k = period OG 32000
TIMER_A_CAPTURECOMPARE_REGISTER_1,
TIMER_A_OUTPUTMODE_RESET_SET,
96 // 7.5% or 1.5ms duty cycle OG 3200
};
int main(void)
{
// Halting the watchdog
MAP_WDT_A_holdTimer();
// 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 GPIO 2.4 as peripheral output for PWM and P1.1 for button interrupt
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN4,GPIO_PRIMARY_MODULE_FUNCTION);
MAP_GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_clearInterruptFlag(GPIO_PORT_P1, GPIO_PIN1);
MAP_GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
// Configuring GPIO 2.7, 2.6, 5.6 as peripheral outputs for PWM
MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN7,GPIO_SECONDARY_MODULE_FUNCTION);
// MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2, GPIO_PIN6,GPIO_PRIMARY_MODULE_FUNCTION);
// MAP_GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, GPIO_PIN6,GPIO_PRIMARY_MODULE_FUNCTION);
// Set P1.0 to output direction (LED)
MAP_GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0);
// OG Configuring Timer_A to have a period of approximately 500ms and an initial duty cycle of 10% of that (3200 ticks)
// Configuring Timer_A to have a period of approximately 20ms and an initial duty cycle of 5% of that (64 ticks)
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig0);
//
MAP_Timer_A_generatePWM(TIMER_A1_BASE, &pwmConfig1);
// 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);
int32_t speedChange; // %percent change on button press 16 for 1.25% increase or 0.25ms 32 for 2.5% or .5ms
if (status & GPIO_PIN1)
{
if(pwmConfig0.dutyCycle == 128) // 10% cycle at 128, OG 28800 90%
{
speedChange = -16;
// pwmConfig.dutyCycle += speedChange;
}
if(pwmConfig0.dutyCycle == 64) // 5% cycle, 1ms OG 28800 90%
{
speedChange = 16;
// pwmConfig.dutyCycle += speedChange; // 1.25% increase or 0.25ms 32 for 2.5% or .5ms OG 3200 10%
}
// pwmConfig.dutyCycle = 64; // reset to 5% or 1ms 3200 10%
// else
pwmConfig0.dutyCycle += speedChange; // 1.25% increase or 0.25ms 32 for 2.5% or .5ms OG 3200 10%
MAP_Timer_A_generatePWM(TIMER_A0_BASE, &pwmConfig0);
volatile uint32_t i;
// Button Press debug
// Toggle P1.0 output debug button press
MAP_GPIO_toggleOutputOnPin(GPIO_PORT_P1,GPIO_PIN0);
// Delay
for(i=1000; i>0; i--);
}
}
What is required to get the other 3 pins (highlighted in blue) to output their own separate PWM signals?
Thanks,
Robert Pulatie