Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Everything about electronics
Everything about electronics
.calculator-container {
max-width: 650px;
margin: 40px auto;
padding: 20px;
border: 2px solid #ccc;
border-radius: 12px;
background-color: #f9f9f9;
font-family: Arial, sans-serif;
}
.calculator-container h2 {
text-align: center;
margin-bottom: 5px;
}
.calculator-container p {
text-align: center;
font-size: 14px;
margin-bottom: 20px;
}
.calc-box {
padding: 15px;
border: 2px solid #aaa;
border-radius: 12px;
background-color: #fff;
}
.form-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.form-row label {
flex: 1.3;
}
.form-row input,
.form-row select {
flex: 2;
padding: 6px;
margin-left: 10px;
}
.form-buttons {
text-align: center;
margin-top: 15px;
}
.form-buttons button {
padding: 8px 18px;
margin: 5px;
font-size: 14px;
border-radius: 6px;
border: none;
background-color: #3498db;
color: white;
cursor: pointer;
}
.result-box {
margin-top: 20px;
text-align: center;
font-weight: bold;
font-size: 16px;
}
Leave one input blank (R1, R2, C, or Frequency) to calculate it. Duty cycle is always calculated.
Ω
kΩ
MΩ
Ω
kΩ
MΩ
µF
nF
pF
Hz
kHz
MHz
function calculateAstable() {
const r1Val = document.getElementById(“r1”).value;
const r2Val = document.getElementById(“r2”).value;
const cVal = document.getElementById(“c”).value;
const fVal = document.getElementById(“freq”).value;
const r1 = parseFloat(r1Val) * parseFloat(document.getElementById(“r1_unit”).value);
const r2 = parseFloat(r2Val) * parseFloat(document.getElementById(“r2_unit”).value);
const c = parseFloat(cVal) * parseFloat(document.getElementById(“c_unit”).value);
const f = parseFloat(fVal) * parseFloat(document.getElementById(“freq_unit”).value);
const filled = [r1Val !== “”, r2Val !== “”, cVal !== “”, fVal !== “”].filter(Boolean).length;
if (filled < 3) {
alert("Please fill any 3 fields. Leave one blank to calculate it.");
return;
}
let output = "";
if (r1Val === "") {
const r1_calc = (1 / f – 0.693 * r2 * c) / (0.693 * c);
const duty = ((r1_calc + r2) / (r1_calc + 2 * r2)) * 100;
output = `Calculated R1: ${formatWithUnit(r1_calc, "Ω")}
Duty Cycle: ${duty.toFixed(2)} %`;
} else if (r2Val === “”) {
const r2_calc = (1 / f – 0.693 * r1 * c) / (0.693 * c * 2);
const duty = ((r1 + r2_calc) / (r1 + 2 * r2_calc)) * 100;
output = `Calculated R2: ${formatWithUnit(r2_calc, “Ω”)}
Duty Cycle: ${duty.toFixed(2)} %`;
} else if (cVal === “”) {
const c_calc = (1 / f) / (0.693 * (r1 + 2 * r2));
const duty = ((r1 + r2) / (r1 + 2 * r2)) * 100;
output = `Calculated Capacitance: ${formatWithUnit(c_calc, “F”)}
Duty Cycle: ${duty.toFixed(2)} %`;
} else if (fVal === “”) {
const freq = 1 / (0.693 * (r1 + 2 * r2) * c);
const duty = ((r1 + r2) / (r1 + 2 * r2)) * 100;
output = `Calculated Frequency: ${formatWithUnit(freq, “Hz”)}
Duty Cycle: ${duty.toFixed(2)} %`;
} else {
const duty = ((r1 + r2) / (r1 + 2 * r2)) * 100;
output = `Duty Cycle: ${duty.toFixed(2)} %
All inputs provided. No missing value to calculate.`;
}
document.getElementById(“result”).innerHTML = output;
}
function formatWithUnit(value, baseUnit) {
const absVal = Math.abs(value);
if (baseUnit === “Ω”) {
if (absVal >= 1e6) return (value / 1e6).toFixed(2) + ” MΩ”;
if (absVal >= 1e3) return (value / 1e3).toFixed(2) + ” kΩ”;
return value.toFixed(2) + ” Ω”;
} else if (baseUnit === “F”) {
if (absVal >= 1e-6) return (value * 1e6).toFixed(2) + ” µF”;
if (absVal >= 1e-9) return (value * 1e9).toFixed(2) + ” nF”;
return (value * 1e12).toFixed(2) + ” pF”;
} else if (baseUnit === “Hz”) {
if (absVal >= 1e6) return (value / 1e6).toFixed(2) + ” MHz”;
if (absVal >= 1e3) return (value / 1e3).toFixed(2) + ” kHz”;
return value.toFixed(2) + ” Hz”;
}
return value.toFixed(2);
}
function resetAstable() {
[“r1”, “r2”, “c”, “freq”].forEach(id => document.getElementById(id).value = “”);
document.getElementById(“result”).innerHTML = “”;
}
(adsbygoogle = window.adsbygoogle || []).push({});