256 Step PWM on Kinetis KL03

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

256 Step PWM on Kinetis KL03

跳至解决方案
1,211 次查看
RP_ARW
Contributor I

Hi,

I am using the MKL03Z32VFG4(R) MCU on a target board. Intend to use both the TPM0 and TPM1 PWM channels for generating 4 PWM signals to drive RGBW LEDs.

I am using the frdmkl03z_tpm_pwm_twochannel example driver code from the SDK. I am able to generate 4 PWMs and drive the LEDs with 1%-100% PWM duty cycle with 1KHz PWM frequency. I would like to increase the PWM resolution from 100 to 256 steps.

Please advise if this would be possible. If so, what changes needs to be done in the configuration / code.

Thanks,

0 项奖励
回复
1 解答
1,199 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hello!

The frdmkl03z_tpm_pwm_twochannel example you are using sets up its functions in a way that the resolution of the PWM is based on 100 steps in order to be simple and easy to understand (by basing its duty cycle in percentage). However, you are able to adjust the resolution. "The Edge-Aligned PWM (EPWM) Mode" section of the KL03 Sub-Family Reference Manual (p. 478) describes the way that the PWM is set up using the TPM registers. In this case the “EPWM period is determined by (MOD + 0x0001) and the pulse width (duty cycle) is determined by CnV.” So, in order to increase the resolution of your PWM to 256, you would require to adjust the value of MOD to 255. This would still depend on the values of the clock you are using and the frequency of your PWM, but as you can see in the example from the SDK that you are using, the formula to calculate the MOD value for a specific clock and frequency is: mod = (tpmClock / pwmFreq_Hz) - 1;

You can find this reference manual by clicking on this link:

https://www.nxp.com/docs/en/reference-manual/KL03P24M48SF0RM.pdf

 

Regards,

Edwin.

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,200 次查看
EdwinHz
NXP TechSupport
NXP TechSupport

Hello!

The frdmkl03z_tpm_pwm_twochannel example you are using sets up its functions in a way that the resolution of the PWM is based on 100 steps in order to be simple and easy to understand (by basing its duty cycle in percentage). However, you are able to adjust the resolution. "The Edge-Aligned PWM (EPWM) Mode" section of the KL03 Sub-Family Reference Manual (p. 478) describes the way that the PWM is set up using the TPM registers. In this case the “EPWM period is determined by (MOD + 0x0001) and the pulse width (duty cycle) is determined by CnV.” So, in order to increase the resolution of your PWM to 256, you would require to adjust the value of MOD to 255. This would still depend on the values of the clock you are using and the frequency of your PWM, but as you can see in the example from the SDK that you are using, the formula to calculate the MOD value for a specific clock and frequency is: mod = (tpmClock / pwmFreq_Hz) - 1;

You can find this reference manual by clicking on this link:

https://www.nxp.com/docs/en/reference-manual/KL03P24M48SF0RM.pdf

 

Regards,

Edwin.

0 项奖励
回复