LM317 Constant Current Calculator

Enter either the current or the resistor value to calculate the missing parameter.


A
mA


Ω



Formula: I = 1.25 / R | (R = 1.25 / I). Vref assumed to be 1.25V for LM317 constant current operation.

function calculateLM317Current() {
const current = parseFloat(document.getElementById(“lm317Current”).value);
const currentUnit = parseFloat(document.getElementById(“currentUnit”).value);
const resistor = parseFloat(document.getElementById(“lm317Resistor”).value);
const resistorUnit = parseFloat(document.getElementById(“resistorUnit”).value);
const result = document.getElementById(“lm317CurrentResult”);

const Vref = 1.25;

const hasCurrent = !isNaN(current);
const hasResistor = !isNaN(resistor);

if (hasCurrent && hasResistor) {
result.textContent = “Please leave one field blank.”;
return;
}

if (!hasCurrent && hasResistor) {
const I = Vref / (resistor * resistorUnit);
result.textContent = “Calculated Current = ” + (I * 1000).toFixed(2) + ” mA”;
} else if (hasCurrent && !hasResistor) {
const R = Vref / (current * currentUnit);
result.textContent = “Calculated Resistor = ” + R.toFixed(2) + ” Ω”;
} else {
result.textContent = “Please enter either current or resistor value.”;
}
}

function resetLM317Current() {
document.getElementById(“lm317Current”).value = “”;
document.getElementById(“lm317Resistor”).value = “”;
document.getElementById(“lm317CurrentResult”).textContent = “”;
document.getElementById(“currentUnit”).selectedIndex = 1;
document.getElementById(“resistorUnit”).selectedIndex = 0;
}


(adsbygoogle = window.adsbygoogle || []).push({});