PWM Microcontroller Timing Utility

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.

✓ PWM Frequency ✓ Duty Cycle ✓ High Time ✓ Low Time ✓ CCR / Compare ✓ ARR / TOP
PWM
Frequency & Duty Cycle
● Ready
Enter the actual clock feeding the timer peripheral.
With PSC+1 mode, a value of 71 means divide the timer clock by 72.
With ARR+1 mode, 999 gives 1000 timer counts per PWM period.
Percentage of each PWM period that the output should be active.
Select the convention used by the target timer peripheral.
Changes how high/low time is described; frequency is unchanged.
Common edge-aligned PWM formula: 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.
PWM Calculation Result Calculated
PWM Output
PWM Frequency
PWM Period
Timer Tick Frequency
Timer Tick Period
Prescaler Divider
Counts Per Period
Requested Duty
Compare / CCR Value
Actual Duty
Active Time
Inactive Time
Duty Resolution
Calculation Breakdown

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 Hz

PWM Period

PWM period is the reciprocal of PWM frequency.

Period = 1 / Frequency For 1 kHz: 1 / 1000 = 0.001 s = 1 ms

PWM 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 Period

Because 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 ticks

25% Duty Cycle Example

1 kHz PWM Period: 1 ms Duty: 25% Active Time: 0.25 ms Inactive Time: 0.75 ms

PWM Duty Resolution

The number of timer counts per PWM period determines the smallest ideal duty increment.

Duty Resolution ≈ 100% ----------------- Counts Per Period

With 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 kHz

50 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?
For a common zero-based edge-aligned timer, divide the timer input clock by (PSC+1) × (ARR+1).
What is duty cycle?
Duty cycle is the percentage of one PWM period spent in the active output state.
What is the period of 1 kHz PWM?
A 1 kHz waveform has a period of 1 millisecond.
What is the period of 20 kHz PWM?
20 kHz corresponds to 50 microseconds per period.
What is high time at 50% duty?
The active time is half of the full PWM period.
Why does the compare value need rounding?
Timer compare registers contain integer counts, so some requested duty cycles cannot be represented exactly.
Does ARR=999 mean 999 counts?
With a zero-based timer running from 0 through 999, there are 1000 counter states, so the period contains ARR+1 counts.
Does this calculator support active-low PWM?
Yes. Select Active Low and the calculator describes the active interval as the low portion of the waveform.
Can I use this for servo PWM?
Yes for the basic frequency and duty timing. Verify the actual pulse-width range required by the servo.
Does this formula apply to center-aligned PWM?
Not necessarily. Center-aligned timers commonly introduce an additional counting factor, so consult the MCU reference manual.

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.

Scroll to Top