PWM timer prescaler purpose

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

PWM timer prescaler purpose

2,662件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wella-tabor on Sun Dec 01 04:57:24 MST 2013
Hello,

does anybody know the meaning of the prescaler in LPC1788 pwm? I cannot imagine the purpose for PWM freq > 1 HZ. The MR0 is a 32 bit register, enabling to achieve up to ~4GHz, or ~35s (PWM clock = 120 MHz).

Let's compute the MR0
MR0 = INT(PWM_clock / ((1 + prescaler) * desired_freq))), INT is a function that returns integral part of the result
error =  PWM_clock / ((1 + prescaler) * MR0)) - desired_freq

The error is zero if we solve this equation PWM_clock MOD ((1 + prescaler) * desired_freq) = 0, however if the PWM_clock MOD desired_freq != 0, such (1 + prescaler) does not exist. The best option is to set the prescaler to 0.

Or maybe I am wrong....

Best
Martin






ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,943件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Wed Dec 04 03:37:16 MST 2013
In my case I am running with a cpu clock of 120 MHz and PClk at 1:1 (i.e. the same).

This gives me a resolution of 8.333 nano secs (8 and 1/3).

By setting the pre-scaler to 120 I can feed micro second times directly to the timer registers.
[NB: 120 x 8.333 = 1000 or 1 usec]

I suggest that this makes the code easier to read and more self documenting.

Of course, the intervals are exactly the same either way -- it depends if you want
to sprinkle the multiplies (either 'on-screen' or 'off-screen') through your code whenever
you set or change a timer,

Just my opinion, and not binding <g>

Mike
0 件の賞賛
返信

1,943件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by wella-tabor on Sun Dec 01 15:34:30 MST 2013
Hello,

what is your PWM freq for the LCD? Is it 4,8 or 16 KHz. Actually there is not any limit (> 1 Hz and <120 MHz). If the PWM->PM = 0, your PWM->MR0 will contain  = INT(120*10^6 / {4000, 8000,16000} ) = {30000, 15000, 7500}. All what you get is the finer control over the duty cycles than using the prescaler.

Best
Martin
0 件の賞賛
返信

1,943件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by YOZHik on Sun Dec 01 06:14:01 MST 2013
Sometimes it is more convenient to use the prescaler. For example, I have a project with LCD backlight dimming using PWM. In GUI you select a duty factor from 20% to 100%. If 120 MHz is directly applied as a counter limit then you PWM frequency will be too high for an LCD backlight driver. Therefore there are two options - multiply you desired duty factor by some number or just set this number in the prescaler. Obviously, there is nothing wrong with multiplication but setting up the prescaler is even easier and should be done only once.
0 件の賞賛
返信