PWM outputs on KL03 MCU for driving a stepper motor

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

PWM outputs on KL03 MCU for driving a stepper motor

跳至解决方案
904 次查看
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 项奖励
回复
1 解答
885 次查看
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

 

 

  

在原帖中查看解决方案

3 回复数
880 次查看
McLuhan
Contributor II

Dear Kerry,

thank you for your suggestion.

Everything is clear and working fine!

Best Regards,

MC

0 项奖励
回复
863 次查看
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 项奖励
回复
886 次查看
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