PWM Duty Cycle and Average Voltage Calculator
PWM Duty Cycle and Average Voltage Calculator
On and off times, average voltage, RMS voltage and average power from a PWM frequency and duty cycle — plus the microcontroller timer view: what frequency and duty-cycle step your clock, prescaler and resolution actually give.
PWM duty cycle
1 kHz, 60% duty, 12 V high, 0 V low, into 100 Ω, from a 16 MHz clock with a /8 prescaler and 8-bit fast PWM
Average, RMS and power of a rectangular wave
- D
- duty cycle as a fraction: the share of each cycle spent at the high level
- Vrms
- the DC voltage that would heat the same resistor equally; found by averaging the square, then taking the root
- 2bits
- counter steps per cycle; an up-and-down (phase-correct) counter takes twice as many
Worked example
1 kHz, 60% duty, 12 V high, 0 V low, into 100 Ω, from a 16 MHz clock with a /8 prescaler and 8-bit fast PWM
Period = 1 ÷ 1 kHz = 1 ms, so on = 0.6 ms (600 µs) and off = 400 µs
Vavg = 0.6 × 12 + 0.4 × 0 = 7.2 V
Vrms = √(0.6 × 12²) = √86.4 = 9.2952 V — higher than the average
Power = Vrms² ÷ R = 86.4 ÷ 100 = 864 mW. Using the average voltage instead would give 518.4 mW, which is wrong by two thirds
Timer: 16 MHz ÷ (8 × 256) = 7.813 kHz, in steps of 0.3906%; the nearest duty to 60% is 60.1563% (compare value 154)
PWM frequency from a 16 MHz clock
| Prescaler | Resolution | Counter | PWM frequency | Duty step |
|---|---|---|---|---|
| 1 | 8-bit | up only | 62.5 kHz | 0.3906% |
| 8 | 8-bit | up only | 7.813 kHz | 0.3906% |
| 64 | 8-bit | up only | 976.6 Hz | 0.3906% |
| 256 | 8-bit | up only | 244.1 Hz | 0.3906% |
| 1024 | 8-bit | up only | 61.04 Hz | 0.3906% |
| 1 | 10-bit | up only | 15.63 kHz | 0.0977% |
| 8 | 8-bit | up and down | 3.906 kHz | 0.3906% |
What PWM actually delivers
Pulse-width modulation switches a fixed voltage on and off quickly and varies the share of each cycle it spends on. Nothing in between is ever produced — the output is always either the high level or the low one — but anything with enough inertia responds to the average. A motor’s rotor, an LED seen by the eye, a heater’s thermal mass and a capacitor after a resistor all average the pulses out. The frequency has to be high enough for that: above about 100 Hz for an LED, a few hundred hertz upward for a brushed motor (often above 20 kHz to get the whine out of the audible band), and above the corner of the filter for a filtered output.
Average is not RMS. The average of the waveform is D·Vh + (1−D)·Vl — with 60% of 12 V that is 7.2 V. The RMS value comes from averaging the square and then taking the root: over one period the square is Vh² for a fraction D of the time and Vl² for the rest, so the mean square is D·Vh² + (1−D)·Vl² and Vrms = √(that) = 9.2952 V. The power in a resistor is the average of v²/R, which is exactly Vrms² ÷ R = 864 mW. Squaring the average instead gives 518.4 mW and is simply wrong — the two agree only at 0% and 100%. This is why a heater on 50% PWM delivers half its full power, not a quarter, and why a meter that reads mean and a meter that reads true RMS disagree on a PWM signal.
The microcontroller’s view. A hardware PWM channel counts a timer from 0 to a top value and compares it with a register. The PWM frequency is therefore the clock divided by the prescaler and by the number of counts per cycle: 16 MHz with a prescaler of 8 and an 8-bit counter gives 16,000,000 ÷ (8 × 256) = 7.813 kHz. A counter that runs up and then back down — phase-correct mode — takes twice as many steps and halves that. Resolution and frequency trade against each other one for one: 8 bits gives 0.3906% steps, so 60% comes out as 60.1563% (compare value 154 of 256), while 16 bits resolves to 0.0015% but at 1/256th of the frequency for the same prescaler.
PWM is not a DAC until you filter it. A PWM output is a square wave with a DC component, not a variable voltage. To turn it into one you need a low-pass filter whose corner is well below the PWM frequency — a factor of a hundred or more if you want the ripple small — and then the output is slow to settle, because the same filter that removes the ripple also removes the speed. Work the corner out with the RC filter calculator and the settling with the RC time constant calculator. For driving a load directly, the switch itself costs something: a MOSFET dissipates conduction loss all through the on time and switching loss at every edge, and the MOSFET loss calculator adds those up. A 555 will generate a PWM signal in hardware if you have no microcontroller — see the 555 astable calculator for the duty cycle it can reach.
Frequently asked questions
How do I calculate the average voltage of a PWM signal?
Average = duty × high level + (1 − duty) × low level. A 12 V signal at 60% duty switching down to 0 V averages 7.2 V.
What is the RMS voltage of a PWM signal?
√(D·Vh² + (1−D)·Vl²). For 60% of 12 V that is √86.4 = 9.2952 V, noticeably higher than the 7.2 V average. Use the RMS value for power in a resistive load, the average for a filtered output or a motor’s speed.
How much power does PWM deliver to a resistive load?
Vrms² ÷ R, which works out as (D·Vh² + (1−D)·Vl²) ÷ R — so with a 0 V low level the power is simply the duty cycle times the full-power figure. 60% of 12 V into 100 Ω gives 864 mW, exactly 60% of the 1.44 W the load would take at a steady 12 V.
How do I work out the PWM frequency from a microcontroller timer?
Clock ÷ (prescaler × counter steps per cycle). 16 MHz with a /8 prescaler and an 8-bit counter is 16,000,000 ÷ 2,048 = 7.813 kHz. A phase-correct counter runs up and down, so it takes 512 steps and halves the frequency.
Can I use PWM as a digital-to-analogue converter?
Only after a low-pass filter. On its own a PWM output is a square wave that happens to have the right average; a resistor and capacitor with a corner well below the PWM frequency turn it into a voltage, at the cost of settling time. A motor or an LED does its own averaging and needs no filter.
Related calculators
References
- Mohan N, Undeland TM, Robbins WP. Power Electronics: Converters, Applications, and Design, 3rd ed. Wiley, 2003. Chapter 8 on switch-mode dc–dc conversion: the duty ratio, the average of a switched waveform and why a filter is what turns it into a dc level.
- Horowitz P, Hill W. The Art of Electronics, 3rd ed. Cambridge University Press, 2015. §7.1.3, “The classic oscillator–timer chip: the 555”.
- Texas Instruments. LM555 Timer, datasheet SNAS548 — the 555 in astable mode as a hardware PWM source, with the duty cycle set by the ratio of the two timing resistors.
- BIPM. The International System of Units (SI Brochure), 9th ed., 2019 — the watt as J/s and the definition of RMS as the value of a steady quantity producing the same mean power.
