Last active
August 29, 2015 14:17
-
-
Save codedot/ce479a4c606e7ff6b0b9 to your computer and use it in GitHub Desktop.
Learning SPICE
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
output.txt |
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
LED adjustment | |
.PARAM Tstep = 50us | |
.PARAM Nsteps = 100 | |
.TRAN {Tstep} {Nsteps * Tstep} {Tstep} uic | |
.PLOT TRAN I(Vled) | |
.PLOT TRAN V(vfb) | |
.OPTIONS NOPAGE LIST | |
* How much light from LED reaches photo diode | |
.PARAM Rfb = 0.05 | |
* Limits of our LED | |
.PARAM Iledmax = 20mA | |
.PARAM Iledmin = 5mA | |
* Coefficient from LT1932's datasheet | |
.PARAM K = 225 | |
* Voltage on Rset according to LT1932's datasheet | |
.PARAM Vrsetdc = 100mV | |
* Our battery | |
.PARAM Vmax = 3V | |
* What signal we want to get | |
.PARAM Vtarget = 2V | |
.PARAM Itarget = 20uA | |
* Transimpedance of the photo diode amplifier | |
.PARAM Rprobe = {Vtarget / Itarget} | |
* Tolerable current loss | |
.PARAM Iloss = {Iledmax / K} | |
* Estimation of the B-E potential | |
.PARAM Vcutin = 600mV | |
* Unity-gain frequency of OA1NP | |
.PARAM Fu = 8kHz | |
Vbattery vcc gnd DC {Vmax} | |
* Light goes to a photo diode | |
Hlight optin gnd Vled {Rfb} | |
Xphoto optin gnd pcath gnd BPW34 | |
* Converting the photo diode's current into voltage | |
Cprobe pcath vfb {K / (2 * 3.14 * Fu * Rprobe)} | |
Rprobe pcath vfb {Rprobe} | |
Xopamp gnd pcath vcc gnd vfb OA1NP | |
* Error amplifier to get the target voltage | |
R1 vfb r1 {(Vtarget - Vcutin) / Iloss} | |
R2 gnd r1 {Vcutin / Iloss} | |
Vb r1 nb1 DC 0V | |
Q1 r3 nb1 gnd 2N2222A | |
R3 vcc r3 {Vcutin / Iloss} | |
Q2 vdc r3 vcc 2N2907A | |
* LT1932 setup according to its datasheet | |
Radj vdc rset {K * (Vmax - Vrsetdc) / (Iledmax - Iledmin)} | |
Rset gnd rset {K * Vrsetdc / Iledmax} | |
Xdrv rset vcc vcc vcc led LT1932 | |
* LED with an ammeter | |
Dled vcc lcath LS_L296_typ_T | |
Vled lcath led DC 0V | |
.LIB library.sp myOA1NP | |
.LIB library.sp myLT1932 | |
.LIB library.sp 2N2222A | |
.LIB library.sp 2N2907A | |
.LIB library.sp LS_L296 | |
.LIB library.sp BPW34 | |
.END |
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
.LIB myOA1NP | |
.SUBCKT OA1NP in+ in- v+ v- out | |
.PARAM Gain = 1e6 | |
.PARAM Fu = 8kHz | |
.PARAM Rp = 1Meg | |
Egain amp gnd in+ in- {Gain} | |
Rp amp p {Rp} | |
Cp p gnd {Gain / (2 * 3.14 * Fu * Rp)} | |
Bbuf out gnd V = min(max(V(p), V(v-)), V(v+)) | |
.ENDS OA1NP | |
.ENDL myOA1NP | |
.LIB myLT1932 | |
.SUBCKT LT1932 rset en vin sw led | |
.PARAM Vrsetdc = 100mV | |
.PARAM K = 225 | |
Vrsetdc vrsetdc gnd DC {Vrsetdc} | |
Vrset vrsetdc rset DC 0V | |
Fled led gnd Vrset {K} | |
.ENDS LT1932 | |
.ENDL myLT1932 | |
.LIB 2N2222A | |
.MODEL 2n2222a npn | |
+IS=3.88184e-14 BF=929.846 NF=1.10496 VAF=16.5003 | |
+IKF=0.019539 ISE=1.0168e-11 NE=1.94752 BR=48.4545 | |
+NR=1.07004 VAR=40.538 IKR=0.19539 ISC=1.0168e-11 | |
+NC=4 RB=0.1 IRB=0.1 RBM=0.1 | |
+RE=0.0001 RC=0.426673 XTB=0.1 XTI=1 | |
+EG=1.05 CJE=2.23677e-11 VJE=0.582701 MJE=0.63466 | |
+TF=4.06711e-10 XTF=3.92912 VTF=17712.6 ITF=0.4334 | |
+CJC=2.23943e-11 VJC=0.576146 MJC=0.632796 XCJC=1 | |
+FC=0.170253 CJS=0 VJS=0.75 MJS=0.5 | |
+TR=1e-07 PTF=0 KF=0 AF=1 | |
.ENDL 2N2907A | |
.LIB 2N2907A | |
.MODEL 2n2907a pnp | |
+IS=3.02341e-12 BF=523.064 NF=1.16335 VAF=44.2994 | |
+IKF=0.591421 ISE=3.31443e-11 NE=1.9954 BR=4.8572 | |
+NR=1.18959 VAR=1.33092 IKR=5.91421 ISC=3.31443e-11 | |
+NC=3.81262 RB=2.76209 IRB=0.1 RBM=0.880912 | |
+RE=0.0001 RC=0.857407 XTB=0.119647 XTI=1 | |
+EG=1.05 CJE=3.934e-11 VJE=0.680693 MJE=0.379312 | |
+TF=2.75919e-10 XTF=0.674951 VTF=54426.6 ITF=0.067962 | |
+CJC=2.40198e-11 VJC=0.4 MJC=0.462796 XCJC=1 | |
+FC=0.570446 CJS=0 VJS=0.75 MJS=0.5 | |
+TR=1e-07 PTF=0 KF=0 AF=1 | |
.ENDL 2N2907A | |
.LIB BPW34 | |
.subckt BPW34 Opt_In+ Opt_In- Cath Ano | |
+params: SENS=100 resp=50e-5 lens=1 | |
G001 2 Ano Opt_In+ Opt_In- {SENS*resp*lens} | |
D1 Ano 2 F301 | |
Rs 2 Cath 6.5 | |
.model F301 D(IS=3.5e-11 N=1.01 IKF=6e-5 Cjo=73.01p M=0.452 Vj=0.304 BV=200) | |
.ends | |
.ENDL BPW34 | |
.LIB LS_L296 | |
.MODEL LS_L296_max_T D | |
+ IS=15.578E-24 | |
+ N=1.6879 | |
+ RS=8.9062 | |
+ EG=2.6500 | |
+ XTI=3 | |
+ CJO=1.0000E-12 | |
.MODEL LS_L296_typ_T D | |
+ IS=191.46E-24 | |
+ N=1.6112 | |
+ RS=3.9559 | |
+ EG=2.4500 | |
+ XTI=3 | |
+ CJO=1.0000E-12 | |
.MODEL LS_L296_min_T D | |
+ IS=6.8935E-21 | |
+ N=1.6235 | |
+ RS=.74794 | |
+ EG=2.3100 | |
+ XTI=3 | |
+ CJO=1.0000E-12 | |
.ENDL LS_L296 |
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
SRC = circuit.sp library.sp | |
all: output.txt | |
less output.txt | |
sim output.txt: $(SRC) | |
ngspice <circuit.sp >temp.txt | |
mv temp.txt output.txt | |
clean: | |
-rm -f temp.txt output.txt |
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
! Get rid of LT1932 | |
~ Print interesting measurements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment