Untitled

advertisement
Electrical Circuits
AM
FM
1
Contents
1
Introduction
1.1
Installation
4
4
2
Basics
2.1
Electrical elements
2.2
Usage
2.3
Labels
2.4
Element methods
2.5
Connectors
2.6
Extra parameters
2.6.1
Chips
2.6.2
Gates
2.6.3
Passive elements
2.6.4
Active elements
2.7
Extra methods defined for Chip elements
5
5
5
6
7
8
8
9
10
10
10
10
3
11
Available elements
4
Falstad Circuit Simulator
4.1
Introduction
4.2
Caveat
4.3
Importing a Falstad circuit
4.4
Some imported Falstad circuits
16
16
16
16
17
2
Figures
2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
4.1
4.2
4.3
4.4
4.5
4.6
4.7
4.8
4.9
4.10
4.11
4.12
4.13
4.14
4.15
4.16
4.17
4.18
4.19
4.20
4.21
4.22
Resistor
Resistor (European standard)
Resistor with labels
Capacitor moved
Capacitor rotated
Set draw pen
Set fill pen
Capacitor with connectors
Passive elements
Active elements
Input/Output elements
Chip elements
SipoRegister
PisoRegister
DecadeCounter
Gate elements
3-cgand.txt
555lowduty.txt
7segdecoder.txt
ceamp.txt
clockedsrff.txt
counter.txt
deccounter.txt
decoder.txt
delayrc.txt
dram.txt
eclnor.txt
edgedff.txt
flashadc.txt
hfadc.txt
jkff.txt
johnsonctr.txt
masterslaveff.txt
nandff.txt
opint-current.txt
phasecompint.txt
rossler.txt
sinediode.txt
6
6
7
7
7
8
8
8
11
12
13
14
15
15
15
15
17
18
19
20
20
21
21
22
22
23
24
25
26
26
27
28
29
29
30
31
32
32
3
4.23
4.24
4.25
synccounter.txt
triodeamp.txt
xor.txt
33
33
34
4
1 Introduction
The electrical circuit package Circuit is a collection of graphical elements for drawing
electrical circuits.
The package is initially designed to work with the Falstad Circuit Simulator (FCS)1 2.
One can use the FCS to design the electrical circuit, export the circuit to a text file and
than use this package to import and draw the circuit. All the FCS elements are defined.
It is also possible to use this package without the FCS.
In the next sections, examples are given on how to use the Circuit package.
1.1 Installation
To start using the package Circuit, we need to install it. This is simple, just unzip the file
circuits.zip in the Asymptote directory into a subdirectory circuits for your platform.
On a Unix platform the directory to use, is /usr/local/share/asymptote/circuits.
1
2
See http://www.falstad.com/circuit/
The version of the Falstad Circuit Simulator located at https://github.com/gummybears/falstad_circuit_simulator is compatible with Java 7
5
2 Basics
2.1 Electrical elements
An electrical element is initialized by calling the element’s init(…)
defined as
method and is
void operator init(
pair a,
pair b,
pen drawpen=black,
pen fillpen=invisible
… Label[] labels
)
Common properties of a element are
•
pair a : the begin point of the element
•
pair b : the end point of the element
•
pen fillpen : the pen used to fill cyclic paths
•
pen drawpen : the pen used to fill non-cyclic paths
•
Label[] labels : an optional argument to specify labels
Some elements have extra parameters specific for the given element, and we will list
them later.
To draw a element, we need to know it’s element name. The standard for naming elements is the CamelCase method. For example a resistor can be initialized by calling the
method Resistor().3
2.2 Usage
We begin with a simple example i.e a resistor and draw different versions of this resistor
using different values for the properties just listed.
3
See appendix ?? for a list of all the elements and their names
6
1
2
3
4
5
6
7
8
9
10
11
12
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element[] e;
e[0] = Resistor( (0,0),(2,0));
e[0].draw();
e[1] = Resistor( (0,0), ( 0,-2), drawpen=green);
e[1].draw();
e[2] = Resistor( (0,0), ( 0, 2), drawpen=red);
e[2].draw();
e[3] = Resistor( (0,0), (-2, 0), drawpen=blue);
e[3].draw();
shipout(bbox(2mm,invisible));
Figure 2.1 Resistor
First we import the the Circuit package on line 1. Next we setup the size of the drawing to
use 1 centimeter as its default unit (we will in user coordinates). On line 3 we declare an
electrical element e, and on line 4 we initialize the element e. On line 5 we call e.draw()
which draws the element. Another resistor is defined and we draw this resistor in green.
The last line is to draw a border of 2 millimeter around the final picture.
There is an optional boolean parameter bool european, when set to true, will draw a
resistor as a small box (European standard).
1
2
3
4
5
6
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
e = Resistor( (0,0),(2,0), european=true);
e.draw();
shipout(bbox(2mm,invisible));
Figure 2.2 Resistor (European standard)
2.3 Labels
There is an optional parameter Label[] labels present to set a label or series of labels for
a given element. To add labels, we need to specify the labels and pass it to the constructor
method as demonstrated in the next example.
7
1
2
3
4
5
6
7
8
9
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
Label[] lv_labels;
lv_labels[0] = Label("$R$",(1,0.1),N);
lv_labels[1] = Label("$100 \Omega$",(1,-0.1),S);
e = Resistor( (0,0),(2,0), lv_labels[0], lv_labels[1]);
e.draw();
shipout(bbox(2mm,invisible));
R
100Ω
Figure 2.3 Resistor with
labels
2.4 Element methods
There are additional methods defined for each element and they are
•
void move(pair center) : to move the element to a given position.
•
void rotate(pair center, real angle) : to rotate the element given a position over angle
degrees.
•
void set_drawpen(pen drawpen) : to set the draw pen.
•
void set_fillpen(pen fillpen) : to set the fill pen (only for cyclic paths).
1
2
3
4
5
6
7
8
9
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
e = Capacitor( (0,0),(2,0) );
e.draw();
e.move( (0,-1) );
e.set_drawpen(green);
e.draw();
shipout(bbox(2mm,invisible));
1
2
3
4
5
6
7
8
9
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
e = Capacitor( (0,0),(2,0) );
e.draw();
e.rotate( (0,0), -90 );
e.set_drawpen(green);
e.draw();
shipout(bbox(2mm,invisible));
Figure 2.4 Capacitor moved
Figure 2.5 Capacitor rotated
8
1
2
3
4
5
6
7
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
e = Capacitor( (0,0),(2,0) );
e.set_drawpen(red);
e.draw();
shipout(bbox(2mm,invisible));
1
2
3
4
5
6
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
e = ACVoltage((0,0), (2,0), drawpen=green, fillpen=blue );
e.draw();
shipout(bbox(2mm,invisible));
Figure 2.6 Set draw pen
Figure 2.7 Set fill pen
2.5 Connectors
Each element has a number of connectors defined. Normally when calling the element’s
draw method the connector dots are not drawn.
By calling the method void draw_connectors(pen color) the connectors are drawn.
1
2
3
4
5
6
7
import "circuits/Circuit.asy" as Circuit;
unitsize(1cm,1cm);
Element e;
e = Capacitor( (0,0),(2,0) );
e.draw();
e.draw_connectors(red);
shipout(bbox(2mm,invisible));
Figure 2.8 Capacitor with
connectors
2.6 Extra parameters
As seen with the Resistor element, there are some elements which accept extra parameters. These elements are per category
9
2.6.1 Chips
For the Chip elements, there is the size parameter, which can take either the value 1 or
2. When the size is 1, a smaller version of the Chip element is drawn. This resembles
the Small Grid option in the FCS.
•
ADC
•
CC2
•
DAC
•
DecadeCounter
•
DeMultiplexer
•
DFlipFlop
•
FullAdder
•
HalfAdder
•
JKFlipFlop
•
MonoStable
•
Multiplexer
•
PhaseComparator
•
PisoRegister
•
SequenceGenerator
•
SevenSegmentDecoder
•
SevenSegmentDisplay
•
SipoRegister
•
TFlipFlop
•
Timer
•
VCO
10
2.6.2 Gates
For the Gate elements, one can specify the number of input pins, by setting the parameter input_connectors. The default number of input connectors is 2, with a maximum
of 32.
•
AndGate
•
NandGate
•
NorGate
•
OrGate
•
XorGate
For the Inverter element, by setting inverted to true, the input signal is inverted.
Setting bool inverted to false, the output signal is inverted.
2.6.3 Passive elements
For the Resistor element as seen before, we can set european. When false, the resistor
is drawn in US standard form.
2.6.4 Active elements
•
AnalogSwitch, bool open. The default is that the switch is open.
•
AnalogSwitch2, bool open. The default is that the switch is open.
•
Jfet, bool pnpflag. The default is false, a NJFet is drawn. When set to true, a PJfet is
drawn.
•
Mosfet, bool pnpflag. The default is false, a NJFet is drawn. When set to true, a PJfet
is drawn.
2.7 Extra methods defined for Chip elements
For all the Chip elements the following methods can be used
•
void flip_x(). This will flip all the pins in the X direction.
•
void flip_y(). All the pins are flipped in the Y direction.
•
void with_set(). This method will draw the flipflops with a Set pin.
•
void with_reset(). This method will draw the flipflops with a Reset pin .
11
3 Available elements
There are 70 predefined elements and to use them, we need to know the name of each
element. We tried to match each element name with its Asymptote’s structure or class
name.
The following is a list of all the available elements, organized by category. The class
name is given by the text in each figure and this is the name we will use to construct
circuit diagrams.
Capacitor
Inductor
Memristor
PotentioMeter
Probe
Resistor
Relay
SparkGap
Switch
SwitchSPDT
TransmissionLine
Transformer
TappedTransformer
Figure 3.1 Passive elements
12
Diode
InvertingSchmitt
Jfet
NJfet
NMosfet
OpAmp
OpAmpSwap
PJfet
PMosfet
SCR
Schmitt
Transistor
TriState
Triode
TunnelDiode
Zener
Figure 3.2 Active elements
13
AM
Antenna
ACVoltage
AM
Current
Ground
Lamp
FM
DCVoltage
FM
L
L
Led
LogicInput
LogicOutput
Output
SawtoothVoltage
SquareVoltage
Sweep
TriangleVoltage
Figure 3.3 Input/Output elements
14
In D3
D2
X
Z
D1
V+ D0
ADC
Q
Y
CC2
Q3
D3 O
Q2
D2
Q1
D1
Q
D
R Q0
D0 V+
Counter
DAC
Q
DFlipFlop
Q0
Q1
Q2
A
Q3
B
S0 S1
Cin S
DeMultiplexer
I0
J
C
FullAdder
A
S
B
C
Q
Q
K
HalfAdder
Q
Q
JKFlipFlop
Q
I1
I3
a
I2
b
I1
c
I0
d
a
e
b
I2
I1
I3
S0 S1
Multiplexer
f
Q
Q
I2
PhaseComparator
Vi
T
O
SequenceGenerator
g
SevenSegmentDecoder
C
C
R1
Q
TFlipFlop
Vo R2
VCO
Figure 3.4
Chip elements
MonoStable
c
d
e
f
g
SevenSegmentDisplay
15
I7
I6
I5
I4
I3
I2
I1
I0
D
Figure 3.5 SipoRegister
I7
I6
I5
I4
I3
I2
I1
I0
Q
L
Figure 3.6 PisoRegister
Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9
R
Figure 3.7 DecadeCounter
AndGate
Inverter
OrGate
XorGate
NandGate
Figure 3.8 Gate elements
NorGate
16
4 Falstad Circuit Simulator
4.1 Introduction
The primary reason to write the Circuit package, is to be able to draw the electrical
circuits created by the Falstad Circuit Simulator.
4.2 Caveat
In the Falstad Circuit Simulator there is an option to use a Small Grid. However there is
a problem that this setting is not exported for the OpAmp element. It is advised not to
set the Small Grid option, and design the circuit with the default grid setting.
4.3 Importing a Falstad circuit
To import a Falstad circuit, we can use the method
1
2
3
4
5
bool import_circuit(
string filename,
bool european = false,
bool show_values = true
){
The next example demonstrates this.
1
2
3
4
5
6
7
8
import "circuits/Circuit.asy" as Circuit;
Circuit lv_circuit;
unitsize(1cm,1cm);
lv_circuit = Circuit();
lv_circuit.import_circuit("3-cgand.txt", european=false, show_values=true);
lv_circuit.draw(drawpen=black);
lv_circuit.draw_dots(black);
shipout(bbox(0.25cm,invisible));
On line 4, we initialize a circuit. On line 5 we import the circuit 3-cgand.txt. The file
3-cgand.txt must be located in the same directory as your Asymptote script. It will use
the US standard for drawing the resistor (when present). By setting the show_values
to true, the values of each element (when present) will be drawn. On line 6 we use the
17
method draw to do the actual drawing. On line 7 by calling draw_dots elements which
share 3 or more connectors will drawn with a connector dot.
4.4 Some imported Falstad circuits
+5V
+2.5V
2
1
1
Figure 4.1 3-cgand.txt
18
+10V
Vin
dis
rst
out
150k
tr
th ctl
10k
100nF
Figure 4.2
555lowduty.txt
out
19
0
1
0
1
a
b
c
d
Figure 4.3 7segdecoder.txt
e
f
g
20
+20V
110k
10k
5µF
80Hz
5µF
out
1M
10k
1k
Figure 4.4 ceamp.txt
L
L
L
L
CLK
Figure 4.5 clockedsrff.txt
21
0
0
0
0
J
Q
J
Q
J
Q
J
Q
K
Q
K
Q
K
Q
K
Q
CLK
+5V
Figure 4.6
counter.txt
0
0
0
0
+5V
J
Q
J
Q
J
Q
J
Q
K
Q
K
Q
K
Q
K
Q
CLK
Figure 4.7 deccounter.txt
22
0
L
L
L
0
L
Figure 4.8 decoder.txt
+5V
+5V
1.5k
H
L
10nF
Figure 4.9 delayrc.txt
23
10nF
10nF
0
10nF
row select
1
10nF
+2.5V
write
L
data
H
refresh
L
Figure 4.10 dram.txt
L
24
240
217
L
250
L
NOR
H
Q3
Q1
OR
H
Q2
1.2k
3k
2.5k
-5.2V
Figure 4.11 eclnor.txt
1.5k
1.5k
25
L
CLK
L
H
Figure 4.12 edgedff.txt
26
50Hz
+7V
500
1k
1k
1k
1k
L
1k
L
1k
L
500
Figure 4.13 flashadc.txt
5Hz
In D3
+25.5V
D3 O
D2
D2
D1
D1
V+ D0
D0 V+
+25.5V
L
100k
100k
L
L
L
100k
In D3
D2
D1
100k
+1.5V
V+ D0
Figure 4.14 hfadc.txt
L
L
L
L
27
J
H
Q
L
K
H
L
Q
CLK
Figure 4.15 jkff.txt
28
L
L
L
L
L
L
L
L
L
L
D
D
Q
Q
D
Q
Q
D
Q
Q
D
Q
Q
Q
Q
CLK
L
L
L
Figure 4.16 johnsonctr.txt
L
L
29
D
master
slave
H
Q
L
L
Q
CLK
Figure 4.17 masterslaveff.txt
set
Q
H
L
Q
reset
L
H
Figure 4.18 nandff.txt
30
40Hz
150
300
+15V
+
25
4.5k
39k
30pF
out
7.5k
1k
50k
1k
50
5k
50k
-15V
Figure 4.19 opint-current.txt
50
31
+5V
120Hz
+5V
D
Q
R
Q
+5V
1k
out
1k
115Hz
+5V
D
Q
R
Q
Figure 4.20 phasecompint.txt
32
1nF
200k
2M
100k
75k
1nF
10k
5M
10k
100k
1nF
150k
100k
10k
100k
68k
-15V
Figure 4.21 rossler.txt
80Hz
200
out
2k
100
33
1k
82
470
330
120
47
30
39
+2.4V
100
33
82
47
30
39
-2.4V
Figure 4.22 sinediode.txt
33
0
0
0
0
+5V
J
Q
J
Q
J
Q
J
Q
K
Q
K
Q
K
Q
K
Q
CLK
Figure 4.23 synccounter.txt
+160V
10k
5µF
80Hz
out
5µF
100k
10k
3k
Figure 4.24 triodeamp.txt
5µF
34
L
L
L
Figure 4.25 xor.txt
Download