# Pyspice (Python) code to simulate a constant power load # Electric Circuits @ You Tube # kzitem.info/rock/n5Hpio6i2SNpETUeemKWuw # #################################################### import math import numpy as np from engineering_notation import EngNumber import matplotlib.pyplot as plt from matplotlib.widgets import Cursor from matplotlib.pyplot import semilogx from matplotlib import pyplot 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 * #################################################### circuit = Circuit('Constant power load') voltage = 13@u_V power =15@u_W; Imin = 0.1@u_A Imax = 20@u_A; circuit.V(1, 'inp', circuit.gnd, voltage) # Use B source to model a constant power load # # Option 1 #circuit.B(1, 'inp', 'dummy',i = min(power/circuit.V1.dc_value,Imax)) # # Option 2 # limit(x,y,z) | intermediate value of x, y, and z, equivalent to min(max(x,y),z) circuit.B(1, 'inp', 'dummy',i = min(max(Imin, power/circuit.V1.dc_value),Imax)) # Dummy 0V source to measure current through B source circuit.V(2, 'dummy',circuit.gnd, 0@u_V) simulator = circuit.simulator(temperature=25, nominal_temperature=25) analysis = simulator.operating_point() for node in analysis.nodes.values(): print('Node {}: {:4.1f} V'.format(str(node), float(node))) for node in analysis.branches.values(): print('Node {}: {:5.3e} A'.format(str(node), float(node))) # Measure power in B source power_mea = analysis.nodes['inp']*analysis.branches['v2'] # display the desired power print('Set Power={} W'.format(EngNumber(float(power)))) # display the measured power print('Measured Power={} W'.format(EngNumber(float(power_mea))))
@creativegoods7737
3 жыл бұрын
Would you please make a video for the constant power load in Simulink Matlab?
@electriccircuits7164
3 жыл бұрын
Thank you for the suggestion. This is already implemented in Simulink: www.mathworks.com/help/physmod/sps/ref/constantpowerload.html
@sq2643
2 жыл бұрын
How to calculate impedance of different amplifier and current mirror circuits using Ltspice?
@electriccircuits7164
2 жыл бұрын
Thank you. I may cover difference amplifier and current mirrors in future videos.
Пікірлер: 5