Hi,
For driving 2 motors we are using 4 PWM pins. When we want to drive the motor in CW direction, one of the pin is made as GPIO and other pin as PWM and vice versa for CCW.
We have written 2 different function for driving the 2 motors as in our application both the motors may not start together and stop together. The issue what we are facing is when one motor is driven and if we try to drive the 2nd motor, the first motor is stropping and 2 motor is running.
uint16_t motor1_drive(void)
{
SCTIMER_Init(SCT0, &sctimerInfo);
GPIO_PinInit(GPIO, GPIO0_PORT, BUCKY_TABLE_PWM2, &outputConfig);
const uint32_t port0_pin28_config = (/* Pin is configured as SCT0_OUT3 */
//IOCON_PIO_FUNC4 |
IOCON_PIO_FUNC0 |
/* No addition pin function */
IOCON_PIO_MODE_INACT |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Input filter disabled */
IOCON_PIO_INPFILT_OFF |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
/* PORT0 PIN22 (coords: E3) is configured as SCT0_OUT3 */
IOCON_PinMuxSet(IOCON, 0U, 28U, port0_pin28_config);
GPIO_PinWrite(GPIO, GPIO0_PORT, BUCKY_TABLE_PWM2, 1);
GPIO_PinInit(GPIO, GPIO0_PORT, BUCKY_TABLE_PWM1, &outputConfig);
const uint32_t port0_pin31_config = (/* Pin is configured as SCT0_OUT3 */
//IOCON_PIO_FUNC4 |
IOCON_PIO_FUNC0 |
/* No addition pin function */
IOCON_PIO_MODE_INACT |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Input filter disabled */
IOCON_PIO_INPFILT_OFF |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
/* PORT0 PIN22 (coords: E3) is configured as SCT0_OUT3 */
IOCON_PinMuxSet(IOCON, 0U, 31U, port0_pin31_config);
GPIO_PinWrite(GPIO, GPIO0_PORT, BUCKY_TABLE_PWM1, 1);
GPIO_PinInit(GPIO, GPIO0_PORT, BUCKY_VER_PWM2, &outputConfig);
const uint32_t port0_pin22_config = (/* Pin is configured as SCT0_OUT3 */
//IOCON_PIO_FUNC4 |
IOCON_PIO_FUNC0 |
/* No addition pin function */
IOCON_PIO_MODE_INACT |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Input filter disabled */
IOCON_PIO_INPFILT_OFF |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
/* PORT0 PIN22 (coords: E3) is configured as SCT0_OUT3 */
IOCON_PinMuxSet(IOCON, 0U, 22U, port0_pin22_config);
GPIO_PinWrite(GPIO, GPIO0_PORT, BUCKY_VER_PWM2, 0);
const uint32_t port0_pin18_config = (/* Pin is configured as SCT0_OUT3 */
IOCON_PIO_FUNC4 |
//IOCON_PIO_FUNC0 |
/* No addition pin function */
IOCON_PIO_MODE_INACT |
/* Input function is not inverted */
IOCON_PIO_INV_DI |
/* Enables digital function */
IOCON_PIO_DIGITAL_EN |
/* Input filter disabled */
IOCON_PIO_INPFILT_OFF |
/* Standard mode, output slew rate control is enabled */
IOCON_PIO_SLEW_STANDARD |
/* Open drain is disabled */
IOCON_PIO_OPENDRAIN_DI);
/* PORT0 PIN22 (coords: E3) is configured as SCT0_OUT3 */
IOCON_PinMuxSet(IOCON, 0U, 18U, port0_pin18_config)
pwmParam.output = BUCKY_VER_FIRST_SCTIMER_OUT;
pwmParam.level = kSCTIMER_LowTrue;
pwmParam.dutyCyclePercent = 10;
/* Schedule the pulse event for the PWM */
if (SCTIMER_SetupPwm(SCT0, &pwmParam, kSCTIMER_EdgeAlignedPwm, 10000U, sctimerClock, & UpEventNumberOutput) == kStatus_Fail)
{
return -1;
}
SCTIMER_StartTimer(SCT0, kSCTIMER_Counter_U);
}
As we are reconfiguring the PWM pins as GPIO pins and vice versa, we are re initializing the SCTIMER every time and de-initializing when we want to stop the motor.
Can you please let us know how to resolve this issue. Please note, we need different duty cycle for both the motors.
Thanks,
Anusha