Debian Codegraph @

texmf-dist/doc/latex/circuit-macros/examples/extras/ShowcaseExample.m4

raw
1 .PS
2 # `ShowcaseExample.m4'
3 # https://tex.stackexchange.com/questions/758824/showcase-of-beautiful-electrical-circuit-diagrams-done-in-tex-friends
4 # https://www.mdpi.com/2079-9292/10/21/2631
5
6 log_init
7 define(`sub',`_{\hbox{\scriptsize `$1'}}')
8 pushdef(`lg_plen',0)
9
10 del = 4*L_unit
11 TopRow: [
12 setdir_(R)
13 M1: Mux(5,\normalsize AD8429,X,dimen_*4*3/5,dimen_*4)
14 "$+$" at M1.In0 ljust; "$-$" at M1.In4 ljust;
15 line from M1.In1 left_ del
16 resistor(down_ M1.In1.y-M1.In3.y)
17 rlabel(,\shortstack[r]{$R_{\hbox{\scriptsize G}}$\\\SI{131}{\ohm}})
18 line to M1.In3
19 dot(at M1.Out+(del*3/2,0))
20 {line from M1.Out to 2 between M1.Out and Here
21 dot(,,1); "$V`'sub(out)$" at last [].e ljust}
22 line up_ del; tbox(r_text(90,$V`'sub(out)$))
23 Vref: "$V`'sub(ref)$" above rjust at 2/3 between M1.SW and M1.SE;
24 right_
25 OA3: opamp(,,,dimen_*5/4) with .w at (M1.w.x,M1.SW.y-2.25*del)
26 "OA3" at OA3.C
27 line from OA3.Out to (Vref,OA3) then to Vref
28 line from OA3.In1 left_ del then up del*9/8; continue to (Vref,Here); dot
29 arrow from OA3.In2 left_ del then down_ del*3/2
30 Rz: resistor(right_ dimen_ at Here)
31 rlabel(,\shortstack{$R`'sub(z)$\\\SI{10}{\kilo\ohm}})
32 {resistor(right_ dimen_*3/4 from Rz.end)
33 arrow right_ del; "\SI{5}{\volt}" ljust}
34 {resistor(left_ dimen_*3/4 from Rz.start)
35 arrow left_ del; "\SI{-5}{\volt}" rjust}
36
37 define(`rstring',`[
38 ground(,T)
39 Vin: source(up_ (M1.In0.y-M1.In4.y)/2,V)
40 llabel(,V^`'ifelse(`$1',1,+,-)sub(in)); {move left_ 17bp__ from last [].w}
41 resistor(right_ elen_); llabel(,\SI{10}{\kilo\ohm}); dot
42 { resistor(down_ Vin.len); rlabel(,\SI{100}{\ohm}); ground(,T) }
43 Rp: resistor(right_ elen_); rlabel(,R^ifelse(`$1',1,+,-))
44 llabel(,\shortstack{\SI{0}{\ohm}\\\SI{5}{\kilo\ohm}\\\SI{50}{\kilo\ohm}})
45 {dot; resistor(down_ Vin.len/2)
46 llabel(,\shortstack[l]{$R`'sub(A`$1')$\\\SI{5}{\kilo\ohm}})
47 switch(down_ Vin.len/2,O)
48 llabel(,\shortstack[l]{\small
49 v`'ifelse(`$1',1,`+\scriptsize R\\3',`-\scriptsize R\\2')})
50 G1: ground(,T)}
51 line right_ dimen_; dot
52 {line down_ Vin.len/2
53 switch(down_ Vin.len/2,O)
54 llabel(,\shortstack[l]{\small
55 v`'ifelse(`$1',1,`+\scriptsize GND\\4',`-\scriptsize GND\\1')})
56 G2: ground(,T)}
57 line right_ dimen_*2/3
58 C`$1'B: dot; {"C`$1'B" at last [].nw rjust above}
59 capacitor(right_ elen_); llabel(,\SI{10}{\micro\farad})
60 rlabel(,C`'sub(B`$1'))
61 C`$1'A: dot; {"C`$1'A" at last [].ne ljust above}
62 ifelse(`$1',1,`{line dashed 0.04 up_ dimen_*0.8 then left_ elen_ then to C1B
63 circle fill_(1) dashed 0.04 rad sourcerad_ at C1B+(elen_/2,dimen_*0.8)
64 arrow dashed 0.04 left_ sourcerad_*3/2 at last circle
65 "$i`'sub(f`$1')$" at last circle.n above}',
66 `{line dashed 0.04 down_ dimen_*0.8 then left_ elen_ then to C2B
67 circle fill_(1) dashed 0.04 rad sourcerad_ at C2B+(elen_/2,-dimen_*0.8)
68 arrow dashed 0.04 left_ sourcerad_*3/2 at last circle
69 "$i`'sub(f`$1')$" at last circle.s below}')
70 {ifelse(`$1',1,`resistor(from C1A down_ (M1.In0.y-M1.In4.y)/2)
71 llabel(,\shortstack[l]{$R`'sub(B1)$\\\SI{160}{\kilo\ohm}})
72 dot; line left del; ground',
73 `resistor(from C2A up_ (M1.In0.y-M1.In4.y)/2)
74 rlabel(,\shortstack[l]{$R`'sub(B2)$\\\SI{160}{\kilo\ohm}})')}
75 line right_ del; resistor(right elen_); llabel(,\SI{100}{\ohm})
76 D: dot
77 R33: resistor right_(elen_); llabel(,\SI{33}{\ohm})
78 ]')
79
80 S1: rstring(1) with .R33.end at M1.In0
81 S2: rstring(2) with .R33.end at M1.In4
82 capacitor(down_ from S1.D to S2.D)
83 rlabel(,\shortstack{$C`'sub(hf)$\\\SI{1}{\nano\farad}})
84 "Switches:" at 1/2 <S2.G1,S2.G2>+(0,-del*7/4) below "1$\times$ADG202AKN"
85 ]
86
87 SecondRow: [
88 ADN: [
89 C: circle rad sourcerad_; line from C.sw to C.ne; line from C.nw to C.se
90 line right_ C.rad*2 from C.e
91 MR: Mux(,,X,sourcerad_*2,sourcerad_*6)
92 line left_ C.rad up_ C.rad*3/4 from C+(Rect_(C.rad,150)) \
93 then up_ C.rad*3/4; down_
94 MT: Mux(,,X,sourcerad_*2,sourcerad_*6,,X1:8/7 between In0 and In1;\
95 X0: 8/7 between In1 and In0) with .Out at Here
96 "\small $-$" at MT.X0 below; "+" at MT.X1 below
97 line left_ C.rad down_ C.rad*3/4 from C+(Rect_(C.rad,210)) \
98 then down_ C.rad*3/4; up_
99 MB: Mux(,,X,sourcerad_*2,sourcerad_*6,,X1:8/7 between In0 and In1;\
100 X0:8/7 between In1 and In0) with .Out at Here
101 "\small $-$" at MB.X1 above; "+" at MB.X0 above
102 dx = MB.X1.x-MB.X0.x
103 Bx: [ B: box wid dx*4 ht dx*3 at C+(dx/2,0)
104 for i=1 to 4 do {
105 exec sprintf("Pin%g: (i-1/2)/4 <B.sw,B.se>; \"%g\" at Pin%g above rjust;
106 Pin%g: (i-1/2)/4 <B.ne,B.nw>; \"%g\" at Pin%g below rjust;",i,i,i,\
107 4+i,4+i,4+i) } ] with .Pin8 at MT.X1+(0,dx/2)
108 line from MR.Out to (Bx.Pin5,MR.Out) then to Bx.Pin5
109 Vr: 1/2 between MR.SW and MR.SE
110 line from Vr down_ sourcerad_; continue to (Bx.Pin4,Here) then to Bx.Pin4
111 ]
112 "ADN835ANZ" at ADN.w rjust
113 hdn = ADN.ht/(dimen_); dx = ADN.MB.X1.x-ADN.MB.X0.x
114 line from ADN.MT.X1 up del+ADN.n.y-ADN.MT.n.y then left del/2
115 resistor(left_ dimen_); rlabel(,\SI{100}{\ohm}); right_
116 OA4: opamp(,,,dimen_*5/4) with .Out at Here; "OA4" at OA4.C
117 line from OA4.In1 left_ del then up del*3/2
118 continue to (OA4.Out,Here) then to OA4.Out; dot
119 line left_ del from OA4.In2; dot
120 {capacitor(down_ elen_); rlabel(,C`'sub(LP)); llabel(,\SI{1}{\micro\farad})
121 ground(,T)}
122 resistor(left_ dimen_); rlabel(,R`'sub(LP)); llabel(,\SI{10}{\kilo\ohm})
123 tbox(V`'sub(ctrl),,,<); right_
124 OA1: opamp(,,,dimen_*5/4) with .Out at (OA4.Out.x,ADN.s.y-(OA4.Out.y-ADN.n.y));
125 "OA1" at OA1.C
126 resistor(right_ dimen_ from OA1.Out); rlabel(,\SI{100}{\ohm})
127 line to (ADN.Bx.Pin1,Here) then to ADN.MB.X0
128 line from OA1.In1 left_ del then up_ del*3/2; dot
129 {resistor(right_ to (OA1.Out,Here))
130 llabel(,R`'sub(g2)); rlabel(,\SI{2}{\kilo\ohm})
131 line to OA1.Out; dot}
132 resistor(left_ dimen_); rlabel(,R`'sub(g1)); llabel(,\SI{1}{\kilo\ohm})
133 tbox(V`'sub(out),,,<)
134 line from OA1.In2 left_ del then down_ del; ground
135 dot(at (ADN.Bx.Pin6,OA4)); {"\SI{3.3}{\micro\farad}" at last [].e ljust}
136 Cp: capacitor(left_ dx,C+); dot
137 dot(at Here+(0,del*3/2)); capacitor(right_ dx); dot
138 {"\SI{10}{\nano\farad}" at last [].e ljust}
139 arrow from ADN.Bx.Pin6 to Here chop 0 chop -del; {"\SI{5}{\volt}" above}
140 line from ADN.MT.X0 up_ Here.y-ADN.MT.X0.y-del/2 \
141 then left_ del then down_ del/2
142 ground(,T)
143 dot(at (ADN.Bx.Pin2.x,ADN.s.y-(Cp.y-ADN.n.y)))
144 capacitor(right_ dx,C+); dot; {"\SI{3.3}{\micro\farad}" at last [].e ljust}
145 dot(at Here-(0,del*3/2)); {"\SI{10}{\nano\farad}" at last [].e ljust}
146 {arrow from ADN.Bx.Pin3 to Here chop 0 chop -del; "\SI{-5}{\volt}" below}
147 capacitor(left_ dx); dot
148 line from ADN.MB.X1 up_ Here.y-ADN.MB.X0.y-del/2; ground
149 T: dot(at ADN.ne+(del,del))
150 {resistor(down_ to ADN.se+(del,-del)); llabel(,\SI{2}{\kilo\ohm})
151 Dp: dot
152 {line to (ADN.Bx.Pin4,Here) then to ADN.Bx.Pin4}
153 resistor(down_ dimen_); rlabel(,\SI{100}{\ohm})
154 G: ground(,T) }
155 line from Here+(del*3,0) to (ADN.Bx.Pin5,Here) then to ADN.Bx.Pin5; right_
156 OA2: opamp(,,,dimen_*5/4,R) with .In1 at last line.start; "OA2" at OA2.C
157
158 define(`VO1263A',`[ dh = dimen_*2/3
159 B1: VO1263DL
160 B2: VO1263DL with .D.start at B1.D.end-(0,dh*2/3)
161 Bx: box ht B1.D.start.y-B2.D.end.y+del wid B1.L.x-B1.D.x+del \
162 at 1/2 between B1.D.start and B2.L.end
163 line from B1.D.end left_ del; continue to (Here,B2.D.start) then to B2.D.start
164 ]')
165 define(`VO1263DL',`[
166 D: diode(down_ dh,LE)
167 L: line invis from D.start+(dimen_*3/4,0) down_ dh
168 pushdef(`dimen_',dimen_*2/3)
169 line from L.start down_ L.len/4; diode(down_ dimen_/8 at Here)
170 line dashed dimen_/20 down_ to 3/4 between L.start and L.end
171 diode(down_ dimen_/8 at Here); line to L.end popdef(`dimen_')
172 ]')
173
174 line from OA2.Out right_ del*3/2
175 VO1: VO1263A with .B1.D.start at Here
176 VO2: VO1263A with .n at VO1.s+(0,-del/2)
177 "VO1263$\times$2" at VO1.Bx.n above
178 S: dot(at (OA2.In2.x-del,(1/2 between VO1.s and VO2.n).y))
179 line from OA2.In2 to (S,OA2.In2) then to S
180 resistor(down_ to (Here,G))
181 llabel(,\shortstack[l]{$R`'sub(L)$\\\SI{100}{\ohm}})
182 ground(,T)
183
184 line from VO1.B2.D.end left_ del then down_ VO1.B2.D.end.y-VO2.B1.D.start.y \
185 then to VO2.B1.D.start
186 line from S to (VO1.B2.D.end.x-del,S.y); dot
187 dot(at OA2.Out); line to (Here,VO2.B2.D.end) then to VO2.B2.D.end
188
189 dot(at VO1.B1.L.end+(del,0))
190 { line to (Here,VO2.B1.L.start) then to VO2.B1.L.start }
191 line right_ from VO1.B1.L.end to Here+(dimen_,0)
192 Rt: Here
193 tbox("C1A")
194 dot(at VO1.B1.L.start+(del*3/2,0))
195 { line to (Here,VO2.B1.L.end) then to VO2.B1.L.end }
196 line right_ from VO1.B1.L.start to (Rt,Here)
197 tbox("C1B")
198 {arrow <- from (Rt.x-del/6,Here.y) left_ dimen_/8
199 "$i`'sub(f1)$" at Here+(0,lthick*2) above}
200 dot(at VO1.B2.L.end+(del*2,0))
201 { line to (Here,VO2.B2.L.start) then to VO2.B2.L.start }
202 line right_ from VO1.B2.L.end to (Rt,Here)
203 tbox("C2B")
204 dot(at VO1.B2.L.start+(del*5/2,0))
205 { line to (Here,VO2.B2.L.end) then to VO2.B2.L.end }
206 line right_ from VO1.B2.L.start to (Rt,Here)
207 tbox("C2A")
208 arrow <- from (Rt.x-del/6,Here.y) left_ dimen_/8
209 "$i`'sub(f2)$" at Here+(0,lthick*2) above
210
211 ] with .nw at TopRow.sw+(0,-dimen_/2)
212 popdef(`lg_plen')
213
214 .PE