How to use it
- Choose what you want to find: the duty cycle from a pulse width, or the pulse width from a duty cycle.
- Enter the frequency in Hz.
- Enter the pulse width in milliseconds, or the duty cycle in percent.
- Enter the high voltage level and the resolution of your PWM peripheral in bits (8 is a common default).
Formulas
- Period T = 1 ÷ f
- Duty cycle D = t_on ÷ T, and back t_on = D × T; off-time T − t_on
- Average voltage V_avg = V × D (low level 0 V)
- RMS voltage V_rms = V × √D
- Register value = round(D × (2ⁿ − 1))
- Period ÷ pulse width = 1 ÷ D
Worked example
A 1 kHz PWM with 0.25 ms pulses at 5 V:
- T = 1 ÷ 1000 = 1 ms, D = 0.25 ÷ 1 = 25 %
- off-time 0.75 ms; period ÷ pulse width = 4
- average 5 × 0.25 = 1.25 V, RMS 5 × √0.25 = 2.5 V
- 8-bit register: 0.25 × 255 = 63.75 → 64
A hobby servo signal of 50 Hz with a 1.5 ms pulse has a 20 ms period and a 7.5 % duty cycle.
Tips
- Frequency and resolution trade off. A timer with a fixed clock gives fewer steps at higher PWM frequencies.
- Average voltage needs a load that averages: a motor, an LED seen by the eye or an RC filter. The instantaneous voltage is still 0 or V.
- Inverted outputs produce 100 % − D; check whether your pin is active high or low.