Duty Cycle Calculator

Duty Cycle Calculator
.calculator-widget-container { font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; max-width: 800px; margin: 0 auto; background: #ffffff; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.05); padding: 20px; color: #333; } .calc-header { text-align: center; margin-bottom: 25px; border-bottom: 2px solid #0073aa; padding-bottom: 15px; } .calc-header h2 { margin: 0; color: #0073aa; font-size: 24px; } .calc-input-row { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 20px; align-items: flex-end; } .calc-input-group { flex: 1; min-width: 200px; display: flex; flex-direction: column; } .calc-input-group label { font-weight: 600; margin-bottom: 8px; font-size: 14px; color: #555; } .calc-input-group input, .calc-input-group select { padding: 12px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; transition: border-color 0.3s; } .calc-input-group input:focus, .calc-input-group select:focus { border-color: #0073aa; outline: none; } .calc-btn { width: 100%; background-color: #0073aa; color: white; padding: 15px; border: none; border-radius: 4px; font-size: 18px; font-weight: bold; cursor: pointer; transition: background 0.2s; margin-top: 10px; } .calc-btn:hover { background-color: #005177; } .calc-result-box { background-color: #f9f9f9; border: 1px solid #eee; border-radius: 6px; padding: 20px; margin-top: 25px; display: none; } .calc-result-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #e0e0e0; } .calc-result-row:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; } .result-label { font-size: 16px; color: #666; } .result-value { font-size: 20px; font-weight: bold; color: #0073aa; } .result-main { text-align: center; font-size: 32px; color: #27ae60; margin: 15px 0; } .error-msg { color: #e74c3c; text-align: center; font-weight: bold; display: none; margin-top: 10px; } .content-section { margin-top: 40px; line-height: 1.6; color: #444; } .content-section h3 { color: #333; border-left: 4px solid #0073aa; padding-left: 10px; margin-top: 30px; } .formula-box { background: #f0f7fb; padding: 15px; border-left: 3px solid #0073aa; font-family: monospace; margin: 15px 0; font-size: 1.1em; } @media (max-width: 600px) { .calc-input-row { flex-direction: column; gap: 15px; } }

Duty Cycle Calculator

Using Total Period Using Frequency
sec (s) ms μs
sec (s) ms μs
Hz kHz MHz
Calculated Duty Cycle
0%
Pulse Width ($t_{on}$): 0 ms
Total Period ($T$): 0 ms
Signal Frequency: 0 Hz
Low Time ($t_{off}$): 0 ms

What is Duty Cycle?

Duty cycle is a measure of the fraction of time a signal is "active" or "high" during a single period of operation. It is most commonly used in electronics and telecommunications to describe pulse-width modulation (PWM) signals, which control power to devices like motors, LEDs, and servos.

Duty Cycle Formula

The duty cycle ($D$) is calculated as the ratio of the Pulse Width ($t_{on}$) to the Total Period ($T$) of the signal.

Duty Cycle (%) = ($t_{on}$ / $T$) × 100%

Where:

  • $t_{on}$: The duration the signal is active (Pulse Width).
  • $T$: The total time for one complete cycle (Period).

Calculating with Frequency

Since frequency ($f$) is the inverse of the period ($T = 1/f$), you can also calculate duty cycle if you know the frequency and the pulse width:

Duty Cycle (%) = $t_{on}$ × $f$ × 100%

Note: Ensure your units for time and frequency are compatible (e.g., seconds and Hertz) before calculating.

Common Examples

  • 50% Duty Cycle: The signal is high for half the time and low for half the time (a perfect square wave).
  • 10% Duty Cycle: The signal is on for a short burst (10% of the time) and off for the majority (90%) of the cycle.
  • 100% Duty Cycle: The signal is continuously on (DC voltage).
function toggleInputs() { var mode = document.getElementById('calcMode').value; var periodRow = document.getElementById('periodRow'); var freqRow = document.getElementById('freqRow'); if (mode === 'period') { periodRow.style.display = 'flex'; freqRow.style.display = 'none'; } else { periodRow.style.display = 'none'; freqRow.style.display = 'flex'; } // Hide results when switching modes to avoid confusion document.getElementById('resultBox').style.display = 'none'; document.getElementById('errorBox').style.display = 'none'; } function calculateDuty() { // Inputs var pwVal = parseFloat(document.getElementById('pulseWidth').value); var pwUnit = parseFloat(document.getElementById('widthUnit').value); var mode = document.getElementById('calcMode').value; var resultBox = document.getElementById('resultBox'); var errorBox = document.getElementById('errorBox'); // Validation if (isNaN(pwVal) || pwVal < 0) { errorBox.innerText = "Please enter a valid positive Pulse Width."; errorBox.style.display = "block"; resultBox.style.display = "none"; return; } var periodSeconds = 0; var freqHz = 0; // Logic based on mode if (mode === 'period') { var periodVal = parseFloat(document.getElementById('periodInput').value); var periodUnit = parseFloat(document.getElementById('periodUnit').value); if (isNaN(periodVal) || periodVal periodSeconds) { errorBox.innerText = "Error: Pulse Width cannot be larger than the Total Period."; errorBox.style.display = "block"; resultBox.style.display = "none"; return; } freqHz = 1 / periodSeconds; } else { // Frequency Mode var freqVal = parseFloat(document.getElementById('freqInput').value); var freqUnit = parseFloat(document.getElementById('freqUnit').value); if (isNaN(freqVal) || freqVal periodSeconds) { errorBox.innerText = "Error: Pulse Width is longer than the calculated period (" + formatTime(periodSeconds) + ")."; errorBox.style.display = "block"; resultBox.style.display = "none"; return; } } // Calculate Duty Cycle var dutyDecimal = pwSeconds / periodSeconds; var dutyPercent = dutyDecimal * 100; var offTimeSeconds = periodSeconds – pwSeconds; // Formatting Helpers function formatTime(sec) { if (sec < 0.001) return (sec * 1000000).toFixed(2) + " μs"; if (sec = 1000000) return (hz / 1000000).toFixed(2) + " MHz"; if (hz >= 1000) return (hz / 1000).toFixed(2) + " kHz"; return hz.toFixed(2) + " Hz"; } // Display Results document.getElementById('dutyResult').innerText = dutyPercent.toFixed(2) + "%"; document.getElementById('resPulse').innerText = formatTime(pwSeconds); document.getElementById('resPeriod').innerText = formatTime(periodSeconds); document.getElementById('resFreq').innerText = formatFreq(freqHz); document.getElementById('resOff').innerText = formatTime(offTimeSeconds); errorBox.style.display = "none"; resultBox.style.display = "block"; }

Leave a Reply

Your email address will not be published. Required fields are marked *