Hi,
We have NXP LPC54606J256 controller. When we set pwm output SCT0_OUT3 for P0_22 and P0_31, It is generating pwm on both the pins.
As per our application we need two pins for pwm.
Let us know how to generate pwm output SCT0_OUT3 on only one pin.
Regards,
Anusha
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
Hello @anusha_123
For example, P0_28 and P0_32 control motor 1, P0_22 and P0_18 control motor 2.
When start motor 1, do not want to start motor 2 :configure P0_28 and P0_32 as pwm functions, P0_22 and P0_18 as gpio and output low.
When start motor 2, do not want to start motor 1 : configure P0_22 and P0_18 as pwm functions, P0_28 and P0_32 as gpio and output low.
BR
Alice
Hi,
Currently we are doing as you mentioned. However, in our application we want to run both the motors at a time with different duty cycle. So when one motor is running with say 30 % duty cycle and when we start the 2nd motor with 90% duty cycle, the first motor is stopping and 2nd motor is starting.
We want both the motor to run with the specified duty cycle.
Thanks,
Anusha
Hello @anusha_123
About configure different duty cycle, you can refer to SDK dmeo"lpcxpresso54628_sctimer_multi_state_pwm".
If still have any issue, you can debug your code and measure whether the PWM signal is right.
BR
Alice
Hi,
we're able to generate different duty cycle for two different motors, but we want to run both the motors simultaneously.
In our case, as the above example of motor1_drive function port0_pin18_config
configured as PWM. Likewise we have motor2_drive function and port0_pin31_config configured as PWM. But when we start motor1, it is running and if we start motor 2 at the same time motor1 stops and motor2 starts running.
In our application we want to start motor1 first and then start motor2 but both should run or we'll start both motors at the same time.
Thanks,
Anusha
Hello @anusha_123
You can configure the another pin to other functions( not SCT0_OUT3), or if you do not want to use this pin as any functions, just configure as below:
BR
Alice
Hello @anusha_123
How about only configure PWM B when use motor 1, and only configure PWM A when use motor 2.
BR
Alice
Hi,
Our application flow is as below,
1. Drive motor 1 with PWM.
2. Drive motor 2 with PWM.
3. Drive motor 3 with PWM.
All the 3 motors are driven with GPIO interrupt is triggered. In our case when motor 1 is running, when 2nd interrupt occurs, we start driving the motor 2 with PWM. in this case motor 1 is getting stopped and motor 2 starts running. But for our application we need both the motors to be running till out application stops the motor.
Thanks,
Anusha