Created
January 28, 2017 13:36
-
-
Save lukewilde/76ba6f98eeb5e75a145e8d7940fb5928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var original = { | |
resistorA: 470, | |
resistorB: 1, | |
capacitor: 0.01 | |
}; | |
var adapted = { | |
resistorA: 100, | |
resistorB: 0.27, | |
capacitor: 0.047 | |
}; | |
function getChargeTime(circuit) { | |
return 0.693 * (circuit.resistorA + circuit.resistorB) * circuit.capacitor; | |
} | |
function getDischargeTime(circuit) { | |
return 0.693 * circuit.resistorB * circuit.capacitor; | |
} | |
function getTotalPeriod(circuit) { | |
return getChargeTime(circuit) + getDischargeTime(circuit); | |
} | |
function getFrequency(circuit) { | |
var frequency = 1.44 / ((circuit.resistorA + circuit.resistorB) * circuit.capacitor); | |
// Making micro second readable | |
var hz = frequency * 1000; | |
if (hz > 1000) { | |
return (hz / 1000).toFixed(4) + 'khz'; | |
} else { | |
return hz.toFixed(4) + ' hz'; | |
} | |
} | |
function getDutyCycle(circuit) { | |
return circuit.resistorB / (circuit.resistorA + circuit.resistorB * 2) | |
} | |
function showStats(circuit, title) { | |
console.log('\n' + title + '\n'); | |
console.log('Charge Time: ', getChargeTime(circuit).toFixed(4) + ' seconds'); | |
console.log('Discharge Time: ', getDischargeTime(circuit).toFixed(4) + ' seconds'); | |
console.log('Total Period: ', getTotalPeriod(circuit).toFixed(4)); | |
console.log('Frequency: ', getFrequency(circuit)); | |
console.log('Duty Cycle: ', getDutyCycle(circuit)); | |
} | |
showStats(original, 'original'); | |
showStats(adapted, 'adapted'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment