Skip to content
Advertisement

PWM Duty Cycle Calculator

Convert between frequency, duty cycle, on/off times and average voltage, with a bit-depth resolution helper.

Calculator Converter

Period
1 ms
On time
250 µs
Off time
750 µs

Resolution

Duty steps
256
Finest duty step
0.3906 %

How PWM Duty Cycle Calculator works

Pulse-width modulation delivers a variable average power by switching a fixed voltage fully on and fully off at a constant frequency, varying only the fraction of each cycle spent on. That fraction is the duty cycle, and because the switch is either saturated or off, almost no power is dissipated in the switch itself — which is why PWM is far more efficient than a linear regulator or a series resistor.

The average voltage seen by a load is simply the supply times the duty cycle, provided the load integrates the switching. A motor’s inductance and inertia do this mechanically; an LED relies on your eye’s persistence of vision; a power supply uses an explicit inductor and capacitor filter. Without some form of integration the load sees the raw square wave, not an average.

Period and frequency are reciprocals, and the on and off times follow directly from the duty cycle. Choosing the frequency is a design trade: too low and you get audible whine from motors or visible flicker from LEDs; too high and switching losses rise, since every transition costs energy in the switching device and its gate drive.

On a microcontroller the resolution is finite. An n-bit PWM peripheral divides the period into 2^n steps, so an 8-bit timer gives 256 levels — about 0.39% per step. Resolution and frequency compete for the same timer clock: at a fixed clock, doubling the frequency halves the number of steps available.

Reference

  • Duty cycle D = t_on / T = t_on / (t_on + t_off)
  • Period T = 1 / f
  • Average voltage V_avg = D × V_supply
  • Average power into a resistive load P_avg = D × V_supply² / R
  • Resolution: steps = 2^bits; step size = 100% / 2^bits; f_max = f_timer / 2^bits

How to use this calculator

  1. Enter frequency or period

    Set whichever you know — the other is derived immediately.

  2. Set the duty cycle

    Enter duty as a percentage, or give an on-time and let the tool derive the duty.

  3. Add the supply voltage

    Supply the rail voltage to see the average voltage and, with a load resistance, the average power.

  4. Check the resolution

    Enter your timer bit depth to see the smallest duty step you can actually command.

Worked examples

LED dimming

Given
1 kHz, 25% duty, 5 V supply
Result
V_avg = 1.25 V, on-time 250 µs

Well above the flicker-fusion threshold, so the LED looks steadily dimmed. Brightness tracks duty roughly, not exactly — the eye is non-linear.

Motor speed control

Given
20 kHz, 60% duty, 12 V
Result
V_avg = 7.2 V, period 50 µs

Above the audible range deliberately: at 2 kHz the same motor would whine at 2 kHz because the windings are magnetostrictive.

Resolution versus frequency

Given
A 16 MHz timer clock at 8-bit resolution
Result
Maximum 62.5 kHz with 256 steps

Wanting 10-bit resolution from the same clock drops the ceiling to 15.6 kHz. You cannot have both without a faster timer.

When to use it

  • Dimming LEDs or a backlight without wasting power in a series resistor.
  • Controlling DC motor speed or fan speed efficiently.
  • Driving a servo, where position is encoded as a pulse width within a 20 ms frame.
  • Generating a crude analogue output from a digital pin by adding an RC filter.
  • Regulating a heating element by slow duty modulation.

Things to watch out for

  • Average voltage assumes the load integrates the waveform. A high-impedance input or an oscilloscope probe sees the square wave itself, not the average.
  • PWM frequency choice is a trade-off: audible whine and visible flicker below a few kHz, rising switching losses above tens of kHz.
  • Human brightness perception is roughly logarithmic, so linear duty steps look unevenly spaced. Apply a gamma curve for smooth-looking dimming.
  • Switching inductive loads such as motors and solenoids requires a flyback diode. Without one, the inductive kick will destroy the switching transistor.

Frequently asked questions

How do I calculate PWM duty cycle?

Duty cycle is on-time divided by total period, expressed as a percentage. A 250 µs pulse in a 1 ms period is 25%. The average voltage delivered is the duty cycle times the supply voltage, provided the load integrates the switching.

What PWM frequency should I use?

For LEDs, above about 200 Hz to avoid visible flicker, with 1 kHz a common choice. For motors, above 20 kHz to move switching noise out of the audible band. For heaters, a fraction of a hertz is fine because the thermal mass does the integrating.

Is PWM the same as an analogue output?

No. PWM is a digital square wave whose average approximates an analogue level. Loads with inertia or inductance integrate it naturally; anything else needs an RC filter to turn it into a genuine analogue voltage.

What does PWM resolution mean?

The number of distinct duty steps the timer can produce, set by its bit depth. An 8-bit peripheral offers 256 steps, or about 0.39% each. Higher resolution costs maximum frequency at a fixed timer clock — the two divide the same budget.

Why does my motor whine?

Because the PWM frequency is inside the audible range and the windings physically vibrate at it. Raise the frequency above 20 kHz. The cost is higher switching loss, which is normally a good trade for silence.

Does duty cycle map linearly to brightness?

Electrically yes, perceptually no. Human vision responds roughly logarithmically, so equal duty steps look coarse at the dim end and indistinguishable at the bright end. Apply a gamma correction of about 2.2 for even-looking steps.

All electrical engineering tools