Controlling a Servo Motor with PWM - FRDM-KL43Z

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

Controlling a Servo Motor with PWM - FRDM-KL43Z

Jump to solution
1,482 Views
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 Kudos
Reply
1 Solution
1,302 Views
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.
-------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
2 Replies
1,303 Views
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 Kudos
Reply
1,302 Views
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 Kudos
Reply