Last active
December 24, 2016 23:56
-
-
Save Jamil/9101595 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #lang racket | |
| (define (find-Vt temp) | |
| (define boltzmann 1.38e-23) ; J/K | |
| (define e-charge 1.60e-19) ; Coulombs/e- | |
| (/ (* boltzmann (+ temp 273)) e-charge)) | |
| (define (kvl-current Vdd R Vd) | |
| (/ (- Vdd Vd) R)) | |
| (define (log10 x) | |
| (/ (log x) (log 10))) | |
| (define (diode-voltage Vt Vd-prev Id-prev Id-curr) | |
| (+ Vd-prev (* 2.3 Vt (log10 (/ Id-curr Id-prev))))) | |
| (define (solve-iter Vt Vdd R Vd-prev Id-prev) | |
| (cond ((< (abs (- (diode-voltage Vt Vd-prev Id-prev (kvl-current Vdd R Vd-prev)) Vd-prev)) 0.0001) Vd-prev) | |
| (else | |
| (solve-iter Vt Vdd R (diode-voltage Vt Vd-prev Id-prev (kvl-current Vdd R Vd-prev)) (kvl-current Vdd R Vd-prev))))) | |
| (define (solve Vdd R Vd-ref Id-ref temp) | |
| (solve-iter (find-Vt temp) Vdd R Vd-ref Id-ref)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment