PWM Duty Cycle Calculator
Supports two calculation modes — "frequency + duty cycle → timing" and "period + high time → duty cycle" — with optional MCU clock frequency input to compute PWM resolution in bits.
FreeOnline Tool
Loading…
How to Use
- Select a calculation mode: Mode A "Frequency + Duty Cycle → Timing" or Mode B "Period + High Time → Duty Cycle" — the input fields below change accordingly.
- Mode A: enter the frequency (Hz) and duty cycle (0–100%).
- Mode B: enter the period T (seconds) and high time Th (seconds); Th is automatically capped to not exceed T.
- Optional: click an MCU clock preset — Arduino (16MHz), STM32 (72MHz), ESP32 (240MHz), or Pi Pico (133MHz) — or manually enter a clock frequency (Hz) to compute the PWM resolution at that clock. Click "None" or set the clock frequency to 0 to hide the resolution result.
- Click "Calculate" (or edit any field to trigger automatic recalculation).
- The results show six core values: frequency, duty cycle, period T, high time Th, low time Tl, and the high/low ratio. If a clock frequency is provided, a "PWM Resolution" section additionally shows the resolution in bits and steps.
- The "Time Units" section shows the period, high time, and low time in scientific notation plus ms/μs/ns units, useful for cross-checking against oscilloscope readings or code configuration.
- Click "Load Sample Data" to restore the default: Mode A, frequency=1000Hz, duty cycle=50%, clock=16MHz (Arduino).
Features
- Two interchangeable input modes: Mode A derives period and high/low timing from frequency and duty cycle; Mode B derives frequency and duty cycle from period and high time — covering both common "known conditions" scenarios.
- Core timing parameters (period, high time, low time) are automatically converted and displayed in seconds, milliseconds, microseconds, and nanoseconds simultaneously, reducing manual unit-conversion errors.
- When an MCU clock frequency is provided, computes the achievable duty-cycle adjustment precision (in bits and steps) at that PWM frequency using: resolution steps = floor(clock frequency / PWM frequency), resolution bits = floor(log2(steps)).
- Includes four built-in MCU clock frequency presets — Arduino (16MHz), STM32 (72MHz), ESP32 (240MHz), Raspberry Pi Pico (133MHz) — for one-click substitution of common development board parameters.
- In Mode B, the high time Th is bounds-checked and automatically clamped between 0 and the period T, preventing an invalid duty cycle result exceeding 100%.
Use Cases
Servo/ESC control signal timing verification
Servo signals typically use a 20ms period with a 1–2ms high pulse; use Mode B to enter period and high time and quickly get the corresponding duty cycle percentage for code configuration.
LED dimming: mapping PWM duty cycle to brightness
Use Mode A to enter a target PWM frequency and desired duty cycle to get the exact high/low timing needed for timer register configuration or software PWM implementation.
Evaluating MCU timer PWM resolution
Given an MCU clock frequency and target PWM frequency, calculate the achievable duty-cycle adjustment resolution (e.g., 8-bit/10-bit) to determine whether it meets dimming smoothness or motor speed control precision requirements.
Cross-checking frequency/time unit conversions (Hz/kHz/MHz and s/ms/μs/ns)
When debugging PWM waveforms captured by a logic analyzer or oscilloscope, quickly convert frequency or timing readings to other units and cross-check against register values configured in code.
FAQ
When should I use Mode A vs. Mode B?
Mode A (frequency + duty cycle → timing) is for when you already know the target PWM frequency and duty cycle percentage and want to derive the exact high/low timing for timer configuration. Mode B (period + high time → duty cycle) is for when you've read a period and high time directly from an oscilloscope or datasheet (e.g., a servo datasheet stating "20ms period, 1–2ms pulse width") and want to know the corresponding duty cycle percentage.
How is PWM resolution calculated, and why does it sometimes not show?
PWM resolution reflects how many steps a timer can subdivide one PWM period into, given a clock frequency, to adjust duty cycle. It's calculated as: resolution steps = floor(MCU clock frequency / PWM frequency), resolution bits = floor(log2(steps)). This section only appears when you've entered a clock frequency greater than 0; leaving it blank, entering 0, or clicking "None" hides it, since resolution has no meaning without a specific clock frequency.
What happens in Mode B if the high time Th is entered longer than the period T?
The tool automatically clamps Th between 0 and T (using Math.min(period, highTime)), meaning even if you enter a Th greater than T, the value actually used in the calculation is capped at T. The duty cycle will then show as 100% rather than an invalid result exceeding 100%.
Why do Arduino and ESP32 give different resolution bit counts for the same PWM frequency?
Because the resolution step count depends on the ratio of "MCU clock frequency / PWM frequency." Arduino's default clock is 16MHz while ESP32's is 240MHz — a 15x difference. At the same PWM frequency, ESP32 can subdivide one period into far more steps, giving a higher theoretical resolution in bits. This is one reason choosing a higher-clock-frequency MCU helps achieve finer duty-cycle control.