<!DOCTYPE html>
<html ng-app="LM3404Calculator">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.css">
<link rel="stylesheet" href="style.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.js"></script>
<script src="//code.angularjs.org/1.3.1/angular.js"></script>
<script src="http://code.angularjs.org/1.2.1/angular-animate.js"></script>
<script src="script.js"></script>
</head>
<body role='document'>
<div class="container theme-showcase" role="main">
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>LM3404 Component Calculator</h1>
<p>This tool determines possible component values for the LM3404.</p>
</div>
<form ng-controller="LM3404CalculatorController">
<div class="page-header">
<h1>Define system parameters</h1>
</div>
<div class="row">
<div class='col-md-2'>
<label for="Vin">V<sub>in</sub></label>
<input type='text' class='form-control' id='Vin' ng-model="step1.Vin" ng-focus="setRelated('Vin')" />
</div>
<div class='col-md-2'>
<label for="current">Current</label>
<input type='text' class='form-control' id='current' ng-model="step1.current" ng-focus="setRelated('Current')"/>
</div>
<div class='col-md-2'>
<label for="LEDVf">LED V<sub>f</sub></label>
<input type='text' class='form-control' id='LEDVf' ng-model="step1.LEDVf" ng-focus="setRelated('LEDVf')"/>
</div>
<div class='col-md-2'>
<label for="NumLEDs"># of LEDs</label>
<input type='text' class='form-control' id='NumLEDs' ng-model="step1.NumLEDs" ng-focus="setRelated('NumLEDs')"/>
</div>
<div class='col-md-2'>
<label for="allowed-ripple">Ripple (%)</label>
<input type='text' class='form-control' id='allowed-ripple' ng-model="step1.allowedRipple"/>
</div>
<div class='col-md-2'>
<label for="frequency">Frequency (kHz)</label>
<input type='text' class='form-control' id='frequency' ng-model="step1.frequency"/>
</div>
</div>
<div class='row'><div class='col-md-12'> </div></div>
<div class='panel panel-default'>
<div class='panel-heading'>
<h3 class='panel-title'>Calculated Results</h3>
</div>
<div class='panel-body'>
<div class='row'>
<div class='col-md-2'>
<input type="checkbox" ng-model="step1.lockRon" data-toggle="tooltip" data-placement="top" title="Lock Value"><label>E96 R<sub>on</sub> (kOhm)</label><br />
<input type='text' class='form-control' id='RonStd' ng-model="step1.RonStd" />
</div>
<div class='col-md-2'>
<label>R<sub>on</sub> (kOhm)</label><br />
<span type='text' class='form-control-static'>{{step1.Ron()| number:1}}</span>
</div>
<div class='col-md-2'>
<label>V<sub>out</sub></label><br />
<span type='text' class='form-control-static'>{{step1.Vout() | number:2}}</span>
</div>
<div class='col-md-2'>
<label>t<sub>on</sub> (ns)</label><br />
<span type='text' class='form-control-static'>{{step1.ton() | number:0}}</span>
</div>
<div class='col-md-2'>
<label>T<sub>off</sub> (ns)</label><br />
<span type='text' class='form-control-static'>{{step1.toff() | number:0}}</span>
</div>
<div class='col-md-2'>
<label>frequency (kHz)</label><br />
<span type='text' class='form-control-static'>{{step1.calculatedFrequency() | number:1}}</span>
</div>
</div>
<div class='row'>
<div class='col-md-2'>
<input type="checkbox" ng-model="step1.lockInductor" data-toggle="tooltip" data-placement="top" title="Lock Value"><label>E96 Inductor (uH)</label><br />
<input type='text' class='form-control' id='RonStd' ng-model="step1.inductorStandardValue" />
</div>
<div class='col-md-2'>
<label>Inductor (uH)</label><br />
<span type='text' class='form-control-static'>{{step1.inductor()| number:1}}</span>
</div>
<div class='col-md-2'>
<label>Inductor Tolerance (%)</label><br />
<span type='text' class='form-control-static'>{{step1.inductorTolerance}}</span>
</div>
<div class='col-md-2'>
<label>Current Ripple</label><br />
<span type='text' class='form-control-static'>{{step1.currentRipple() | number:3}}</span>
</div>
<div class='col-md-2'>
<label>Current Range</label><br />
<span type='text' class='form-control-static'>{{step1.currentPeak()| number:3}} - {{step1.currentValley()| number:3}}</span>
</div>
<div class='col-md-2'>
<label>Output Current</label><br />
<span type='text' class='form-control-static'>{{step1.ouptutCurrent() | number:3}}</span>
</div>
</div>
<div class='row'>
<div class='col-md-2'>
<input type="checkbox" ng-model="step1.lockRsns" data-toggle="tooltip" data-placement="top" title="Lock Value"><label>E96 R<sub>sns</sub></label><br />
<input type='text' class='form-control' id='RonStd' ng-model="step1.RsnsStandard" />
</div>
<div class='col-md-2'>
<label>R<sub>sns</sub></label><br />
<span type='text' class='form-control-static'>{{step1.Rsns()| number:3}}</span>
</div>
<div class='col-md-2'>
<label>Δ<i>i</i> (min-typ-max)</label><br />
<span type='text' class='form-control-static'>
{{step1.currentDeltaMin() | number:3}} - {{step1.currentDeltaTypical() | number:3}} - {{step1.currentDeltaMax() | number:3}}
</span>
</div>
<div class='col-md-2'>
<label>Peak Current</label><br />
<span type='text' class='form-control-static'>{{step1.peakCurrent()| number:3}}</span>
</div>
<div class='col-md-2'>
<label>Peak current led-short</label><br />
<span type='text' class='form-control-static'>{{step1.ledShortPeakCurrent()| number:1}}</span>
</div>
</div>
</div>
</div>
</form>
</div>
</body>
</html>
// Code goes here
angular.module("LM3404Calculator", []).controller("LM3404CalculatorController",
function LM3404CalculatorController($scope){
var inductorValues = [10,12,15,18,22,27,33,39,47,56,68,82];
var getStandardResistor = function(r){
var decade = Math.floor(Math.log(r) / Math.log(10));
var Mant = r / Math.pow(10,decade);
var i = Math.ceil(96 * Math.log(Mant) / Math.log(10));
return (Math.pow(10,decade) * Math.pow(10, (i/96)).toFixed(2));
};
var getStandardInductor = function(l){
var val = 0;
var i = 0;
var j = 1;
while(val === 0){
if (l < inductorValues[i]*j)
val = inductorValues[i]*j;
i++;
if (i >= inductorValues.length){
i=0;
j++;
}
if (j > 10)
return undefined;
}
return val;
}
$scope.step1 = {
k: 0.000000000134,
tsns: 0.00000022,
Vin: 24,
current: 0.7,
LEDVf: 3.5,
NumLEDs: 1,
allowedRipple: 20,
frequency: 400,
RonStd: 0,
inductorStandardValue: 0,
inductorTolerance: 20,
RsnsStandard: 0,
lockRon: false,
lockRsns: false,
lockInductor: false,
frequencyHertz: function(){return this.frequency*1000;},
Vout: function(){ return (this.LEDVf * this.NumLEDs) + 0.2;},
currentRipple: function(){ return parseFloat(this.current) * (this.allowedRipple/100);},
currentPeak: function(){ return parseFloat(this.current) + (this.currentRipple()/2);},
currentValley: function(){ return parseFloat(this.current) - (this.currentRipple()/2);},
Ron: function(){ return (this.Vout()/(this.k*this.frequencyHertz()))/1000; },
ton: function(){ return (this.k * (this.RonStd * 1000)/this.Vin) * 1000000000;},
toff: function() {
var x = (this.Vin*0.8202)/this.Vout();
x = x-1;
return (this.ton())*x;
},
calculatedFrequency: function(){return this.Vout()/(this.k*(this.RonStd*1000))/1000;},
inductor: function(){return (((this.Vin - this.Vout())/this.currentRipple())*(this.ton()/1000000000))*1000000;},
Rsns: function(){
var L = this.inductorStandardValue/1000000;
return (0.2*L)/((this.current*L)+(this.Vout()*this.tsns)-(((this.Vin-this.Vout())/2)*(this.ton()/1000000000)));
},
currentDeltaTypical: function(){return ((this.Vin-this.Vout())*(this.ton()/1000000000))/(this.inductorStandardValue/1000000);},
currentDeltaMax: function(){return ((this.Vin-this.Vout())*(this.ton()/1000000000))/((this.inductorStandardValue/1000000)*(1-(this.inductorTolerance/100)));},
currentDeltaMin: function(){return ((this.Vin-this.Vout())*(this.ton()/1000000000))/((this.inductorStandardValue/1000000)*(1+(this.inductorTolerance/100)));},
peakCurrent: function(){return parseFloat(this.current) +(this.currentDeltaMax()/2);},
ledShortCurrentDelta: function(){return (this.Vin-0.2)*(this.ton()/1000000000)/((this.inductorStandardValue/1000000) *(1-(this.inductorTolerance/100)));},
ledShortPeakCurrent: function(){return parseFloat(this.current) + this.ledShortCurrentDelta()/2;},
ouptutCurrent: function(){ return (.2/this.RsnsStandard) + ((this.Vin-this.Vout())/(2*(this.inductorStandardValue/1000000)))*(this.ton()/1000000000) + ((this.Vout()*this.tsns)/((this.inductorStandardValue/1000000))) }
};
$scope.$watch(function(scope) { return scope.step1.Ron(); },
function(newValue, oldValue) {
if (!$scope.step1.lockRon)
$scope.step1.RonStd = getStandardResistor(newValue * 1000)/1000;
});
$scope.$watch(function(scope) { return scope.step1.Rsns(); },
function(newValue, oldValue) {
if (!$scope.step1.lockRsns)
$scope.step1.RsnsStandard = getStandardResistor(newValue * 100000)/100000;
});
$scope.$watch(function(scope) { return scope.step1.inductor(); },
function(newValue, oldValue) {
if (!$scope.step1.lockInductor)
$scope.step1.inductorStandardValue = getStandardInductor(newValue);
});
$scope.relationships = {
'Vin': ['Ron', 'Vout', 'Inductor', 'Ton'],
'Current' : ['Ripple', 'Peak', 'Valley'],
'LEDVf': ['Vout'],
'LEDCount': ['Vout'],
'Ripple': [],
'Frequency': []
};
$scope.affectedFields = [];
$scope.setRelated = function(val){
$scope.affectedFields = $scope.relationships[val];
};
$scope.clearRelated;
}
).directive('animateOnChange', function($animate) {
return function(scope, elem, attr) {
scope.$watch(attr.animateOnChange, function(nv,ov) {
if (nv!=ov) {
var c = 'affected';
$animate.removeClass(elem,c);
$animate.addClass(elem,c);
}
});
};
});
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
/* Styles go here */
.affected{
-webkit-animation: highlight 3s;
-moz-animation: highlight 3s;
animation: highlight 3s;
}
@-webkit-keyframes highlight{
from {background: yellow;}
to {background: none;}
}
@keyframes highlight{
from {background: orange;}
to {background: none;}
}
.change {
background-color: red;
}
.change-add,.change-remove {
background-color: white;
transition: all 1s;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
}
.change-add-active {
background-color: red;
}
.change-remove {
background-color: red;
}
.change-remove-active {
background-color: white;
}
.change-up {
background-color: green;
}
.change-up-add,.change-up-remove {
background-color: white;
transition: all 1s;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
}
.change-up-add-active {
background-color: green;
}
.change-up-remove {
background-color: green;
}
.change-up-remove-active {
background-color: white;
}
LM 3404 Calculator
This is a calculator to determine component values for LM3404 circuit