-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiode_va_characteristic.ngjs
executable file
·65 lines (63 loc) · 2.12 KB
/
diode_va_characteristic.ngjs
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
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ngspicejs
// Compare VA characteristic, timing and AC of 2 diodes
// linter: ngspicejs-lint
"use strict";
function compare_diodes(aModel1, aModel2) {
// Compare 2 diodes
// V-A characteristic
netlist_clear();
pwl('U1', 1, 0).shape([[0, 0], [0.02, 3]]);
resistor('R1', 1, 2, 330);
var d1 = diode('D1', 2, 0, aModel1);
var t1 = tran().run();
d1.model(aModel2);
var t2 = tran().run();
// log
chart_xy()
.title('V-A characteristic of diodes')
.label_x('Vf/V')
.label_y('If/A')
.log_y(true)
.add_series(t1.data['V(2)'].slice(2), t1.data['I(U1)'].slice(2).scale(-1), aModel1)
.add_series(t2.data['V(2)'].slice(2), t2.data['I(U1)'].slice(2).scale(-1), aModel2)
.show();
// linear
chart_xy()
.height(204)
.title('V-A characteristic of diodes')
.label_x('Vf/V')
.label_y('If/A')
.add_series(t1.data['V(2)'].slice(2), t1.data['I(U1)'].slice(2).scale(-1), aModel1)
.add_series(t2.data['V(2)'].slice(2), t2.data['I(U1)'].slice(2).scale(-1), aModel2)
.show();
// timing
netlist_clear();
square('U1', 1, 0).v(2).f('1M');
resistor('R1', 1, 2, 100);
d1 = diode('D1', 2, 0, aModel1);
t1 = tran().step('5n').interval('5u').run();
d1.model(aModel2);
t2 = tran().step('5n').interval('5u').run();
chart_xy()
.height(204)
.title('Timing at 1MHz')
.add_series(t1.data.time, t1.data['V(2)'], aModel1)
.add_series(t2.data.time, t2.data['V(2)'], aModel2)
.show();
// ac with series inductor
netlist_clear();
sinewave('U1', 1, 0).v(2).f('1M');
resistor('R1', 1, 3, 100);
inductor('L1', 3, 2, '1m');
d1 = diode('D1', 2, 0, aModel1);
var a1 = ac().fstop('2M').run();
d1.model(aModel2);
var a2 = ac().fstop('2M').run();
chart_xy()
.height(204)
.title('AC with 1mH series inductor')
.add_series(a1.data.frequency, a1.data['V(2)'].modulus(), aModel1)
.add_series(a2.data.frequency, a2.data['V(2)'].modulus(), aModel2)
.show();
}
compare_diodes('1N5399', 'FR107');