PWM generation using SCT0_OUT3

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM generation using SCT0_OUT3

1,365 Views
anusha_123
Contributor II

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

Labels (1)
Tags (1)
0 Kudos
Reply
9 Replies

1,195 Views
anusha_123
Contributor II

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

0 Kudos
Reply

1,170 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

 

 

0 Kudos
Reply

1,164 Views
anusha_123
Contributor II

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

 

0 Kudos
Reply

1,146 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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

0 Kudos
Reply

1,123 Views
anusha_123
Contributor II

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

0 Kudos
Reply

1,344 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

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:

Alice_Yang_0-1682045975622.png

 

 

 BR

Alice

0 Kudos
Reply

1,243 Views
anusha_123
Contributor II
Hi,


We're trying to generate pwm on two sctimer out pins to run two motors simultaneously.
e.g if we have A and B as two outputs, in the first i'm configuring A as gpio and B as pwm for motor1. for second A as pwm and B as gpio for motor2.
When we try to run the motor, even for individual motor it can run only 4 times or 5 times, after that it is going to hardfault handler.
This is happening when we try to run one motor.
But for running both the motors, if we start motor1 to run, it is running and if we start motor2, motor2 will not move.

Please let us know how to do pwm configuration to start both pwm.


Regards,
Anusha
0 Kudos
Reply

1,221 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello @anusha_123 

How about only configure PWM B when use motor 1, and only configure PWM A when use motor 2.

 

BR

Alice

0 Kudos
Reply

1,176 Views
anusha_123
Contributor II

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

 

 

0 Kudos
Reply