[SOLVED] OpAmp-based logic level tester in ngSpice

Yes, it is. Your noniverting input (VBIAS) is stuck at almost 5 V. As the voltage on the inverting input increases, the common voltage rises above the maximum allowed.

Reread the second paragraph in the linked document, look at the datasheet spec for input common mode range and maybe even study the opamp schematic in the datasheet.

When you build a circuit of this compexity in spice as probably both a beginner with spice, kicad, and maybe electronics in general too then it’s easy to get lost.

  • Is it your circuit?
  • Is it the potentiometer model?
  • Is it the LM324 model?
  • Are the power supplies connected in reverse?

When such doubts arises I usually go back to simpler circuits. It is a simple process of elimination.
These:

are separate steps. Start with just one opamp, In spice this is easily done by just deleting the others. On a breadboard those other three may start oscillating and have to be pacified as in the excellent (SLOA227.pdf / Chapter 7.2) linked above.
Any doubt of the potentiometer? Just eliminate it and use two resistors.

I learned to work with microcontrollers in the old days. Getting a blinking LED project to work was quite a challenge back then, and always exhilarating when it worked. The blinking LED in itself is irrelevant, but it shows that the whole toolchain from compiling source to programming the thing is working.

Same with learning spice, kicad & electronics all at the same time. Start with the simplest of things and get that to work, then slowly expand and build upon gained knowledge.

Thank you so much! It was spot on! Sorry, I could not follow you the first time.

Here red is the OpAmps pin 1, cyan = VBIAS, violet = VPROBE, white = I_d
plot_3

Thanks, I totally see your points. Indeed, it is hard to tell what is at fault here, given several complex SPICE models. Since I do not know SPICE, I decided to ask here, as I could not debug it myself.

And I never had to deal with SPICE models before. At the university, I did my simulations using Electronics Workbench, which did not require knowledge of SPICE. Now that I have again taken up electronics as a hobby, I will try to learn some more on these models. Otherwise, KiCad is great, but it has a pretty steep learning curve when it comes to simulations.

The way ngspice works in KiCad is indeed not very well polished, but it is quite powerful. For some things you end up writing spice directives in a textbox on the schematic.

On the plus side, it is being actively developed and has an extensive user manual:
https://html.duckduckgo.com/html?q=ngspice+pdf+user+manual
http://ngspice.sourceforge.net/docs/ngspice-manual.pdf

Date: 2021-03-14 and 679 pages of reading.

I have not done much with spice in KiCad myself. The thing I have the most trouble with is finding usable spice models. KiCad comes with hardly any. Many models you find on the net have incomprehensible licenses (or none at all) or are simply impossible to use because of encryption or of incompatibilities because they use proprietary extensions only available in some specific program.

I’d think that distributing a bunch of spice models for “standard” components (lm324, ne555, bc547, 2n2222, 2sc945, some power transistors such as bc327 bc337) as a default library together with KiCad would make it a lot easier for beginners to start with spice in KiCad.

I guess you already found it, but just to be sure, (and for others into the future), this is a pretty nice tutorial of getting spice to work in KiCad:
http://ngspice.sourceforge.net/ngspice-eeschema.html

On the plus side:
Your problem is solved now, and it did not have anything to do with ngspice or KiCad. You must have use a quite good spice model if it also simulates the opamp misbehaving if it’s inputs are not properly biased.