how is pwm frequency setting parameters?

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

how is pwm frequency setting parameters?

1,252件の閲覧回数
rlaxortn
Contributor IV

i know pwm frequency is PWM frequency = CORE_CLK / global prescaler / internal prescaler / (B1+1).

but don't understand how is set that parameter.

 

this pics are my current pwm frequncy setting. 

i am using CH4(emios0). 

and i got pwm frequency is 3.906kHz.

i wanna set pwm frequency is 30kHz.

1.png

 

2.png

 

3.png

 

4.png

 

i think CORE_CLK is 160Mhz, global prescaler is 1. internal prescaler is 1??? b1 is 32768.

so i expect pwm frequency is 160000000/1/1/(32768+1) = 4.882Khz.

 

1. how i set parameter for getting 30Khz pwm parameter???

 

2. what is mean 0x5000 in Emios_Mcl_Ip_SetCounterBusPeriod function parameter?

5.png

i changed smaller than 0x5000 value like 0x1000.

then pwm frequency is changed more higher(3.906kHz->19.53Khz). 

what is mean that value and what influence that value for pwm frequency formula?

0 件の賞賛
返信
7 返答(返信)

1,222件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

PWM frequency equation differs depending mode selected. For MCB up/down counting mode, the counter bus period is global prescaler * internal prescaler * (2*period_in_ticks-2) / CORE_CLK. For the init setting from picture it gives PWM freq = 160e6/1/1/(2*16385-2) = 4.882KHz you calculated. You measure 3.9kHz, as MCB period is changed in code from default one. If you stop the code after init functions and have eMIOS FRZ bit cleared you will see 4.882KHz

1. for 30KHz PWM in OPWCMB mode you need to set MCB channel's period to period_in_tics = (CORE_CLK / global prescaler / internal prescaler / 30e3 + 2) / 2.  It gives 2667.66. Using 2667 value, it results in 30.0075 kHz.

2. third parameter in Emios_Mcl_Ip_SetCounterBusPeriod determines value directly written to MCB channel A register. A register specifies the MCB period and for up/down mode it will be 160e6/1/1/(2*0x5000-2) =3.906 kHz
For 0x1000 value used it is 160e6/1/1/(2*0x1000-2) = 19.536 kHz

BR, Petr

0 件の賞賛
返信

1,214件の閲覧回数
rlaxortn
Contributor IV

@PetrS 

 

after i watched your post, i tried. 

but result is different. 

when i apply Emios_Mcl_Ip_SetCounterBusPeriod(pwmInstance0, pwmCH23, 0x14d5).

i got pwm frequency is 30kHz. 

so i think formula is core_clk / Period.

bacause i changed code Emios_Mcl_Ip_SetCounterBusPeriod(pwmInstance0, pwmCH23, 0x29aa). so i got pwm frequency is 15kHz. 

 

i don't understand. because it is different with formula you teached.

and current pwm setting is same with post pics. 

thanks.

 

 

0 件の賞賛
返信

1,198件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

this my measurement using RTD500

PetrS_0-1747211486917.png

BR, Petr

 

0 件の賞賛
返信

1,196件の閲覧回数
rlaxortn
Contributor IV
1. for 30KHz PWM in OPWCMB mode you need to set MCB channel's period to period_in_tics = (CORE_CLK / global prescaler / internal prescaler / 30e3 + 2) / 2. It gives 2667.66. Using 2667 value, it results in 30.0075 kHz.

i think is this formula is wrong.
0 件の賞賛
返信

1,178件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I see calculation and measurement aligned

PetrS_2-1747223529389.pngPetrS_3-1747223553194.png

PetrS_0-1747223298834.png

BR, Petr

0 件の賞賛
返信

1,161件の閲覧回数
rlaxortn
Contributor IV

@PetrS 

 

when i set Emios_Mcl_Ip_SetCounterBusPeriod(pwmInstance0, pwmCH23, 2667);.

i got pwm frequency 60Khz.

0 件の賞賛
返信

1,156件の閲覧回数
PetrS
NXP TechSupport
NXP TechSupport

Hi,

it could be if channel is using counter bus in MCB up counting mode. But for channel in OPWMCB mode using counter bus in MCB up/down counting you should not get that. Unless different value is written to counter bus A register, you can check it within debugger.

BR, Petr

 

0 件の賞賛
返信