forked from labtroll/KiCad-Simulations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTian_subckt.lib
54 lines (45 loc) · 1.87 KB
/
Tian_subckt.lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
* **** Tian Probe ***********
* provided by Robert Turnbull (see https://sourceforge.net/p/ngspice/feature-requests/34/?limit=25#49dd )
* Modified by H. Vogt, Jan 2022
* Three clause BSD license
* For KiCad users: Add the Tianprobe2 to the circuit, cutting in the feedback loop.
* Copy the file
* The loopgainprobe subcircuit needs to be named X999 (numeric node name chosen for compatibility with KiCad)
* The probe subcircuit is inserted as follows, the a_node/b_node (input/output) order is unimportant
* X999 a_node b_node loopgainprobe
* The loopgainprobe can be disabled by setting both i.X999.Ii and v.X999.Vi to zero
* tian_loop.lib was translated from Frank Wiedmann's LTspice LoopGainProbe.asc into the ngspice dialect
* For more information see: https://sites.google.com/site/frankwiedmann/loopgain
* and http://education.ingenazure.com/ac-stability-analysis-ngspice/
* Original literature:
* Michael Tian, V. Visvanathan, Jeffrey Hantgan, and Kenneth Kundert,
* "Striving for Small-Signal Stability", IEEE Circuits and Devices Magazine,
* vol. 17, no. 1, pp. 31-41, January 2001.
.subckt loopgainprobe a b
Ii 0 x DC 0 AC 0
Vi x a DC 0 AC 1
Vnodebuffer b x 0
.ends loopgainprobe
.func tian_loop() {1/(1-1/(2*(ac1.I(v.X999.Vi)*ac2.V(X999.x)-ac1.V(X999.x)*ac2.I(v.X999.Vi))+ac1.V(X999.x)+ac2.I(v.X999.Vi)))}
* The following .control section performs the loop analysis and plots the results in standard ngspice
.control
pre_set noinit
set controlswait
if $?sharedmode
version -s
rusage time
else
ac dec 100 0.01 1000Meg
alter i.X999.ii acmag=1
alter v.X999.vi acmag=0
ac dec 100 0.01 1000Meg
let tian_signal = tian_loop()
set xbrushwidth=2
plot db(tian_signal)
let dbsignal = db(tian_signal)
meas ac zerogainfreq WHEN dbsignal=0
plot 180*cph(tian_signal)/pi
let tphase = 180*cph(tian_signal)/pi
meas ac phaseatzerogain FIND tphase AT=zerogainfreq
end
.endc