Controlling a Servo Motor with PWM - FRDM-KL43Z

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

Controlling a Servo Motor with PWM - FRDM-KL43Z

跳至解决方案
1,282 次查看
zezao
Contributor I

So, basically, I'm trying to control a servo motor which pulse have 20ms, like the picture below:

Micro Servo 9g

I setup my PWM to 50 Hz, but when I'm updating the duty cycle (with the function TPM_UpdatePwmDutycycle), I can only work with percent changes, which give me like 10 differents angles (from varying the duty cycle from 1% to 10%, because 2 ms equals to 10% of the pulse), since the function expects an integer parameter.

void TPM_UpdatePwmDutycycle(TPM_Type *base, tpm_chnl_t chnlNumber, tpm_pwm_mode_t currentPwmMode, uint8_t dutyCyclePercent)

How can I work around it?

0 项奖励
回复
1 解答
1,102 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi José Baretta

   The dutyCyclePercent in the API TPM_UpdatePwmDutycycle(TPM_Type *base, tpm_chnl_t chnlNumber, tpm_pwm_mode_t currentPwmMode, uint8_t dutyCyclePercent) just used to change the dutyCyclePercent.

    The value is from 0-100. If you want the duty cycle is 1-2ms, then you can use 5% to 10%.

    If you don't want to use the percent change, you also can calculate the according duty data, then input it in the TPM_CnV register.

   More details, you can refer to the KL43 reference manual.

    BTW, the KL43 is 3.3V chip, if you want to output 5V, you need external transform circuit.

Wish it helps you!

If you still have question about it, please kindly let me know.

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,103 次查看
kerryzhou
NXP TechSupport
NXP TechSupport

Hi José Baretta

   The dutyCyclePercent in the API TPM_UpdatePwmDutycycle(TPM_Type *base, tpm_chnl_t chnlNumber, tpm_pwm_mode_t currentPwmMode, uint8_t dutyCyclePercent) just used to change the dutyCyclePercent.

    The value is from 0-100. If you want the duty cycle is 1-2ms, then you can use 5% to 10%.

    If you don't want to use the percent change, you also can calculate the according duty data, then input it in the TPM_CnV register.

   More details, you can refer to the KL43 reference manual.

    BTW, the KL43 is 3.3V chip, if you want to output 5V, you need external transform circuit.

Wish it helps you!

If you still have question about it, please kindly let me know.

Have a great day,
Kerry

 

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 项奖励
回复
1,102 次查看
zezao
Contributor I

The problem is with that function I can only vary my pulse from 0.2 to 0.2 ms (I can't get 1.05 ms, for example). I think I'll have to use the TPM_CnV register anyway.

BTW, I'm powering the servo with 5V, only my PWM is 3.3V, and it seems to work fine.

Thank you for the reply!

0 项奖励
回复