Город МОСКОВСКИЙ
00:16:02

Introduction to PySpice (Python) for Simulating BJT Common Emitter and Common Collector Amplifiers

Аватар
Питоновый поток
Просмотры:
33
Дата загрузки:
02.12.2023 23:19
Длительность:
00:16:02
Категория:
Обучение

Описание

This video shows to how to simulate BJT amplifier circuits in PySpice (Python).

It has the following chapters:
(00:00) [1] Introduction
(02:09) [2] How to model BJT
(03:14) [3] Voltage divider bias circuit
(06:32) [4] BJT common emitter (CE) amplifier circuit
(12:59) [5] BJT common collector (CC) amplifier circuit

It explains:
(a) In Section 2: How to model 2N3904 and 2N2222 BJT's in PySpice.
(b) In Sections 3-5: For each circuit, it discusses the theory, PySpice netlist, how to do theoretical calculations [(7:12) and (13:33)] side by side with simulations and real-time PySpice demos (see: (4:47) and (9:00) and (14:10). Results are also compared with LTSPICE [(5:35) and (11:08)] and PSPICE (11:43).

The Python codes are posted in the comments section below. The three examples show how to simulate BJT voltage divider bias circuit, BJT common emitter amplifier and BJT common collector amplifier.

A large collection of BJT Spice Models is available here:
https://github.com/kicad-spice-library/KiCad-Spice-Library/tree/master/Models/Transistor

The Python code for DC bias analysis is below. The Python code for transient analysis is in the pinned comment below.

######################################################################

# Pyspice (Python) code to simulate BJT Voltage Divider Bias Circuit
######################################################################

# STANDARD DECLARATIONS
# ------------------------

import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()

from PySpice.Doc.ExampleTools import find_libraries
from PySpice.Probe.Plot import plot
from PySpice.Spice.Library import SpiceLibrary
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

from engineering_notation import EngNumber

# CIRCUIT NETLIST
# ------------------------

circuit = Circuit('Voltage Divider Bias Circuit')

# http://ltwiki.org/index.php?title=Standard.bjt
circuit.model('2N2222', 'npn', IS=1E-14, VAF=100, BF=200, IKF=0.3, XTB=1.5, BR=3,
CJC=8E-12, CJE=25E-12, TR=100E-9, TF=400E-12, ITF=1,
VTF=2, XTF=3, RB=10, RC=.3, RE=.2, VCEO=30)

circuit.model('2N3904', 'npn', IS=1E-14, VAF=100, Bf=300, IKF=0.4, XTB=1.5, BR=4,
CJC=4E-12, CJE=8E-12, RB=20, RC=0.1, RE=0.1, TR=250E-9,
TF=350E-12, ITF=1, VTF=2, XTF=3, VCEO=40)

circuit.R('1', 'Vcc', 'base', 47@u_kΩ)
circuit.R('2', 'base', circuit.gnd, 10@u_kΩ)
circuit.R('C', 'Vcc', 'collector', 4.7@u_kΩ)
circuit.R('E', 'emitter', circuit.gnd,1@u_kΩ)
circuit.V(1, 'Vcc', circuit.gnd, 15@u_V)
circuit.BJT(1, 'collector', 'base', 'emitter', model='2N3904')

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.operating_point()

# SIMULATION RESULTS
# ------------------------

print('----------------')
print('Simulated Values')
print('----------------')
for node in analysis.nodes.values():
print('Node {}: {:1.3f} V'.format(str(node), float(node)))

for node in analysis.branches.values():
print('Node {}: {:1.3e} A'.format(str(node), float(node)))

IB = ((analysis['Vcc']-analysis['base'])/circuit.R1.resistance)-(analysis['base']/circuit.R2.resistance)
print('IB{}: {:1.4e} A'.format((str(IB)), float(IB)))

IC = (analysis['Vcc']-analysis['collector'])/circuit.RC.resistance
print('IC{}: {:1.4e} A'.format(str(IC), float(IC)))

IE = (analysis['emitter'])/circuit.RE.resistance
print('IE{}: {:1.4e} A'.format(str(IE), float(IE)))

VCE = (analysis['collector']-analysis['emitter'])
print('VCE{}: {:1.3f} V'.format(str(VCE), float(VCE)))

# THEORETICAL RESULTS
# ------------------------

print('------------------')
print('Theoretical Values')
print('------------------')

beta=300
VBE = 0.7@u_V
VTH = (circuit.V1.dc_value)*(circuit.R2.resistance/(circuit.R1.resistance+ circuit.R2.resistance))
RTH = (circuit.R1.resistance*circuit.R2.resistance)/(circuit.R1.resistance+ circuit.R2.resistance)
I_B = (VTH - VBE)/(RTH + (beta+1)*circuit.RE.resistance)
I_C = beta*I_B
I_E = (beta+1)*I_B
V_CE = (circuit.V1.dc_value)-(I_C*circuit.RC.resistance) - (I_E*circuit.RE.resistance)
V_C = (circuit.V1.dc_value)-(I_C*circuit.RC.resistance)
V_E = I_E*circuit.RE.resistance

print('VTH={} V'.format(EngNumber(float(VTH))))
print('RTH={} Ω'.format(EngNumber(float(RTH))))
print('IB={} A'.format(EngNumber(float(I_B))))
print('IC={} A'.format(EngNumber(float(I_C))))
print('IE={} A'.format(EngNumber(float(I_E))))
print('VCE={} V'.format(EngNumber(float(V_CE))))
print('VC={} V'.format(EngNumber(float(V_C))))
print('VE={} V'.format(EngNumber(float(V_E))))

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

Рекомендуемые видео