PWM Frequency & Duty Cycle Calculator
Calculate PWM frequency, period, timer tick, duty cycle, high time, low time and compare-register value from the timer clock, prescaler and ARR/TOP count. Useful for MCU timers, motor control, LEDs, servos and switching applications.
Fpwm = Ftimer / ((PSC + 1) × (ARR + 1)).
For an ideal edge-aligned compare output, the active counts are approximately
Duty × (ARR + 1). Hardware-specific compare semantics should
still be verified in the MCU reference manual.
—
What Is PWM?
Pulse Width Modulation, or PWM, repeatedly switches a digital output between active and inactive states. The frequency determines how often the waveform repeats, while duty cycle determines the fraction of each period spent in the active state.
PWM is widely used for motor control, LED brightness, switching regulators, audio generation, servo signals and digital-to-analog style output.
PWM Frequency Formula
For a common edge-aligned timer using zero-based prescaler and auto-reload registers:
Fpwm =
Timer Clock
---------------------------------
(PSC + 1) × (ARR + 1)72 MHz Timer to 1 kHz PWM
Timer Clock:
72,000,000 Hz
PSC:
71
Prescaler Divider:
72
ARR:
999
Counts:
1000
PWM Frequency:
72,000,000
---------------
72 × 1000
= 1000 HzPWM Period
PWM period is the reciprocal of PWM frequency.
Period = 1 / Frequency
For 1 kHz:
1 / 1000
= 0.001 s
= 1 msPWM Duty Cycle Formula
Duty Cycle =
Active Time
-----------
PWM Period
× 100%A 50% duty-cycle signal is active for half of every PWM period. A 25% signal is active for one quarter of the period.
Compare Register and Duty Cycle
In many edge-aligned PWM implementations, a compare register determines how many timer counts the output remains active.
Ideal Active Counts =
Duty / 100
×
Counts Per PeriodBecause the compare register is integer-valued, the requested duty cycle may need to be rounded to the nearest available timer count.
50% Duty Cycle Example
Counts Per Period:
1000
Requested Duty:
50%
Active Counts:
1000 × 0.50
= 500
Approximate Compare:
500
High / Active Time:
500 timer ticks
Low / Inactive Time:
500 timer ticks25% Duty Cycle Example
1 kHz PWM
Period:
1 ms
Duty:
25%
Active Time:
0.25 ms
Inactive Time:
0.75 msPWM Duty Resolution
The number of timer counts per PWM period determines the smallest ideal duty increment.
Duty Resolution ≈
100%
-----------------
Counts Per PeriodWith 1000 counts per period, one timer count represents approximately 0.1 percentage point of duty cycle.
Frequency vs Duty Resolution
Increasing PWM frequency while keeping the same timer clock reduces the number of available timer counts per period. That can reduce duty-cycle resolution.
Conversely, a lower PWM frequency can permit a larger ARR/TOP value and finer duty adjustment.
20 kHz PWM Example
20 kHz is commonly encountered in motor-control and switching applications because it is above much of the normal audible range.
72 MHz timer
PSC = 0
Required Counts:
72,000,000 / 20,000
= 3600
ARR:
3599
PWM:
20 kHz50 Hz Servo PWM
Traditional hobby-servo control commonly uses a frame rate around 50 Hz, corresponding to a 20 ms period. The active pulse is usually only a small fraction of that full period.
50 Hz period:
20 ms
1.5 ms pulse:
Duty =
1.5 / 20 × 100
= 7.5%Active High vs Active Low PWM
With active-high PWM, duty cycle usually describes the portion of the period during which the output is logically high. With active-low PWM, the active portion corresponds to the low state instead.
This calculator reports active and inactive time so the calculation remains clear regardless of output polarity.
Edge-Aligned vs Center-Aligned PWM
This calculator uses the common edge-aligned timer formula. Center-aligned PWM typically counts both upward and downward and can therefore use a different frequency relationship.
For center-aligned operation, check the microcontroller reference manual before using the edge-aligned formula directly.
PWM Clock Source
Use the actual timer peripheral clock, not automatically the CPU core clock. Clock trees can divide or multiply the peripheral timer clock independently of the processor clock.
PWM Frequency & Duty Cycle Calculator FAQs
How do I calculate PWM frequency?
What is duty cycle?
What is the period of 1 kHz PWM?
What is the period of 20 kHz PWM?
What is high time at 50% duty?
Why does the compare value need rounding?
Does ARR=999 mean 999 counts?
Does this calculator support active-low PWM?
Can I use this for servo PWM?
Does this formula apply to center-aligned PWM?
Calculate PWM Frequency and Duty Timing
Convert MCU timer clock, prescaler, ARR/TOP and duty-cycle settings into PWM frequency, period, timer resolution, compare value and active/inactive timing.