Hello all, I tried to make an ideal opamp in xsche...
# analog-design
e
Hello all, I tried to make an ideal opamp in xschem using VCVS with high gain but there was a problem its output is infinite as it has no rails. Is there a way to make a limiter in xschem or is there an Ideal opamp ready to be used?
c
Sounds like a case for B source magic. See chapter 5.5.1 in the ngspice manual.
πŸ‘ 1
v
That's a classic macro modelling issue. The classic way to model supply clipping is by using a subcircuit with some diodes to the rails inside. I think The Spice Book by Andrei Vladimirescu had an example of that.
πŸ‘ 2
s
@Eslam Morsie A good candidate for this is the tanh function applied to a 'B' voltage source, see picture. The advantage is the transfer function is continous with continus derivative. so it will not cause convergence issues. In the example, VCC is a .param set to 3
πŸ‘ 2
πŸ™Œ 1
e
Thanks sir @Stefan Schippers but I have a question: what is "100" in the bsource is that the opamp gain? and the output swept vs what?
@Stefan Schippers Could you please provide the spice netlist used to test the circuit "stimuli"?
s
@Eslam Morsie yes, 100 is a parameter controlling the gain. The actual gain around the middle point is
VCC/2 * 100
(the derivative of
tanh(x)
is
1-[tanh(x)]^2
, so the derivative of tanh(0) is 1). you can replace '100' with a GAIN parameter and set .param GAIN={100/VCC*2} Simulation sweeps the PLUS voltage around 1.5V and keeping MINUS to 1.5V Here the netlist for the example:
Copy code
**.subckt test_bsource PLUS MINUS OUT
*.ipin PLUS
*.ipin MINUS
*.opin OUT
B2 OUT 0 V = 'VCC/2*(1+tanh(GAIN*(V(PLUS_I)-V(MINUS_I))))' 
V1 PLUS PLUS_I 0
V2 MINUS MINUS_I 0
.param VCC=3
** set gain to 100. Divide by VCC/2 to cancel out the VCC/2 multiplier in Bsource expression
.param GAIN={100/VCC*2}

vminus minus 0 {VCC/2}
vplus plus 0 {VCC/2}
.control
save all
dc vplus 0 3 0.001
write test_bsource.raw
.endc

.end
e
@Stefan Schippers Many thanks for the explanation
t
@Eslam Morsie I didn't see this post until now but I already have exactly what you're looking for in my analoglib https://gitlab.com/edalibs/analoglib/-/blob/master/spice/util.sp there are two versions of the opamp, one ideal infinite BW one
opamp
, and one dominant pole compensated model
opamp2