Beispiel #1
0
# Fixme: for loop makes difficult to intermix code and text !

#!# We will fit from the simulation output the time constant of each circuit and compare it to the
#!# theoretical value.

figure = plt.figure(1, (20, 10))

element_types = ('capacitor', 'inductor')

for element_type in ('capacitor', 'inductor'):

    circuit = Circuit(element_type.title())
    # Fixme: compute value
    source = circuit.Pulse('input', 'in', circuit.gnd,
                           initial_value=0@u_V, pulsed_value=10@u_V,
                           pulse_width=10@u_ms, period=20@u_ms)
    circuit.R(1, 'in', 'out', 1@u_kΩ)
    if element_type == 'capacitor':
        element = circuit.C
        value = 1@u_uF
        # tau = RC = 1 ms
    else:
        element = circuit.L
        # Fixme: force component value to an Unit instance ?
        value = 1@u_H
        # tau = L/R = 1 ms
    element(1, 'out', circuit.gnd, value)
    # circuit.R(2, 'out', circuit.gnd, kilo(1)) # for debug

    if element_type == 'capacitor':
Beispiel #2
0
####################################################################################################

libraries_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'libraries')
spice_library = SpiceLibrary(libraries_path)

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

# #cm# relay.m4

period = 50@u_ms
pulse_width = period / 2

circuit = Circuit('Relay')

# circuit.V('digital', 'Vdigital', circuit.gnd, 5@u_V)
circuit.Pulse('clock', 'clock', circuit.gnd, 0@u_V, 5@u_V, pulse_width, period, rise_time=5@u_ms, fall_time=5@u_ms)
circuit.R('base', 'clock', 'base', 100@u_Ω)
circuit.BJT(1, 'collector', 'base', circuit.gnd, 'bjt') # Q is mapped to BJT !
circuit.model('bjt', 'npn', bf=80, cjc=pico(5), rb=100)
circuit.V('analog', 'VccAnalog', circuit.gnd, 8@u_V)
circuit.R('relay', 'VccAnalog', 1, 50@u_Ω)
circuit.L('relay', 1, 'collector', 100@u_mH)
circuit.include(spice_library['1N5822']) # Schottky diode
diode = circuit.X('D', '1N5822', 'collector', 'VccAnalog')
# Fixme: subcircuit node
# diode.minus.add_current_probe(circuit)

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

figure = plt.figure(1, (20, 10))
Beispiel #3
0
print('Cout =', Cout)
print('Cint =', Cin)

circuit.V('in', 'in', circuit.gnd, Vin)
circuit.C('in', 'in', circuit.gnd, Cin)

# Fixme: out drop from 12V to 4V
# circuit.VCS('switch', 'gate', circuit.gnd, 'in', 'source', model='Switch', initial_state='off')
# circuit.Pulse('pulse', 'gate', circuit.gnd, 0@u_V, Vin, duty_cycle, period)
# circuit.model('Switch', 'SW', ron=1@u_mΩ, roff=10@u_MΩ)

# Fixme: Vgate => Vout ???
circuit.X('Q', 'irf150', 'in', 'gate', 'source')
# circuit.Pulse('pulse', 'gate', 'source', 0@u_V, Vin, duty_cycle, period)
circuit.R('gate', 'gate', 'clock', 1 @ u_Ω)
circuit.Pulse('pulse', 'clock', circuit.gnd, 0 @ u_V, 2. * Vin, duty_cycle,
              period)

circuit.X('D', '1N5822', circuit.gnd, 'source')
circuit.L(1, 'source', 1, L)
circuit.R('L', 1, 'out', RL)
circuit.C(1, 'out', circuit.gnd, Cout)  # , initial_condition=0@u_V
circuit.R('load', 'out', circuit.gnd, Rload)

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.transient(step_time=period / 300, end_time=period * 150)

figure = plt.figure(1, (20, 10))
axe = plt.subplot(111)

plot(analysis.out, axis=axe)
plot(analysis['source'], axis=axe)
Beispiel #4
0
####################################################################################################

# Warning: the capacitor/inductor return current in the generator
#  could use switches instead

figure = plt.figure(1, (20, 10))

for element_type in 'capacitor', 'inductor':

    circuit = Circuit(element_type.title())
    # Fixme: compute value
    source = circuit.Pulse('input',
                           'in',
                           circuit.gnd,
                           initial_value=0,
                           pulsed_value=10,
                           pulse_width=milli(10),
                           period=milli(20))
    circuit.R(1, 'in', 'out', kilo(1))
    if element_type == 'capacitor':
        element = circuit.C
        value = micro(1)  # F
        # tau = RC = 1 ms
    else:
        element = circuit.L
        value = 1  # H
        # tau = L/R = 1 ms
    element(1, 'out', circuit.gnd, value)
    # circuit.R(2, 'out', circuit.gnd, kilo(1)) # for debug
Beispiel #5
0
axe.set_ylabel('Rd [Ω]')

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

frequency = Frequency(mega(1))

circuit = Circuit('Diode')
circuit.include(spice_library['BAV21'])
# source = circuit.Sinusoidal('input', 'in', circuit.gnd,
#                             dc_offset=dc_offset, offset=dc_offset,
#                             amplitude=ac_amplitude,
#                             frequency=frequency)
source = circuit.Pulse('input',
                       'in',
                       circuit.gnd,
                       initial_value=dc_offset - ac_amplitude,
                       pulsed_value=dc_offset + ac_amplitude,
                       pulse_width=frequency.period / 2.,
                       period=frequency.period)
circuit.R(1, 'in', 'out', kilo(1))
circuit.D('1', 'out', circuit.gnd, model='BAV21')

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.transient(step_time=source.period / 1e3,
                               end_time=source.period * 4)

axe = plt.subplot(313)
# Fixme: axis, x scale
# plot(analysis['in'] - dc_offset + quiescent_points[0]['quiescent_voltage'], axis=axe)
# plot(analysis.out, axis=axe)
axe.plot(analysis.out.abscissa * 1e6, analysis.out)
Beispiel #6
0
import PySpice.Logging.Logging as Logging
logger = Logging.setup_logging()

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

from PySpice.Probe.Plot import plot
from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

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

#!# We will drive the transmission line with a pulse source and use a standard 50 Ω load.

circuit = Circuit('Transmission Line')
circuit.Pulse('pulse', 'input', circuit.gnd, 0@u_V, 1@u_V, 1@u_ns, 1@u_us)
circuit.TransmissionLine('delay', 'input', circuit.gnd, 'output',
                         circuit.gnd, impedance=50, time_delay=40e-9)
circuit.R('load', 'output', circuit.gnd, 50@u_Ω)

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.transient(step_time=1e-11, end_time=100e-9)

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

figure = plt.figure(None, (20, 6))
plot(analysis['input'])
plot(analysis['output'])
plt.xlabel('Time [s]')
plt.ylabel('Voltage (V)')
plt.grid()
Beispiel #7
0
####################################################################################################

import PySpice.Logging.Logging as Logging

logger = Logging.setup_logging()

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

from PySpice.Probe.Plot import plot
from PySpice.Spice.Netlist import Circuit

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

circuit = Circuit('Transmission Line')
circuit.Pulse('pulse', 'input', circuit.gnd, 0, 1, 1e-9, 1e-6)
circuit.R('load', 'output', circuit.gnd, 50)
circuit.TransmissionLine('delay',
                         'input',
                         circuit.gnd,
                         'output',
                         circuit.gnd,
                         impedance=50,
                         time_delay=40e-9)

simulator = circuit.simulator(temperature=25, nominal_temperature=25)
analysis = simulator.transient(step_time=1e-11, end_time=100e-9)

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

plt.figure(None, (20, 6))
    #Test Bench Definition
    circuit = Circuit('TestBench')
    circuit.subcircuit(IdealDac(nbits=dac_nbits))
    circuit.subcircuit(BitLogic())
    circuit.subcircuit(IdealSampleHold())
    circuit.subcircuit(IdealPipelineStage())
    circuit.subcircuit(IdealAdc(nbits=adc_nbits))
    #Instantiating Sources
    # -input source
    circuit.Sinusoidal('in1', 'in1', circuit.gnd, dc_offset=dc_signal, offset=dc_signal, amplitude=amp_signal, frequency=f_signal, delay=0, damping_factor=0)
    # -supply rails and references
    circuit.V('vdd', 'vdd', circuit.gnd, 1)
    circuit.V('refp', 'vrefp', circuit.gnd, 1)
    circuit.V('refn', 'vrefn', circuit.gnd, 0)
    # - clock
    circuit.Pulse('clk', 'clk', circuit.gnd, 0, 1, t_sample/2, t_sample, fall_time=0.01*t_sample, rise_time=0.01*t_sample)
    # -ADC/DAC
    circuit.X('ADC', 'IDEALADC', 'vrefp', 'vrefn', 'vdd', circuit.gnd, 'in1', 'clk', ', '.join([('b'+str(i)) for i in range(adc_nbits)]))
    circuit.X('DAC', 'IDEALDAC', 'vrefp', 'vrefn', 'vdd', circuit.gnd, ', '.join([('b'+str(i)) for i in range(dac_nbits)]), 'out')
    #Transient Sims
    # -instantiating a simulator
    simulator = circuit.simulator(temperature=25, nominal_temperature=25)
    # -defining Simulator Properties
    simulator.options('MAXORD=5')
    simulator.options('METHOD=Gear')
    # -Extractin Analysis Data
    analysis = simulator.transient(step_time=1E-9, end_time=tran_sim_end_time)
    #Printing the Circuit Nodes (optional)
    #print(analysis.nodes.values())

    #Plotting Transient Sims Data