Super simple astable not simulate in Ngspice

I draw a text book simple example of a basic astable oscillator
with 2 transistors.Using spice basic components inside Kicad and
BC546B spice model from

Collector resistances 1.5k, base resistances 15k, capacitors 100nF.
Supply voltage 6V. In a protoboard it works.
But Ngspice is unable to simulate.
Why?

This is not a very concise error description.

KiCad version, ngspice version?
Eeschema/ngspice result (answer by ngspice to your simulation input)?
ngspice netlist (post here as text): Eeschema → File → Export → Netlist… → Spice → Export Netlist

Oscillators are bistable circuits. Sometimes they just do not want starting the oscillation in a simulator because the internal noise is too low, in contrast to the real world.
Sometimes it is just helpful to simulate for a longer time, oscillation will start later.
Sometimes they might need a kick to start oscillating, e.g. a small dimple in the powersupply voltage, offered by a short one-time pulse.

In Simulation examples for KiCad/Eeschema/ngspice, after scrolling down a bit, you may find some oscillators.

One of the “problems” with spice is that “perfect symmetry” can be achieved. Resistors have their perfect nominal value without tolerances, BJT’s have exactly the same properties without production variations etc.

I’ve also struggled a few times with simulations, and I’m encountering so many problems that I’ve mostly given up. Apart from those things already stated. Have you verified that the rest of the schematic is properly defined for simulation? KiCad does not come with built in spice libraries. Are you sure your transistor models are actually working? Are you sure that ngSpice actually recognizes your schematic resistor as a resistor? Is power and GND handled correctly?

Several traps here. @paulvdh mentions an important one that’s very often overlooked: the 100% symmetry. You can probably overcome that by changing one of the resistor values.
Another is the model. I prefer to get mine from the manufacturers, they are usually the best and most up to date. nexperia.com is my first address.
Additionally: device pinout. SPICE (and ngspice) expects the following pinout sequence for discretes:
BJT: CBE
FET: DGS
I think it’s correct for BC546, but didn’t check. Otherwise use the “Alternate node sequence” in the model.

The simulator could easily be finding both transistors are saturated on and in a low gain state, so no oscillation build up

I don’t know Kicad version of Spice, but what I saw years ago is that making a working simulation in PCB Cad is not very intuitive, or easy to get working. LTspice LTspice Simulator | Analog Devices
is perhaps easier. At least it does not have PCB Cad in between.

LTSpice shows a slow starting up from both transistors ON over several cycles

I have no external libraries, astable started working without problems


Astable is an example which comes with Ltspice
Edit: A note: This is one of the first circuits I built years ago. Real circuit has one problem., BE diode of transistors gets reverse voltage spikes. If supply voltage is too high eventually one transistor will break. The other will be almost broken.

Do note that in the circuit LM21 posted a bit of asymmetry is added. R4 is 100k, while R3 is 101k Ohm.

2 Likes

And the transistors are not biased on that strongly, so linear operation is more likely

One more note. I think I have had resistors R3 and R4 connected to + power supply, and not to collector like here. Someone should simulate that circuit and check whether that would also work.

In the last hour I’ve been fiddling a bit and got something working in KiCad:

Edit: I’m feeling a bit silly about the Alternative Node Sequence not working. Holger (in post 23 of this thread) had the correct answer.

For me the asymmetry does not matter much. It’s mostly a difference in startup time of either 13ms or 24ms.

But getting anything to work in spice is always a struggle for me and lots of hurdles to overcome. The Spice model I used, I found on my SSD. in the location: ~/projects/kicad/spice/KiCad-Spice-Library/Models/Manufacturer/TRT-Electronics/2n3904.lib (Copied and zipped with the project below.)
You can also find 4 different spice models for this transistor on the Onsemi Website but those all have some copyright notice which confuses me. Why publish that data at all when it’s copyrighted, What does that copyright mean?

For example the “SP2 model”

**************************************
*      Model Generated by MODPEX     *
*Copyright(c) Symmetry Design Systems*
*         All Rights Reserved        *
*    UNPUBLISHED LICENSED SOFTWARE   *
*   Contains Proprietary Information *
*      Which is The Property of      *
*     SYMMETRY OR ITS LICENSORS      *
*Commercial Use or Resale Restricted *
*   by Symmetry License Agreement    *
**************************************
* Model generated on Aug 7, 01
* MODEL FORMAT: SPICE2
*$
.MODEL q2n3904 npn
+IS=1.26532e-10 BF=206.302 NF=1.5 VAF=1000
+IKF=0.0272221 ISE=2.30771e-09 NE=3.31052 BR=20.6302
+NR=2.89609 VAR=9.39809 IKR=0.272221 ISC=2.30771e-09
+NC=1.9876 RB=5.8376 IRB=50.3624 RBM=0.634251
+RE=0.0001 RC=2.65711 XTB=0.1 XTI=1
+EG=1.05 CJE=4.64214e-12 VJE=0.4 MJE=0.256227
+TF=4.19578e-10 XTF=0.906167 VTF=8.75418 ITF=0.0105823
+CJC=3.76961e-12 VJC=0.4 MJC=0.238109 XCJC=0.8
+FC=0.512134 CJS=0 VJS=0.75 MJS=0.5
+TR=6.82023e-08 PTF=0 KF=0 AF=1

At least it’s safe to say I have no commercial interest in this. But does it mean I can not sell my astable anymore? It’s a yucky world we live in.

Also note the transistors are upside down. I fiddled a bit with “alternate node sequence”, but (again) did not get that to work.

I’m also getting some weird stuff:

I’ve never been able to do anything useful with spice. I always bump into so many issues that I start second guessing whether the stuff I see in the simulation has any usable correlation with reality.

2022-11-22_astable.zip (7.7 KB)

Edit:
A new version with the transistors “normal side up” and a working Alternative Node Sequence.
I’ve also connected all 4 resistors to the power supply as is more common by the astable Multi Vibrator. It also starts immediately now with maybe just some asymmetry in the first cycle.

2022-11-22T23:06_astable.zip (8.1 KB)

If you publish something, you are the copyright owner of the published material. Even if you do not state this explicitely, it is enforced by national laws worldwide (and most national regulations are simular).

As the copyright owner you then have the right to issue a licence for using the published material. This license can be permissive or restrictive, this is up to you as the copyright owner.

There is one exception: If you explicitely put your published material into the ‘public domain’, then there is no copyright, and no restriction to its usage whatsoever.

For example: ngspice has as Copyright owners for its source code either UCB (University of California at Berkeley, the originator of spice) or the ngspice dev team for new material. Its licence is BSD 3-clause, a very permissive license.

The KiCad copyright ownwers are

 * Copyright (C) 2019 CERN
 * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.

and maybe some others, its software license is GPL.

For the above cited device model parameters the copyright owner is Symmetry Design Systems, the license is a 'Symmetry License Agreement (whatever that may be). Its major statement is the restriction for ‘Commercial Use or Resale’. And sometimes the legal texts seem to contain a little nonsense: Onsemi puiblished a model which is unpublished and contains proprietary information???

The major question in my view is here: Does this license allow re-publishing? Difficult to answer, and therefore KiCad is very restrictive when somebody asks: Why not distibute model parameters for simulation with KiCad.

How have your Astable sales been, lately?

That weird stuff is typical parasitic oscillation in emitter followers being driven from a negative impedance. It can be avoided by using base resistors.

image

Where has the comment gone about the weird schematic?
Connecting all 4 resistors to Vcc is indeed much more common:

I had just copied the schematic posted by LM21 without thinking much about it.

So that implies it’s actually impressive that ngSpice simulates it…

This seems to be working a lot more stable, even when setting R5 and R6 to zero.

The biggest remaining issue is that I can’t get the Alternate Node Sequence to work.

2022-11-22T19:21_astable.zip (8.2 KB)

Yes, but not surprising. It’s behaviour that’s not well known, but completely explainable.
Most people think emitter followers are pretty simple and harmless… they’re not. Make a note. :slight_smile:

It’s not an emitter follower, it’s an upside down transistor with the emitter and collector swapped so would have low h_fe. Surprising that it works at all unless ngspice is swapping the nodes again.

I didn’t notice until now.

As I wrote before in this thread:

ngSpice apparently expect the pins in CBE order