-
Notifications
You must be signed in to change notification settings - Fork 0
/
InvertingSchmittElm.java
165 lines (152 loc) · 4.28 KB
/
InvertingSchmittElm.java
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import java.awt.*;
import java.util.StringTokenizer;
// contributed by Edward Calver
class InvertingSchmittElm extends CircuitElm {
double slewRate; // V/ns
double lowerTrigger;
double upperTrigger;
boolean state;
public InvertingSchmittElm(int xx, int yy) {
super(xx, yy);
noDiagonal = true;
slewRate = .5;
state=false;
lowerTrigger=1.66;
upperTrigger=3.33;
}
public InvertingSchmittElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
super(xa, ya, xb, yb, f);
noDiagonal = true;
try {
slewRate = new Double (st.nextToken()).doubleValue();
lowerTrigger = new Double (st.nextToken()).doubleValue();
upperTrigger = new Double (st.nextToken()).doubleValue();
} catch (Exception e) {
slewRate = .5;
lowerTrigger=1.66;
upperTrigger=3.33;
}
}
String dump() {
return super.dump() + " " + slewRate+" "+lowerTrigger+" "+upperTrigger;
}
int getDumpType() { return 183; }//Trying to find unused type
void draw(Graphics g) {
drawPosts(g);
draw2Leads(g);
g.setColor(needsHighlight() ? selectColor : lightGrayColor);
drawThickPolygon(g, gatePoly);
drawThickPolygon(g, symbolPoly);
drawThickCircle(g, pcircle.x, pcircle.y, 3);
curcount = updateDotCount(current, curcount);
drawDots(g, lead2, point2, curcount);
}
Polygon gatePoly;
Polygon symbolPoly;
Point pcircle;
void setPoints() {
super.setPoints();
int hs = 16;
int ww = 16;
if (ww > dn/2)
ww = (int) (dn/2);
lead1 = interpPoint(point1, point2, .5-ww/dn);
lead2 = interpPoint(point1, point2, .5+(ww+2)/dn);
pcircle = interpPoint(point1, point2, .5+(ww-2)/dn);
Point triPoints[] = newPointArray(3);
Point symPoints[] = newPointArray(6);
Point dummy=new Point(0,0);
interpPoint2(lead1, lead2, triPoints[0], triPoints[1], 0, hs);
triPoints[2] = interpPoint(point1, point2, .5+(ww-5)/dn);
interpPoint2(lead1, lead2, symPoints[5], symPoints[4], 0.2, hs/4);// 0 5 1
interpPoint2(lead1, lead2, symPoints[1], symPoints[2], 0.35, hs/4);// 4 2 3
interpPoint2(lead1, lead2, symPoints[0],dummy, 0.1, hs/4);
interpPoint2(lead1, lead2,dummy,symPoints[3], 0.45, hs/4);
gatePoly = createPolygon(triPoints);
symbolPoly=createPolygon(symPoints);
setBbox(point1, point2, hs);
}
int getVoltageSourceCount() { return 1; }
void stamp() {
sim.stampVoltageSource(0, nodes[1], voltSource);
}
void doStep() {
double v0 = volts[1];
double out;
if(state)
{//Output is high
if(volts[0]>upperTrigger)//Input voltage high enough to set output low
{
state=false;
out=0;
}
else
{
out=5;
}
}
else
{//Output is low
if(volts[0]<lowerTrigger)//Input voltage low enough to set output high
{
state=true;
out=5;
}
else
{
out=0;
}
}
double maxStep = slewRate * sim.timeStep * 1e9;
out = Math.max(Math.min(v0+maxStep, out), v0-maxStep);
sim.updateVoltageSource(0, nodes[1], voltSource, out);
}
double getVoltageDiff() { return volts[0]; }
void getInfo(String arr[]) {
arr[0] = "InvertingSchmitt";
arr[1] = "Vi = " + getVoltageText(volts[0]);
arr[2] = "Vo = " + getVoltageText(volts[1]);
}
public EditInfo getEditInfo(int n) {
if (n == 0)
{
dlt=lowerTrigger;
return new EditInfo("Lower threshold (V)", lowerTrigger, 0.01,5);
}
if (n == 1)
{
dut=upperTrigger;
return new EditInfo("Upper threshold (V)", upperTrigger, 0.01,5);
}
if (n == 2)
return new EditInfo("Slew Rate (V/ns)", slewRate, 0, 0);
return null;
}
double dlt;
double dut;
public void setEditValue(int n, EditInfo ei) {
if (n == 0)
dlt=ei.value;
if (n == 1)
dut=ei.value;
if (n == 2)
slewRate = ei.value;
if(dlt>dut)
{
upperTrigger=dlt;
lowerTrigger=dut;
}
else
{
upperTrigger=dut;
lowerTrigger=dlt;
}
}
// there is no current path through the InvertingSchmitt input, but there
// is an indirect path through the output to ground.
boolean getConnection(int n1, int n2) { return false; }
boolean hasGroundConnection(int n1) {
return (n1 == 1);
}
}