PWM outputs on KL03 MCU for driving a stepper motor

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

PWM outputs on KL03 MCU for driving a stepper motor

Jump to solution
791 Views
McLuhan
Contributor II

Hello,

I'm trying to write a program on MCUXpresso for driving a stepper motor using a KL03 MCU.

8 ports of the microcontroller are connected to a double H-Bridge, so I need to set 4 ports up and 4 ports down in a different combination for each of the 4 steps. When the ports are up, I would like to have as output a 20 kHz pulsed wave with a duty cycle of 50%.

I've checked the PWM example provided with the SDK 2.x. It seems to be related to a blinking LED present on the FDRM-KL03Z board. Unfortunately I don't have this board. I'm working directly on the microcontroller with the motor connected.

It's not clear for me how the PWM signal is linked to the output pin connected to the LED and how I can route this signal to the 4 output pins involved into the step.

At the moment I'm able to drive the motor rising and falling the pins using PTx->PDOR instructions.

I just need some help letting these outputs being pulsed.

I thank you for your suggestions. Any example is really appreciated.

MC

 

0 Kudos
1 Solution
772 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi McLuhan,

  If you need 8 PWMs, then you can't use the TPM directly, as the TPM just contains two module, each module 2 channels.

  But you can use the timer associated with the GPIO.

  Use timer to generate 25ms, then when time is reached, toggle your 8 ports GPIO to realize the 50% PWM wave. When you want to get set 4 ports up and 4 ports down , just 4 set low, 4 set high.

  About the code, you can refer to the SDK code, TPM timer, and the GPIO output code:

SDK_2.3.1_FRDM-KL03Z\boards\frdmkl03z\driver_examples\tpm\timer

SDK_2.3.1_FRDM-KL03Z\boards\frdmkl03z\driver_examples\gpio\led_output

Not PWM, as the TPM related PWM channel is not enough number for your usage, you can use the timer, when time is reached, the interrupt happens, then add the GPIO toggle code.

 

Wish it helps you!

Best Regards,

kerry

 

 

  

View solution in original post

3 Replies
767 Views
McLuhan
Contributor II

Dear Kerry,

thank you for your suggestion.

Everything is clear and working fine!

Best Regards,

MC

0 Kudos
750 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi McLuhan,

   You are welcome!

   Any new questions in the future, welcome to create a new case.

Best Regards,

Kerry

 

 

 

0 Kudos
773 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi McLuhan,

  If you need 8 PWMs, then you can't use the TPM directly, as the TPM just contains two module, each module 2 channels.

  But you can use the timer associated with the GPIO.

  Use timer to generate 25ms, then when time is reached, toggle your 8 ports GPIO to realize the 50% PWM wave. When you want to get set 4 ports up and 4 ports down , just 4 set low, 4 set high.

  About the code, you can refer to the SDK code, TPM timer, and the GPIO output code:

SDK_2.3.1_FRDM-KL03Z\boards\frdmkl03z\driver_examples\tpm\timer

SDK_2.3.1_FRDM-KL03Z\boards\frdmkl03z\driver_examples\gpio\led_output

Not PWM, as the TPM related PWM channel is not enough number for your usage, you can use the timer, when time is reached, the interrupt happens, then add the GPIO toggle code.

 

Wish it helps you!

Best Regards,

kerry