256 Step PWM on Kinetis KL03

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

256 Step PWM on Kinetis KL03

ソリューションへジャンプ
646件の閲覧回数
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 解決策
634件の閲覧回数
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 返信
635件の閲覧回数
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 件の賞賛
返信