8.12.2. Voltage Divider

voltage-divider.pyvoltage-divider.py
#!# This example shows the computation of the DC bias and sensitivity in a voltage divider.

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

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

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

from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *

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

#cm# voltage-divider.m4

circuit = Circuit('Voltage Divider')

circuit.V('input', 'in', circuit.gnd, 10@u_V)
circuit.R(1, 'in', 'out', 9@u_kΩ)
circuit.R(2, 'out', circuit.gnd, 1@u_kΩ)

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

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

analysis = simulator.operating_point()
for node in (analysis['in'], analysis.out): # .in is invalid !
    print('Node {}: {} V'.format(str(node), float(node)))
#o#

# Fixme: Xyce sensitivity analysis
analysis = simulator.dc_sensitivity('v(out)')
for element in analysis.elements.values():
    print(element, float(element))
#o#

This example shows the computation of the DC bias and sensitivity in a voltage divider.

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

from PySpice.Spice.Netlist import Circuit
from PySpice.Unit import *
../../_images/voltage-divider2.png
circuit = Circuit('Voltage Divider')

circuit.V('input', 'in', circuit.gnd, 10@u_V)
circuit.R(1, 'in', 'out', 9@u_kΩ)
circuit.R(2, 'out', circuit.gnd, 1@u_kΩ)

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

analysis = simulator.operating_point()
for node in (analysis['in'], analysis.out): # .in is invalid !
    print('Node {}: {} V'.format(str(node), float(node)))
Node in [V]: 10.0 V
Node out [V]: 1.0 V
# Fixme: Xyce sensitivity analysis
analysis = simulator.dc_sensitivity('v(out)')
for element in analysis.elements.values():
    print(element, float(element))
r2_scale [V] 0.899999099855317
r1_w [V] -0.0
vinput [V] 0.09999999999621426
r1 [V] -9.999990001102918e-05
r2_l [V] -0.0
r2_bv_max [V] -0.0
r1_l [V] -0.0
r2_m [V] -0.8999999999259601
r1_scale [V] -0.8999991000992625
r1_m [V] 0.8999999999259599
r2 [V] 0.0008999991000504734
r2:bv_max [V] -0.0
r1:bv_max [V] -0.0
r1_bv_max [V] -0.0
r2_w [V] -0.0