Diode A-K in Spice - isn't it a bug?

Reading forum I know that real diodes have K=1 and simulation models have A=1. So I expected diode in Simulation library having A=1. But not - it also has K=1. As I have never before tried using Spice in KiCad I suppose that it was changed to avoid problems if someone take this diode and select footprint to it.
In that symbol there is:
AK_1
So the correction of reversed pins is made here - OK.
I have my simple BAV99 model I have done in 90s based on 1991 Philips data book:
.model BAV99 D (IS=10f RS=1.5 CJO=1.5p TT=8.656n BV=70)
So I decided to start from this simple model to add this diode to my simulation symbols lib.
I:

  • did ā€˜Save-asā€™ those D from Simulation_SPICE library to my library,
  • changed model from ā€˜Build-in SPICE modelā€™ to ā€˜SPICE model from fileā€™,
  • selected file containing my model,
  • selected model.

And then I found my diode works reversed.
During this 4 step process Pin assignment was changed without any action on my side to:

AK_2

Donā€™t you think it is a bug?
After changing to ā€˜SPICE model from fileā€™ on the model side we have twice ā€˜Not connectedā€™. And then when model is selected I suppose the old values (when diode for simulation was draw reversed (as I suppose) are written here.

If it is so that in past diode for simulation was reversed and now is as all other diodes than here it should behave consistently.

Does it matter?
You are already used to maintaining your own verified libraries, and KiCadā€™s libraries do not come with spice models. So you just fix whatever is needed when you update your personal libraries to work with spice.

And the location of the anode is an issue, but a very minor one. Diodes in SOT-23 are very common, and also dual diodes in SOT-23 with a bunch of different combinations. I am already happy that the disambiguation of the location of pin 1 on a SOT-23 seems to have become an historical anecdote.

If a faulty combination of a diode symbol and a spice model was part of KiCadā€™s default libraries I would consider it a bug that needs fixing. But because there are a gazillion parts ā€œout thereā€ I do not have much faith in some rule of thumb of where the anode of a diode should be.

I have even seen examples of SMT leds from the same manufacturer which looked identical, but one LED had the anode marked, and the other had the cathode marked. I assume that somebody in the factory made a mistake, and they only discovered it after a million or so LEDā€™s had been made, and instead of throwing them away, they just made a new datasheet.

For me not specially.
But I think the less user traps in KiCad the better and we are here to make it better. Arenā€™t we?

If all diodes were reversed to K=1 then I suppose automatic filling of Pin Assignment should also follow this convention. I would be sure of my assumptions if I were using KiCad Spice for years and not since yesterday.

I suspect the pin assignments get reset when you changed the model? Though Iā€™m not at a computer so I canā€™t be sure about that.

Whether that is the most user friendly behavior is debatable, but I do think it is reasonable default.

For v7 we changed the sim diode symbol to have the cathode on pin 1 (like real diodes) and added the alternate pin ordering so spice sees the anode on pin1 like it expects. I think we also added the alternate pin ordering to all the ā€realā€ diode symbols, or at least the single diodes (duals, arrays, etc would need a model).

The idea was to avoid the backwards diode on your board footgun, and also to allow any of the diode symbols to be used for simulation. There should no longer be any real distinction between the sim diode and the real diodes (although I think we made sure the sim model is set up out of the box for the diode in the spice library)

Edit: yes there is a trap in that changing the spice model for any symbol deletes the alternate pin ordering. I donā€™t particularly like this behavior - you could raise an issue if you want, but I believe it is that way on purpose.

1 Like

When I changed for Default model to from file model it was reset to ā€œNot connectedā€.
When I selected file it was still ā€œNot connectedā€.
When I selected model it was filled like you see.

I think it was reasonable default when diode symbol for simulation had A=1 (I believe it was such in past). When all symbols have K=1 I think default should be reversed.
Not changed texts written (still A=1 K=2) on the right table side but the same texts written in reversed order or in diode symbols the order of filling table changed so when this is filled automatically it would be just OK.

I expected it but was not sure as never used Spice in KiCad.

May be for backward compatibility.
But it is also possible that it is not on purpose.
I will report it.

Edit:
I was directed to 9 month old report on the same subject so I added there my comment.

Diode and transistor pin numbers seem to be inconsistent between vendor datasheets. So I donā€™t think you need to get into simulation in order to encounter contradictory pin number information.

I have not gotten into NG Spice. I have used PSpice, PSIM, LTSpice, Simplis/Simetrix, TINA-TI. My first one was in Fortran Watfiv compiler, and have done sims in Excel and on a programmable calculator. I am not looking for another one! :frowning:

Of course this was known since before 5.1 but the ngspice developers failed to convince the library maintainers to add the field and most lead developers didnā€™t care before 7.99 started.

From what I remember, the argument for keeping the swapped diode in the ā€œSimulation_Spiceā€ was for maintaining compatibility with existing legacy schematics. And that was important in old KiCad versions because changing the library symbols would break all existing schematics.

Starting from KiCad V5 the project was independent from the libraries (First with the [Project]-cache.lib file), and from V6 onward, the symbols are fully integrated into the project, and that has now been around long enough to justify breaking compatibility with KiCad V4 or earlier. Also, if you care about your projects, you should archive them properly. I still have some memories of KiCad V3 and/or V4 and creating project specific libraries to make projects independent of the main libraries for archiving purposes. Back then there were also scripts to help with that.

It also looks like the Simulation_Spice library has gotten a big overhaul. It used to have much bigger (and ugly) resistor, capacitor and diode symbols for example. The resistor and capacitor have now been completely removed from the simulation library, transistors now have the same graphics as from the other default libraries. Voltage and other sources now have the same style as other KiCad libraries.

And also: Itā€™s a simulator :slight_smile: Start with a source, resistor, diode and GND reference for your fist simulation or just to verify you can get any simulation started, and whether the diode behaves as expected.

After that you can try to sort out the 12 variants of the BAT54. :slight_smile:

I would consider this being a bug.

This is indeed bad and unexpected behavior of Eeschema. The pin sequence and diode polarity have absolutely nothing to do with the model. Attaching a model (talking about a .model line, not a subcircuit) should not touch it, when I already have my circuit up and running! Pin sequence and diode polarity are only connected to the symbol and its polarity in my circuit. And this I did not change.

There is some discussion at Diode pin assignment error (#3216) Ā· Issues Ā· KiCad / KiCad Libraries / KiCad Symbols Ā· GitLab, but it seems to be the wrong issue tracker, as this is an Eeschema bug.

Fortunately I have never need to simulate real schematic of my PCB. My simulations were always a different schematics just to check something so I can have one BAT54 single diode model :slight_smile:
My symbol libraries for Spice will be separate libraries from real part libraries.