PWM outputs on KL03 MCU for driving a stepper motor

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

PWM outputs on KL03 MCU for driving a stepper motor

ソリューションへジャンプ
1,113件の閲覧回数
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 解決策
1,094件の閲覧回数
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 返答(返信)
1,089件の閲覧回数
McLuhan
Contributor II

Dear Kerry,

thank you for your suggestion.

Everything is clear and working fine!

Best Regards,

MC

0 件の賞賛
返信
1,072件の閲覧回数
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 件の賞賛
返信
1,095件の閲覧回数
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