PWM and comparator NGSPICE


I want to show to students how PWM is made, thus using a sawtooth and SIN comparator using op amp.
The only -bloody- opam that I can make working is the lousy TL072.
All real comparator IE 311 and other are impossible to get working.
Ideally I would love to have a significant faster chopping frequency. Here 20 KHz seems a maximum.
Any idea ?
In general It would be nice to have a ideal op amp in the built in library. Also I can’t find how to attach a SCH here.

OK, I read the upload limitation for beginners :wink:

You are already above “new user” level in the forum, are you sure you can’t attach a file?

I don’t know how savvy you are with KiCAD, but you’ll certainly find the LM311 and other comparators in the symbol library “Comparators”.
What the symbols will NOT include are the Spice models. You’ll have to find those yourself and add them to the symbols in your schematic. Best sources (quality-wise) are the manufacturers’ web pages.
This is also a help:

perhaps I can’t find the icon. isn’t a paper clip or smg ?

thanks, yes yes I know.
But even after numerous tryout the LM3111 (or other) don’t work.
My level is limited to: find and DL a model / assign the pins.

You can just drag and drop, or use the upload button above.

If it doesn’t work, I can promote you…

OK! the button has just appeared!

And I managed to get the LM311 working!
Houray and thanks all!

An ideal opamp: Well I have not yet played with ngspice (though used ltspice a fair bit) – remembering back to when I first started playing with spice in the 80s (from fortran source and loaded from 9-track on a vax) I was delighted to find the perfect opamp: the voltage-controlled-voltage-source. I imagine it is still a spice staple. Give it a gain of a million for an open-loop gain of 120dB. It is easy to add an RC on the output to give it a first-order rolloff at a hertz or so (iirc a current-out with parallel RC was better for some reason). Can get fancy with diode clippers on the output…

In Spice models and model parameters for ngspice circuit simulator, especially in the basic model parameter set ( you will find a generic OpAmp model. Its parameters are pole frequency, gain, output resistance and offset. The maximum output voltage is limited to the Vcc and Vee voltages.