tPM PWM Fluctuation& Resolution (FRMD-K66F)

cancel
Showing results for 
Search instead for 
Did you mean: 

tPM PWM Fluctuation& Resolution (FRMD-K66F)

Jump to solution
233 Views
songja
Contributor III

Hello, 

I am trying to send a PWM signal to a motor controller for torque control.

I have a couple of questions regarding tPM_PWM.

Firstly, the PWM signal is fluctuating within 0.5% around the target duty cycle when received at the motor controller.

My colleague has tried with Arduino to the motor controller and the duty cycle did not fluctuate. 

I modified an example code(tpm_simple_pwm) to make it run with FreeRTOS.

But it still has the same structure for PWM. 

The scheme is that when the SW button is pressed, it starts sending PWM to the motor controller. 

Here is the code I used.

if (Motor_Switch==1)
{
   /* Disable channel output before updating the dutycycle */
   TPM_UpdateChnlEdgeLevelSelect(TPM_BASEADDR, (tpm_chnl_t)TPM_CHANNEL, 0U);

   /* Update PWM duty cycle */
   TPM_UpdatePwmDutycycle(TPM_BASEADDR, (tpm_chnl_t)TPM_CHANNEL, kTPM_CenterAlignedPwm,
updatedDutycycle);

   /* Start channel output with updated dutycycle */
   TPM_UpdateChnlEdgeLevelSelect(TPM_BASEADDR, (tpm_chnl_t)TPM_CHANNEL, TPM_LED_ON_LEVEL);
}
else
{
/* Disable channel output before updating the dutycycle */
   TPM_UpdateChnlEdgeLevelSelect(TPM_BASEADDR, (tpm_chnl_t)TPM_CHANNEL, 0U);
}

PWM frequency of the motor controller is 5kHz and TPM_SetupPwm was set to 24kHz.

I tried to match those two values (TPM PWM was set to 5kHz).

(TPM_SetupPwm(TPM_BASEADDR, &tpmParam, 1U, kTPM_CenterAlignedPwm, 5000U, TPM_SOURCE_CLOCK);)

Secondly, according to the example code, I can only send duty cycle from 0% to 99% with 1% increment. 

I had a look at the underlying codes as well but I could not figure out how I can increase the resolution of the dutycycle.

Is there anywhere that I can change to increase the resolution of duty cycle?

Your advice will be very much appreciated.

Regards,

Labels (1)
Tags (3)
0 Kudos
1 Solution
91 Views
nxf46838
NXP TechSupport
NXP TechSupport

Hello,

 

Yes you can change it but you'll need to change some settings in the TPM driver,  go to the definition of the function TPM_UpdatePwmDutycycle, then you'll see the operation where the duty cycle is set cnv = (mod * dutyCyclePercent) / 100, change the 100 to a 1000, that way you'll have more resolution, for example you can achieve your 50.5%.

Also, make sure that you use an 16 bit int for the updatedDutycycle and for the pass parameter of the TPM_UpdatePwmDutycycle, since you'll use values from 1 to 999 (0.1% to 99.9%)

 

 

Hope this helps,

Regards,

Aldo.

-------------------------------------------------------------------------------
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
4 Replies
91 Views
nxf46838
NXP TechSupport
NXP TechSupport

Hello,

 

You can indeed change the PWM frequency using the function you mentioned:

 

TPM_SetupPwm(TPM_BASEADDR, &tpmParam, 1U, kTPM_CenterAlignedPwm, 24000U, TPM_SOURCE_CLOCK)

 

You'll just need to change the 24000 to another value, for example in your case would be 5000.

 

Hope this helps,

Regards,
Aldo.

-------------------------------------------------------------------------------
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
91 Views
songja
Contributor III

Thanks for the reply.

I already changed it already to 5000U and the PWM signal at the receiving end still fluctuated +- 0.2%.

Also, do you know how I can change the resolution of PWM?

The example only seemed to work with every 1% of dutycycle. For example, it could not send 50.5% dutycycle.

I have looked into the underlying code but still had no clue to change the resolution for PWM.

Regards,
Jaeyong Song 

0 Kudos
92 Views
nxf46838
NXP TechSupport
NXP TechSupport

Hello,

 

Yes you can change it but you'll need to change some settings in the TPM driver,  go to the definition of the function TPM_UpdatePwmDutycycle, then you'll see the operation where the duty cycle is set cnv = (mod * dutyCyclePercent) / 100, change the 100 to a 1000, that way you'll have more resolution, for example you can achieve your 50.5%.

Also, make sure that you use an 16 bit int for the updatedDutycycle and for the pass parameter of the TPM_UpdatePwmDutycycle, since you'll use values from 1 to 999 (0.1% to 99.9%)

 

 

Hope this helps,

Regards,

Aldo.

-------------------------------------------------------------------------------
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
91 Views
songja
Contributor III

Hello,

It worked after changing the value from 100 to 1000 and also the pass parameter to uint16_t both in c and header files.

Thanks a lot.

Regards,

J

0 Kudos