I tried to draw a common emitter amplifier by using SchemDraw package in Google Colab Notebook. I installed SchemDraw version=0.14 by pip in Colab Notebook. This version is not latest. The latest version(=0.15) probably has some ploblem.
The Walrus Operator := in Python : The walrus operator is an assignment operator which was introduced in Python 3.8.
One is a loop between the collector, emitter, voltage source, and load resistance
pip install schemdraw==0.14The version of Python in the notebook kernel is 3.7. It came up against a diffculty. In Python 3.7. or earlier the Walrus operator := is not available.
import schemdraw
print('Schemdraw',schemdraw.__version__)
!python --version
# Schemdraw 0.14
# Python 3.7.13
Sample codes in the SchemDraw Gallary are written with the Walrus operator. For instance the code below is one in the gallary and dose not work in the Colab Notebook.
import schemdraw
import schemdraw.elements as elm
# Discharging capacitor
with schemdraw.Drawing() as d:
d += (V1 := elm.SourceV().label('5V'))
d += elm.Line().right(d.unit*.75)
d += (S1 := elm.SwitchSpdt2(action='close').up().anchor('b').label('$t=0$', loc='rgt'))
d += S1
d += elm.Line().right(d.unit*.75).at(S1.c)
d += elm.Resistor().down().label('$100\Omega$').label(['+','$v_o$','-'], loc='bot')
d += elm.Line().to(V1.start)
d += elm.Capacitor().at(S1.a).toy(V1.start).label('1$\mu$F').dot()
# d += (V1 := elm.SourceV().label('5V'))
# ^
# SyntaxError: invalid syntax
So I rewrote ':=' such like
# d += (V1 := elm.SourceV().label('5V')
V1 = elm.SourceV().label('5V')
d += V1
The new code is
import schemdraw
import schemdraw.elements as elm
# Discharging capacitor
with schemdraw.Drawing() as d:
V1 = elm.SourceV().label('5V')
d += V1
d += elm.Line().right(d.unit*.75)
S1 = elm.SwitchSpdt2(action='close').up().anchor('b').label('$t=0$', loc='rgt')
d += S1
d += elm.Line().right(d.unit*.75).at(S1.c)
d += elm.Resistor().down().label('$100\Omega$').label(['+','$v_o$','-'], loc='bot')
d += elm.Line().to(V1.start)
d += elm.Capacitor().at(S1.a).toy(V1.start).label('1$\mu$F').dot()
The Walrus Operator := in Python : The walrus operator is an assignment operator which was introduced in Python 3.8.
Bipolar Junction Transistor
Add Bipolar Junction Transistor for a common emitter amplifier.import schemdraw import schemdraw.elements as elm d = schemdraw.Drawing() # Add Npn Bipolar Junction Transistor d += elm.BjtNpn(circle=True) d.draw()The element BjtNpn has anchors and parameters:
class schemdraw.elements.transistors.BjtNpn(*d, circle: bool = False, **kwargs) NPN Bipolar Junction Transistor Parameters circle – Draw circle around the transistor Anchors: collector emitter basePut a circle to the BjtNpn and add a dot at the collector
import schemdraw import schemdraw.elements as elm d = schemdraw.Drawing() Q1 = elm.BjtNpn(circle=True) d += Q1 d += elm.Dot().at(Q1.collector)
Common Emitter Amplifier
There are two loops in common emitter amplifier circuit.One is a loop between the collector, emitter, voltage source, and load resistance
import schemdraw
import schemdraw.elements as elm
d = schemdraw.Drawing()
# Assaign a BJT NPN to Q1
Q1 = elm.BjtNpn(circle=True)
# Add BJT
d += Q1
d += elm.Line().up().at(Q1.collector).length(d.unit)
d += elm.Line().right().length(d.unit)
# load resistance
d += elm.Resistor().down().label('$R_L$', loc='bottom')
# Voltage applied to the collector
d += elm.BatteryCell()
# d += elm.Line().down().length(d.unit*.5)
d += elm.Line().tox(Q1.emitter)
d += elm.Line().toy(Q1.emitter)
The other loop is a clockwise cuircuit loop through the base, emitter, and voltage source.
# Clockwise cuircuit loop through the base, emitter, and voltage source d += elm.Line().at(Q1.base).left().length(d.unit) # Voltage applied to the collector d += elm.BatteryCell().down() d += elm.Line().tox(Q1.emitter) d += elm.Dot()This emitter common amplifier is a direct current circuit.





Comments
Post a Comment