ForHosting KIT · Engineering & construction

PWM duty cycle calculator

2 ms on in a 10 ms period is a 20 % duty cycle, and on a 5 V supply that averages 1 V. Enter on-time, period and supply voltage to get the duty fraction, percentage and ideal average voltage. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
PWM high
2
Full PWM period
10
Supply
5
You get
Ton
2
T
10
V
5
Duty
0.2

A PWM duty cycle calculator turns pulse on-time and full period into the fraction and percentage that describe how long a digital waveform sits high, then multiplies that fraction by supply voltage to give the ideal average output voltage.

What duty cycle and average voltage mean for a PWM waveform

Pulse-width modulation encodes an analog level in a digital square wave by holding the output high for an on-time ton inside each repeating period T. The duty cycle fraction is defined by the closed ratio D equals ton divided by T; the duty percent is one hundred times that fraction.

For an ideal two-level signal that switches between zero and a fixed supply voltage V, the time-average voltage over one period is simply Vavg equals D times V, because the integral of the high plateau contributes ton times V and the low plateau contributes zero. Doubling ton at fixed T doubles both D and Vavg; doubling T at fixed ton halves them. Period must stay strictly positive because a zero-length cycle leaves no finite denominator under the ratio, and negative period is outside the usual time-duration model.

Classroom numbers are easy: ton equals two and T equals ten with V equals five yields D equals zero point two, twenty percent duty, and one volt average; ton equals five and T equals ten with the same five volts yields fifty percent and two point five volts. Teachers and automated graders care about the zero-period rejection as much as the arithmetic: a student who plugs T equals zero has left the domain of the formula, and a silent absolute-value fallback would hide that mistake.

Prefer consistent units for ton and T—both milliseconds or both seconds—so D is dimensionless and frequency one over T is interpreted correctly.

Homework checks for PWM duty and Vavg

Students enter on-time, period, and supply voltage from textbook PWM problems and compare hand-written D, duty percent, and average voltage against a deterministic result.

LED and heater pre-flight estimates

Designers estimate ideal average voltage from planned ton and T before budgeting filters, thermal load, or DAC alternatives.

Can duty exceed 100%?

The calculator reports the mathematical ratio without clamping so over-wide pulses stay visible.

Is the PWM duty cycle calculator free?

The browser tool is free and runs locally.

How do I calculate PWM duty cycle?

Divide the on-time by the full period, then multiply by 100 for a percentage. Holding the output high for 5 of every 10 time units, for example, gives a 50 % duty cycle.

How is average voltage related to duty cycle?

Multiply the duty cycle by the supply voltage. An ideal signal switching between 0 V and 5 V at 50 % duty averages 2.5 V, and doubling the on-time at the same period doubles the average.

Do on-time and period need the same unit?

Yes. Enter both in milliseconds or both in seconds, so the duty cycle has no unit and the frequency, one divided by the period, is read in the right unit.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/elec/pwm-duty-cycle

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/elec/pwm-duty-cycle \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"on_time":2,"period":10,"voltage":5}'
{
  "on_time": 2,
  "period": 10,
  "voltage": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "elec.pwm_duty_cycle",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

max_abs1000000000000
HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Period must be strictly positive: a zero period would divide by zero, so the API returns a clear invalid_input error instead of inventing Infinity or NaN.

What duty cycle and average voltage mean for a PWM waveform

The check path recomputes ton over T and D times V with the same fixed rounding used for published fields, so a successful response always ships with steps you can assert in tests or worksheets without floating-point ambiguity between the Worker and the browser.

How to call the API and what comes back

On-time must be non-negative; a negative high interval is rejected for this ideal digital PWM model. Prefer sending numbers rather than pre-formatted strings when you control the client; string numbers are accepted only when they match a strict finite numeric pattern including optional scientific notation. Send a JSON body with three required finite numbers: on_time (aliases ton, t_on, high_time, pulse_width, and pw) for the high interval, period (aliases T, t_period, cycle_time, and pwm_period) for the full cycle length in the same time unit, and voltage (aliases V, vcc, v_supply, amplitude, and supply_voltage) for the high-level amplitude in volts. Absolute values must stay within the published limit of one trillion so intermediate ratios and products remain finite in IEEE double precision on the Worker and in the browser. Period must be strictly positive; values whose absolute magnitude is at or below one times ten to the minus fifteen are treated as zero and rejected, and any strictly negative period is also invalid_input. On success the response echoes rounded on_time and ton, period and T, voltage and V, sets duty, duty_cycle, and duty_fraction to the same dimensionless fraction, duty_percent to one hundred times D, average_voltage and Vavg to D times V in volts, off_time to period minus on_time, frequency to one over period, formula to the documented D and Vavg strings, equation to a human-readable substitution line, unit labels for fraction, percent, and volts, message to a short English summary, and steps to an ordered array of given values, formulas, duty, percent, off time, frequency, average voltage, and summary. Failed validation—missing fields, non-numeric strings, non-finite numbers, values outside absolute limits, zero or negative period, negative on-time, or a non-finite ratio—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item and zero marginal unit price.

Practical tips, limits, and related searches

Keep on-time, period, and voltage inside the published absolute range so the ratio and product stay finite under the magnitude cap. Use the same time unit for ton and T before you call if you want duty already dimensionless and frequency already in the reciprocal of that unit without mental rescaling afterward. Prefer this capability when you already have scalar on-time, period, and supply voltage and only need D, duty percent, and ideal Vavg; if your source is a microcontroller compare match and clock divider, convert those into seconds or ticks first so both intervals share a unit. When teaching, pair examples: ton equals two, T equals ten, V equals five yields twenty percent and one volt average; ton equals five, T equals ten, V equals twelve yields fifty percent and six volts; ton equals zero with positive T yields zero duty and zero average; and setting period to zero demonstrates the hard invalid_input path. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when learners deliberately set period to zero. Round-trip checks are easy: recompute ton divided by T and multiply by V by hand and confirm the published duty and average_voltage match within the same twelve-decimal rounding, and confirm that scaling ton and T by the same positive factor leaves D and Vavg unchanged as the formula predicts.

Unit tests for dimming and motor-driver code

Generate known-good duty and Vavg cases plus deliberate zero-period rejections for coding kata expected values.

How is PWM duty cycle calculated?

Duty fraction D = on_time / period. Duty percent is 100 · D. Keep on_time and period in the same time unit so D is dimensionless.

How is average voltage related to duty cycle?

For an ideal 0-to-V square wave, Vavg = D · V = (on_time / period) · voltage. That is the DC level a perfect low-pass would recover.

What happens when period is zero?

The ratio on_time / period is undefined. This tool returns invalid_input instead of Infinity or NaN.

Read the full KIT documentation →