Trying to Create a Schmitt Trigger Component in ModelingToolkit.jl

The errors you are getting both stem from a typo:

	connect(R1.n, R1.p)

should be

	connect(R1.n, R2.p)

But even after that, this ideal op-amp model won’t produce a Schmitt trigger. This model enforces the constraint that there is no current or voltage difference between the inputs, but does not enforce that the sign of the gain is positive. A Schmitt trigger circuit also needs the property that the output sign is the same as the input sign (infinite gain) and the non-ideality that the op-amp has limited output voltage.

You might try connecting a Voltage Sensor to a Voltage Source (with a limiter) via a large gain to produce a more appropriate ideal op-amp for this circuit.

Edit:
A plot after correcting the typo:

soln = solve(prob)
ts=0:0.05:10
plot(soln(ts; idxs=[0, source.v, output_pin.v]))

nogainconstraint

1 Like