summaryrefslogtreecommitdiffstats
path: root/scilab/modules/scicos_blocks
diff options
context:
space:
mode:
authorAllan CORNET <allan.cornet@scilab.org>2010-01-12 12:12:46 +0100
committerAllan CORNET <allan.cornet@scilab.org>2010-01-12 12:12:46 +0100
commit31ab0c1c2f2da9fc4ea1cf9366e9049224ae0619 (patch)
treeebf602f725f270dba4c7b91bd07fec0d77052e8e /scilab/modules/scicos_blocks
parent79d05d4634741f3966db766381af5157c603a98d (diff)
downloadscilab-31ab0c1c2f2da9fc4ea1cf9366e9049224ae0619.zip
scilab-31ab0c1c2f2da9fc4ea1cf9366e9049224ae0619.tar.gz
add initial merged version of Electrical.mo
Diffstat (limited to 'scilab/modules/scicos_blocks')
-rw-r--r--scilab/modules/scicos_blocks/macros/Electrical/Electrical.mo525
1 files changed, 525 insertions, 0 deletions
diff --git a/scilab/modules/scicos_blocks/macros/Electrical/Electrical.mo b/scilab/modules/scicos_blocks/macros/Electrical/Electrical.mo
new file mode 100644
index 0000000..cb60402
--- /dev/null
+++ b/scilab/modules/scicos_blocks/macros/Electrical/Electrical.mo
@@ -0,0 +1,525 @@
1model OutPort
2 output Real v;
3end OutPort;
4
5model OutPutPort
6 output Real vo;
7 Real vi;
8 equation
9 vi = vo;
10end OutPutPort;
11
12model InPutPort
13 Real vo;
14 input Real vi;
15 equation
16 vi=vo;
17end InPutPort;
18
19connector Pin
20 Real v;
21 flow Real i;
22end Pin;
23
24
25partial model TwoPin
26 Pin p, n;
27 Real i, v;
28equation
29 i = p.i;
30 n.i = -i;
31 v = p.v - n.v;
32end TwoPin;
33
34//---------------------------------------
35model Ground "Ground"
36 Pin p;
37equation
38 p.v = 0.0;
39end Ground;
40
41
42model Resistor
43 extends TwoPin;
44 parameter Real R =1 "Resistance";
45
46equation
47 R*i = v;
48end Resistor;
49
50model VariableResistor
51 extends TwoPin;
52 Real R "Resistance";
53equation
54 R*i = v ;
55end VariableResistor;
56
57model Capacitor
58 extends TwoPin;
59 parameter Real C(fixed=true)=1e-5 "Capacitance";
60 equation
61 C * der(v) = i;
62end Capacitor;
63
64model Inductor "Ideal electrical inductor"
65 parameter Real L=1e-6 "Inductance";
66 extends TwoPin;
67equation
68 L * der(i) = v;
69end Inductor;
70
71model ConstantVoltage "Source for constant voltage"
72 extends TwoPin;
73 parameter Real V (fixed=true)=1 "Volts";
74equation
75 V = v;
76end ConstantVoltage;
77
78
79model VsourceAC "Sin-wave voltage source"
80 extends TwoPin;
81 parameter Real VA = 220 "Amplitude";
82 parameter Real f = 50 "Frequency";
83 parameter Real PI=3.141592653589793;
84equation
85 v = VA* sin(2*PI*f*time);
86end VsourceAC;
87
88
89model VVsourceAC "Sin-wave voltage source"
90 extends TwoPin;
91 Real VA "voltage";
92 parameter Real f = 50 "Frequency";
93 parameter Real PI=3.141592653589793;
94equation
95 v = VA*sin(2*PI*f*time);
96end VVsourceAC;
97
98model SineVoltage "Sine voltage source"
99 extends TwoPin;
100 parameter Real V=1 "Amplitude of sine wave";
101 parameter Real phase=0 "Phase of sine wave";
102 parameter Real freqHz=1 "Frequency of sine wave";
103 parameter Real offset=0 "Offset volatge of sine wave";
104 parameter Real startTime=0 "sine wave start time";
105 parameter Real PI=3.141592653589793;
106equation
107 v = offset + (if time < startTime then 0 else V*sin(2*PI*freqHz*(time - startTime) +phase));
108end SineVoltage;
109
110model CCS "controlled voltage source"
111 extends TwoPin;
112 Real Iin;
113equation
114 Iin = i;
115end CCS;
116
117
118
119model CVS "controlled voltage source"
120 extends TwoPin;
121 Real vin;
122equation
123 vin = v;
124end CVS;
125
126model VoltageSensor
127 extends TwoPin;
128 equation
129 i = 0;
130 end VoltageSensor;
131
132model CurrentSensor
133 extends TwoPin;
134 equation
135 v = 0;
136 end CurrentSensor;
137
138model PotentialSensor
139 Pin p;
140 Real v;
141 equation
142 p.i = 0;
143 v = p.v;
144 end PotentialSensor;
145
146model Switch
147 parameter Real Ron=0.01 "Resistance when the Switch is closed";
148 parameter Real Roff=1e5 "Resistance when the switch is open";
149 extends TwoPin;
150 Real inp,Rx;
151equation
152 Rx*i= v;
153 Rx=if inp >0 then Ron
154 else Roff;
155end Switch;
156
157model Interrupter1
158 extends TwoPin;
159 Real R;
160 parameter Real RMAX=1e6;
161 Real K;
162 equation
163 R = if K > 0. then 1. / RMAX else RMAX;
164 R * i = v;
165 end Interrupter1;
166
167 model PowerSource
168 extends TwoPin(v(start=v0), i(start=i0));
169 parameter Real P, v0, i0;
170 equation
171 v * i = P;
172 end PowerSource;
173
174
175model Diode "Simple diode"
176 extends TwoPin;
177 parameter Real Ids=1.e-6 "Saturation current";
178 parameter Real Vt=0.04 "Voltage equivalent of temperature (kT/qn)";
179 parameter Real Maxexp=15 "Max. exponent for linear continuation";
180 parameter Real R=1.e8 "Parallel ohmic resistance";
181 equation
182
183 i = if noEvent(v/Vt > Maxexp) then
184 Ids*(exp(Maxexp)*(1 + v/Vt - Maxexp) - 1) + v/R
185 else
186 Ids*(exp(v/Vt) - 1) + v/R;
187 end Diode;
188
189
190
191
192model Gyrator "Gyrator"
193 parameter Real G1=1 "Gyration conductance";
194 parameter Real G2=1 "Gyration conductance";
195
196 Pin p1,n1,p2,n2;
197 Real v2,v1,i1,i2;
198
199equation
200
201 v1=p1.v-n1.v;
202 0=p1.i+n1.i;
203 i1=p1.i;
204
205 v2=p2.v-n2.v;
206 0=p2.i+n2.i;
207 i2=p2.i;
208
209 i1 = G2*v2;
210 i2 = -G1*v1;
211
212end Gyrator;
213
214model IdealTransformer "Transformer with two ports"
215 parameter Real N=1 "Transformer turn ration N1/N2";
216 Pin p1, n1, p2, n2;
217 Real v2,v1,i1,i2;
218
219equation
220 v1=p1.v-n1.v;
221 0=p1.i+n1.i;
222 i1=p1.i;
223
224 v2=p2.v-n2.v;
225 0=p2.i+n2.i;
226 i2=p2.i;
227
228/* v1 = L1*der(i1) + M*der(i2);
229 v2 = M*der(i1) + L2*der(i2);
230 Results very often in high index
231 problem not handled in Scicos /Masoud
232*/
233
234v1=N*v2;
235i2=-N*i1;
236
237end IdealTransformer;
238
239model NMOS "Simple MOS Transistor"
240 parameter Real W=20.e-6 "Width";
241 parameter Real L=6.e-6 "Length";
242 parameter Real Beta=0.041e-3 "Transconductance parameter";
243 parameter Real Vt=0.8 "Zero bias threshold voltage";
244 parameter Real K2=1.144 "Bulk threshold parameter";
245 parameter Real K5= 0.7311"Reduction of pinch-off region";
246 parameter Real dW=-2.5e-6 "narrowing of channel";
247 parameter Real dL= -1.5e-6"shortening of channel";
248 parameter Real RDS=1.e+7 "Drain-Source-Resistance";
249
250 Pin D "Drain";
251 Pin G "Gate";
252 Pin S "Source";
253 Pin B "Bulk";
254
255 Real v;
256 Real uds;
257 Real ubs;
258 Real ugst;
259 Real ud;
260 Real us;
261 Real id,gds;
262equation
263 //assert (L + dL > 0, "Effective length must be positive");
264 //assert (W + dW > 0, "Effective width must be positive");
265
266 gds = if noEvent(RDS < 1.e-20 and RDS > -1.e-20) then 1.e20 else 1/RDS;
267 v = Beta*(W + dW)/(L + dL);
268 ud = if noEvent(D.v < S.v) then S.v else D.v;
269 us = if noEvent(D.v < S.v) then D.v else S.v;
270 uds = ud - us;
271 ubs = if noEvent(B.v > us) then 0 else B.v - us;
272 ugst = (G.v - us - Vt + K2*ubs)*K5;
273 id = if noEvent(ugst <= 0) then uds*gds else if noEvent(ugst > uds) then v*uds*(ugst
274 - uds/2) + uds*gds else v*ugst*ugst/2 + uds*gds;
275 G.i = 0;
276 D.i = if noEvent(D.v < S.v) then -id else id;
277 S.i = -D.i;
278 B.i = 0;
279end NMOS;
280
281
282model NPN "Simple BJT according to Ebers-Moll"
283 parameter Real Bf=50 "Forward beta";
284 parameter Real Br=0.1 "Reverse beta";
285 parameter Real Is=1.e-16 "Transport saturation current";
286 parameter Real Vak=0.02 "Early voltage (inverse), 1/Volt";
287 parameter Real Tauf=0.12e-9 "Ideal forward transit time";
288 parameter Real Taur=5e-9 "Ideal reverse transit time";
289 parameter Real Ccs=1e-12 "Collector-substrat(ground) cap.";
290 parameter Real Cje=0.4e-12 "Base-emitter zero bias depletion cap.";
291 parameter Real Cjc=0.5e-12 "Base-coll. zero bias depletion cap.";
292 parameter Real Phie=0.8 "Base-emitter diffusion voltage";
293 parameter Real Me=0.4 "Base-emitter gradation exponent";
294 parameter Real Phic=0.8 "Base-collector diffusion voltage";
295 parameter Real Mc=0.333 "Base-collector gradation exponent";
296 parameter Real Gbc=1e-15 "Base-collector conductance";
297 parameter Real Gbe=1e-15 "Base-emitter conductance";
298 parameter Real Vt=0.02585 "Voltage equivalent of temperature";
299 parameter Real EMinMax=40 "if x > EMax, the exp(x) function is linearized";
300 Real vbc;
301 Real vbe;
302 Real qbk;
303 Real ibc;
304 Real ibe;
305 Real cbc;
306 Real cbe;
307 Real ExMin;
308 Real ExMax;
309 Real Capcje;
310 Real Capcjc;
311 Real EMax;
312 Real EMin;
313
314 Pin C "Collector";
315 Pin B "Base";
316 Pin E "Emitter";
317equation
318 EMax=EMinMax;
319 EMin=-2*EMinMax;
320 ExMin = exp(EMin);
321 ExMax = exp(EMax);
322 vbc = B.v - C.v;
323 vbe = B.v - E.v;
324 qbk = 1 - vbc*Vak;
325
326 ibc = if noEvent(vbc/Vt < EMin) then Is*(ExMin*(vbc/Vt - EMin + 1) - 1) + vbc*Gbc
327 else if noEvent(vbc/Vt > EMax) then Is*(ExMax*(vbc/Vt - EMax + 1) - 1) + vbc*Gbc
328 else Is*(exp(vbc/Vt) - 1) + vbc*Gbc;
329
330 ibe = if noEvent(vbe/Vt < EMin) then Is*(ExMin*(vbe/Vt - EMin + 1) - 1) + vbe*Gbe
331 else if noEvent(vbe/Vt > EMax) then Is*(ExMax*(vbe/Vt - EMax + 1) - 1) + vbe*Gbe
332 else Is*(exp(vbe/Vt) - 1) + vbe*Gbe;
333
334 Capcjc = if (vbc/Phic > 0) then Cjc*(1 + Mc*vbc/Phic) else Cjc*(1 - vbc/Phic)^(-Mc);
335 Capcje = if (vbe/Phie > 0) then Cje*(1 + Me*vbe/Phie) else Cje*(1 - vbe/Phie)^(-Me);
336
337 cbc = if noEvent(vbc/Vt < EMin) then Taur*Is/Vt*ExMin*(vbc/Vt - EMin + 1) + Capcjc
338 else if noEvent(vbc/Vt > EMax) then Taur*Is/Vt*ExMax*(vbc/Vt - EMax + 1) + Capcjc
339 else Taur*Is/Vt*exp(vbc/Vt) + Capcjc;
340
341 cbe = if noEvent(vbe/Vt < EMin) then Tauf*Is/Vt*ExMin*(vbe/Vt - EMin + 1) + Capcje
342 else if noEvent(vbe/Vt > EMax) then Tauf*Is/Vt*ExMax*(vbe/Vt - EMax + 1) + Capcje
343 else Tauf*Is/Vt*exp(vbe/Vt) + Capcje;
344
345 C.i = (ibe - ibc)*qbk - ibc/Br - cbc*der(vbc) + Ccs*der(C.v);
346 B.i = ibe/Bf + ibc/Br + cbc*der(vbc) + cbe*der(vbe);
347 E.i = -B.i - C.i + Ccs*der(C.v);
348end NPN;
349
350model OpAmp
351// parameter Real OLGain=1000 "Open Loop gain";
352// parameter Real SatH=10 "Positive saturation voltage";
353// parameter Real SatL=-10 "Negative Saturation voltage";
354 Pin in_p "Positive pin of the input port";
355 Pin in_n "Negative pin of the input port";
356 Pin out "Output pin";
357equation
358 in_p.i = 0;
359 in_n.i = 0;
360 in_p.v - in_n.v=0;
361end OpAmp;
362
363
364model PMOS "Simple MOS Transistor"
365 parameter Real W=50.0e-6 "Width";
366 parameter Real L=6.0e-6 "Length";
367 parameter Real Beta=0.0105e-3 "Transconductance parameter";
368 parameter Real Vt=-1 "Zero bias threshold voltage";
369 parameter Real K2=0.41 "Bulk threshold parameter";
370 parameter Real K5=0.839 "Reduction of pinch-off region";
371 parameter Real dW=-2.5e-6 "Narrowing of channel";
372 parameter Real dL=-2.1e-6 "Shortening of channel";
373 parameter Real RDS=1.e+7 "Drain-Source-Resistance";
374
375 Pin D "Drain";
376 Pin G "Gate";
377 Pin S "Source";
378 Pin B "Bulk";
379
380 Real v;
381 Real uds;
382 Real ubs;
383 Real ugst;
384 Real ud;
385 Real us;
386 Real id,gds;
387equation
388 gds = 1/RDS;//if (RDS < 1.e-20 and RDS > -1.e-20) then 1.e20 else 1/RDS;
389 v = Beta*(W + dW)/(L + dL);
390 ud = if noEvent(D.v > S.v) then S.v else D.v;
391 us = if noEvent(D.v > S.v) then D.v else S.v;
392 uds = ud - us;
393 ubs = if noEvent(B.v < us) then 0 else B.v - us;
394 ugst = (G.v - us - Vt + K2*ubs)*K5;
395 id = if noEvent(ugst >= 0) then uds*gds else if noEvent(ugst < uds) then -v*uds*(
396 ugst - uds/2) + uds*gds else -v*ugst*ugst/2 + uds*gds;
397 G.i = 0;
398 D.i = if noEvent(D.v > S.v) then -id else id;
399 S.i = -D.i;
400 B.i = 0;
401end PMOS;
402
403model PNP "Simple BJT according to Ebers-Moll"
404 parameter Real Bf=50 "Forward beta";
405 parameter Real Br=0.1 "Reverse beta";
406 parameter Real Is=1.e-16 "Transport saturation current";
407 parameter Real Vak=0.02 "Early voltage (inverse), 1/Volt";
408 parameter Real Tauf=0.12e-9 "Ideal forward transit time";
409 parameter Real Taur=5e-9 "Ideal reverse transit time";
410 parameter Real Ccs=1e-12 "Collector-substrat(ground) cap.";
411 parameter Real Cje=0.4e-12 "Base-emitter zero bias depletion cap.";
412 parameter Real Cjc=0.5e-12 "Base-coll. zero bias depletion cap.";
413 parameter Real Phie=0.8 "Base-emitter diffusion voltage";
414 parameter Real Me=0.4 "Base-emitter gradation exponent";
415 parameter Real Phic=0.8 "Base-collector diffusion voltage";
416 parameter Real Mc=0.333 "Base-collector gradation exponent";
417 parameter Real Gbc=1e-15 "Base-collector conductance";
418 parameter Real Gbe=1e-15 "Base-emitter conductance";
419 parameter Real Vt=0.02585 "Voltage equivalent of temperature";
420 parameter Real EMinMax=40 "if x < EMin, the exp(x) function is linearized";
421 Real vbc;
422 Real vbe;
423 Real qbk;
424 Real ibc;
425 Real ibe;
426 Real cbc;
427 Real cbe;
428 Real ExMin;
429 Real ExMax;
430 Real Capcje;
431 Real Capcjc;
432 Real EMax;
433 Real EMin;
434
435 Pin C "Collector";
436 Pin B "Base";
437 Pin E "Emitter";
438equation
439 EMax=EMinMax;
440 EMin=-2*EMinMax;
441 ExMin = exp(EMin);
442 ExMax = exp(EMax);
443 vbc = C.v - B.v;
444 vbe = E.v - B.v;
445 qbk = 1 - vbc*Vak;
446
447 ibc = if noEvent(vbc/Vt < EMin) then Is*(ExMin*(vbc/Vt - EMin + 1) - 1) + vbc*
448 Gbc else if noEvent(vbc/Vt > EMax) then Is*(ExMax*(vbc/Vt - EMax + 1) - 1) +
449 vbc*Gbc else Is*(exp(vbc/Vt) - 1) + vbc*Gbc;
450
451 ibe = if noEvent(vbe/Vt < EMin) then Is*(ExMin*(vbe/Vt - EMin + 1) - 1) + vbe*
452 Gbe else if noEvent(vbe/Vt > EMax) then Is*(ExMax*(vbe/Vt - EMax + 1) - 1) +
453 vbe*Gbe else Is*(exp(vbe/Vt) - 1) + vbe*Gbe;
454
455 Capcjc = if (vbc/Phic > 0) then Cjc*(1 + Mc*vbc/Phic) else Cjc*(1 - vbc/Phic)^(-Mc);
456 Capcje = if (vbe/Phie > 0) then Cje*(1 + Me*vbe/Phie) else Cje*(1 - vbe/Phie)^(-Me);
457
458 cbc = if noEvent(vbc/Vt < EMin) then Taur*Is/Vt*ExMin*(vbc/Vt - EMin + 1) +
459 Capcjc else if noEvent(vbc/Vt > EMax) then Taur*Is/Vt*ExMax*(vbc/Vt - EMax + 1)
460 + Capcjc else Taur*Is/Vt*exp(vbc/Vt) + Capcjc;
461 cbe = if noEvent(vbe/Vt < EMin) then Tauf*Is/Vt*ExMin*(vbe/Vt - EMin + 1) +
462 Capcje else if noEvent(vbe/Vt > EMax) then Tauf*Is/Vt*ExMax*(vbe/Vt - EMax + 1)
463 + Capcje else Tauf*Is/Vt*exp(vbe/Vt) + Capcje;
464
465 C.i = -((ibe - ibc)*qbk - ibc/Br - cbc*der(vbc) + Ccs*der(C.v));
466 B.i = -(ibe/Bf + ibc/Br + cbe*der(vbe) + cbc*der(vbc));
467 E.i = -B.i - C.i - Ccs*der(C.v);
468end PNP;
469
470
471
472
473
474//==================================================
475model Resistorx
476 Pin p, n;
477 parameter Real R (fixed=false)=1 "Re{si}s >< ance";
478 //parameter Integer n = 3;
479 // Real Z[3] (start={ 1.0 for i in 1 : 3 });
480 parameter Real Rx[3] (fixed = {false, false, true})={1,3,40000} "Resistance";
481 Real Z[3](fixed = {false, true, false},start={222,333,444}) "Resistance";
482 parameter Real Ry[3] (fixed = {false, false, true})={1,3,40000} "Resistance";
483 Real T (start=3.4) "fff ggg hhh";
484 /*Real c[2](start={22,33}) "ifffffffff";*/
485 Real mytr (start=3.56,fixed=true);
486 Real mytr2 (start=3.56,fixed=false);
487
488 Resistor Rx[10](R={ i*2.3 for i in 1 : 10 });
489equation
490
491for k in 1: 10 loop
492 Rx[k].n.v=0;
493 Rx[k].p.v=0;
494end for ;
495
496
497 mytr=2.3;
498 mytr2=2.3;
499 T=R;
500 Z[1]=3; Z[2]=0; Z[3]=Rx[3];
501
502 Rx[1]*p.i = p.v - n.v;
503 p.i = -n.i;
504
505/*
506if time < 0.5 then
507 c = {1,0};
508 elseif time < 7 then
509 c[1] = 5;
510 c[2] = 9;
511 elseif time < 8 then
512 c = {5,8};
513 else
514 c[1] = 2;
515 c[2] = 4;
516 end if;
517
518*/
519
520
521end Resistorx;
522
523/* parameter Integer n = 400;
524 Real x[n](start={ 1.0 for i in 1 : n });*/
525