PWM Duty Cycle Calculator
Calculate PWM duty cycle, frequency, period, ON/OFF time instantly. Essential for motor control, LED dimming, Arduino projects, and signal processing applications.
PWM Duty Cycle Calculator
Calculate PWM duty cycle, frequency, period, ON/OFF time instantly. Essential for motor control, LED dimming, and signal processing.
Actions
Calculation Mode
Time Parameters
Common PWM Configurations
What is PWM (Pulse Width Modulation)?
PWM (Pulse Width Modulation) is a technique used to control the average power delivered to a load by switching it on and off at a high frequency. The duty cycle represents the percentage of time the signal is ON (high) versus the total period. PWM is widely used in motor speed control, LED brightness control, power regulation, audio synthesis, and digital-to-analog conversion. By varying the duty cycle, you can control the effective voltage or power delivered to the load without using variable resistors or linear regulators, making it highly efficient.
PWM Calculation Formulas
Duty Cycle Calculation
Duty Cycle (%) = (ON Time / Period) × 100
Where Period = ON Time + OFF Time. Duty cycle represents the fraction of time the signal is high. A 50% duty cycle means the signal is ON for half the period and OFF for the other half.
ON Time Calculation
ON Time = (Duty Cycle / 100) × Period
Calculate the ON time when you know the desired duty cycle and period. For example, a 25% duty cycle with 10ms period gives ON time = 0.25 × 10ms = 2.5ms.
Frequency and Period
Frequency (Hz) = 1 / Period (s)
Frequency is the number of complete cycles per second. A 1kHz PWM signal has a period of 1ms. Higher frequencies result in smoother control but may increase switching losses.
Complete Example
Given: ON Time = 2ms, OFF Time = 8ms
Step 1: Period = 2ms + 8ms = 10ms
Step 2: Duty Cycle = (2ms / 10ms) × 100 = 20%
Step 3: Frequency = 1 / 0.01s = 100 Hz
Common PWM Applications
Arduino PWM Pins and Frequencies
| Board | PWM Pins | Frequency | Resolution |
|---|---|---|---|
| Arduino Uno | 3, 5, 6, 9, 10, 11 | 490 Hz (980 Hz on 5,6) | 8-bit (0-255) |
| Arduino Mega | 2-13, 44-46 | 490 Hz (980 Hz on 4,13) | 8-bit (0-255) |
| ESP32 | All GPIO pins | 5 kHz (configurable) | 8-16 bit |
| Raspberry Pi Pico | All GPIO pins | 1 kHz (configurable) | 16-bit |
Choosing PWM Frequency
PWM Resolution and Duty Cycle
Understanding Resolution
8-bit PWM (Arduino): 256 steps (0-255). Duty cycle = (value / 255) × 100%. Value 128 = 50% duty cycle. Sufficient for most applications.
10-bit PWM: 1024 steps (0-1023). Finer control, useful for precise motor speed or LED brightness control. Value 512 = 50% duty cycle.
16-bit PWM (ESP32, Pico): 65536 steps (0-65535). Ultra-fine control for professional applications. Value 32768 = 50% duty cycle.
| Duty Cycle | 8-bit Value | 10-bit Value | Application |
|---|---|---|---|
| 0% | 0 | 0 | OFF / Stop |
| 25% | 64 | 256 | Low speed / Dim |
| 50% | 128 | 512 | Medium speed / Half brightness |
| 75% | 192 | 768 | High speed / Bright |
| 100% | 255 | 1023 | Full speed / Maximum brightness |
Frequently Asked Questions
What is the difference between duty cycle and frequency?
Duty cycle is the percentage of time the signal is ON during one period, while frequency is the number of complete cycles per second. A 50% duty cycle at 1kHz means the signal is ON for 0.5ms and OFF for 0.5ms, repeating 1000 times per second. You can have the same duty cycle at different frequencies.
How do I calculate PWM duty cycle for Arduino?
Arduino uses 8-bit PWM (0-255). To set a specific duty cycle, use: analogWrite(pin, (dutyCycle / 100) × 255). For 50% duty cycle: analogWrite(9, 128). For 25%: analogWrite(9, 64). For 75%: analogWrite(9, 192). The default Arduino PWM frequency is 490 Hz on most pins.
What PWM frequency should I use for LED dimming?
Use at least 100 Hz to avoid visible flicker, but 200-1000 Hz is recommended for smooth dimming. Higher frequencies (1-10 kHz) eliminate flicker completely and work better with cameras. Very high frequencies (> 20 kHz) may cause audible noise in some LED drivers. Arduino default 490 Hz works well for most LED applications.
Can I use PWM to control AC devices?
Not directly. PWM from microcontrollers is DC (0-5V). To control AC devices, use a solid-state relay (SSR), TRIAC, or optocoupler with zero-crossing detection. For AC motor speed control, use phase control (dimmer circuit) or variable frequency drive (VFD), not simple PWM. Never connect PWM output directly to AC mains.
Why does my motor make noise with PWM control?
Audible noise occurs when PWM frequency is below 20 kHz (human hearing range). The motor vibrates at the PWM frequency, creating sound. Solution: Increase PWM frequency to 20-40 kHz using timer configuration. Trade-off: Higher frequency increases switching losses and heat in the motor driver. Use proper motor driver ICs designed for PWM control.
How do I convert PWM to analog voltage?
Use a low-pass RC filter. Connect PWM output to a resistor (1-10kΩ), then to a capacitor (0.1-10µF) to ground. Output voltage = Supply Voltage × (Duty Cycle / 100). For 5V PWM at 50% duty cycle, output is 2.5V. Filter cutoff frequency should be 10-100× lower than PWM frequency for smooth DC output. Add op-amp buffer for low-impedance output.
What is the maximum PWM frequency for Arduino?
Arduino Uno can achieve up to 62.5 kHz PWM by modifying timer prescaler, but at reduced resolution (4-bit instead of 8-bit). Default is 490 Hz (8-bit). ESP32 supports up to 40 MHz PWM with configurable resolution. Higher frequency requires lower resolution due to timer limitations. For most applications, 1-20 kHz at 8-bit resolution is optimal.
💡 Pro Tip
When using PWM for motor control, always use a motor driver IC (L298N, L293D, TB6612) instead of driving the motor directly from microcontroller pins. Motor drivers provide current amplification, flyback diode protection, and thermal shutdown. For LED dimming, use PWM frequency > 200 Hz to avoid flicker. For servo control, use exactly 50 Hz (20ms period) with 1-2ms pulse width. Always measure actual PWM frequency with an oscilloscope when precision matters, as software delays and interrupts can affect timing.