2

So... I'm trying to build an EMG sensor for biofeedback purposes, but I'm having loads of trouble both on the breadboard and on the CAD side as well. I'm using a M1-processor mac mini which could be a problem regarding ngspice.

Please note that I'm a newbie to circuit design, KiCad and SPICE simulation.

KiCad schematic

This is my circuit. If there's something blatantly wrong with it (besides not adding bypass caps, but I don't think I'll need them for simulation), I wouldn't really be surprised. The SPICE model for INA128 I'm using is from TI: https://www.ti.com/lit/zip/sbom764

The choice of INA128 is basically because it's the part I have, but most likely not the one I'll finally end up using. It's just a DIP-8 package that's easier to do on the breadboard.

noise and sine outputs

Now... if I remove the instamp complex from the schematic and just run the simulator, I get a nice noise and a nice noisy sine wave like I wanted.

If I understand the INA128 correctly, it has a gain of 1+50k/[gain resistor], which means putting a 47ohm resistor there should give me a gain of a bit more than 1000.

Alternate pin configs

Here I should have specified hopefully the correct pin numbers.

BUT... when I then run the simulation, I get this wonderful error:

ngspice error

Mind you, this is the same error I got when I tried to do ngspice's own example of working with an opamp: http://ngspice.sourceforge.net/ngspice-tutorial.html#OpAmp

A google told me that this has something to do with ngspice itself, so I finally managed to install ngspice via homebrew (don't get me started on xcode), saved the SPICE Netlist created by KiCad to a separate file:

KiCad SPICE Netlist

and ran ngspice from the command line, and got THIS wonderful message:

joonas@Celephais-2 SPICE files % ngspice instamp.cir 
Error opening code model "/opt/homebrew/Cellar/ngspice/36/lib/ngspice/spice2poly.cm": dlopen(/opt/homebrew/Cellar/ngspice/36/lib/ngspice/spice2poly.cm, 0x0002): tried: '/opt/homebrew/Cellar/ngspice/36/lib/ngspice/spice2poly.cm' (no such file), '/usr/local/lib/spice2poly.cm' (no such file), '/usr/lib/spice2poly.cm' (no such file)
Error: Library /opt/homebrew/Cellar/ngspice/36/lib/ngspice/spice2poly.cm couldn't be loaded!
Error opening code model "/opt/homebrew/Cellar/ngspice/36/lib/ngspice/analog.cm": dlopen(/opt/homebrew/Cellar/ngspice/36/lib/ngspice/analog.cm, 0x0002): tried: '/opt/homebrew/Cellar/ngspice/36/lib/ngspice/analog.cm' (no such file), '/usr/local/lib/analog.cm' (no such file), '/usr/lib/analog.cm' (no such file)
Error: Library /opt/homebrew/Cellar/ngspice/36/lib/ngspice/analog.cm couldn't be loaded!
Error opening code model "/opt/homebrew/Cellar/ngspice/36/lib/ngspice/digital.cm": dlopen(/opt/homebrew/Cellar/ngspice/36/lib/ngspice/digital.cm, 0x0002): tried: '/opt/homebrew/Cellar/ngspice/36/lib/ngspice/digital.cm' (no such file), '/usr/local/lib/digital.cm' (no such file), '/usr/lib/digital.cm' (no such file)
Error: Library /opt/homebrew/Cellar/ngspice/36/lib/ngspice/digital.cm couldn't be loaded!
Error opening code model "/opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtradev.cm": dlopen(/opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtradev.cm, 0x0002): tried: '/opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtradev.cm' (no such file), '/usr/local/lib/xtradev.cm' (no such file), '/usr/lib/xtradev.cm' (no such file)
Error: Library /opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtradev.cm couldn't be loaded!
Error opening code model "/opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtraevt.cm": dlopen(/opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtraevt.cm, 0x0002): tried: '/opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtraevt.cm' (no such file), '/usr/local/lib/xtraevt.cm' (no such file), '/usr/lib/xtraevt.cm' (no such file)
Error: Library /opt/homebrew/Cellar/ngspice/36/lib/ngspice/xtraevt.cm couldn't be loaded!
Error opening code model "/opt/homebrew/Cellar/ngspice/36/lib/ngspice/table.cm": dlopen(/opt/homebrew/Cellar/ngspice/36/lib/ngspice/table.cm, 0x0002): tried: '/opt/homebrew/Cellar/ngspice/36/lib/ngspice/table.cm' (no such file), '/usr/local/lib/table.cm' (no such file), '/usr/lib/table.cm' (no such file)
Error: Library /opt/homebrew/Cellar/ngspice/36/lib/ngspice/table.cm couldn't be loaded!
******
** ngspice-36 : Circuit level simulation program
** The U. C. Berkeley CAD Group
** Copyright 1985-1994, Regents of the University of California.
** Copyright 2001-2020, The ngspice team.
** Please get your ngspice manual from http://ngspice.sourceforge.net/docs.html
** Please file your bug-reports at http://ngspice.sourceforge.net/bugrep.html
******

No compatibility mode selected!

warning, model type mismatch in line
    s11 41 42 1 41 sp
warning, model type mismatch in line
    s12 4 43 1 41 sm
warning, model type mismatch in line
    s21 45 46 2 45 sp
warning, model type mismatch in line
    s22 4 47 2 45 sm

Circuit: KiCad schematic

Error on line 0 :
  a$poly$e.x1.x1.egnd %vd [ vcc 0 vee 0 ] %vd ( x1.x1.99 0 ) a$poly$e.x1.x1.egnd
 MIF-ERROR - unable to find definition of model a$poly$e.x1.x1.egnd
    Simulation interrupted due to error!

Now... this is also similar to the error I got when trying to run ngspice's opamp example from the command line and THAT I managed to get plotted using MacSpice... but that didn't help here:

MacSpice 32 -> source /Users/joonas/Documents/KiCad/SPICE\ files/instamp.cir

Circuit: .title KiCad schematic

Note: Found one or more Spice-2 'poly' devices; will convert to Spice-3
      'B' sources. Use 'listing physical expand' to check the result(s).
On line 6:
    v5 noise net-_v5-pad2_ trnoise(20u 0.5u 0 0)
    Error: Unknown parameter (trnoise).
On line 325 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    .model 1:1:jx pjf(is=15.00e-12 beta=31.58e-3 vto=-1)
    Missing level parameter - using level=1
On line 427 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    .model 1:2:jx pjf(is=15.00e-12 beta=31.58e-3 vto=-1)
    Missing level parameter - using level=1
On line 179 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    s:1:11 1:41 1:42 noise 1:41 1:sp 
    Warning: Unable to find model '1:sp' for this device - using default.
On line 185 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    s:1:12 vee 1:43 noise 1:41 1:sm 
    Warning: Unable to find model '1:sm' for this device - using default.
On line 193 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PS-- hit return for more, ? for help -- 
PICE_AIO/INA128.LIB" included at line 2:
    s:1:21 1:45 1:46 sine 1:45 1:sp 
    Warning: Unable to find model '1:sp' for this device - using default.
On line 199 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    s:1:22 vee 1:47 sine 1:45 1:sm 
    Warning: Unable to find model '1:sm' for this device - using default.
On line 215 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    .model 1:sp vswitch(ron=10 roff=100e3 von=.7 voff=1) 
    Error: Unknown model type vswitch - ignored.
On line 217 of "/Users/joonas/Documents/KiCad/Projects/EMG simulator/INA128_PSPICE_AIO/INA128.LIB" included at line 2:
    .model 1:sm vswitch(ron=10 roff=100e3 von=-.7 voff=-1)
    Error: Unknown model type vswitch - ignored.
MacSpice 33 -> run
On line 6:
    v5 noise net-_v5-pad2_ trnoise(20u 0.5u 0 0)
    Warning: Source 'v5' has no DC value specified, 0V assumed.
On line 5:
    v3 sine noise sin(0 100u 2k)
    Warning: Source 'v3' has no DC value specified, using value at transient time = 0s.
On line 24:
    .tran 10u 2m
    Warning: Unspecified TRAN parameter, TMAX will default to 4e-05s.
On line 24:
    .tran 10u 2m
    Warning: Basic iteration method failed to find operating point; iteration limit (100) exceeded.
    TRAN: initial timepoint: Trouble with node 'net-_r1-pad2_'.
    Note: Looking for operating point by Gmin stepping:
        Trying Gmin = 1.0000E-02  succeeded
        Trying Gmin = 1.0000E-03  succeeded
        Trying Gmin = 1.0000E-04  succeeded
        Trying Gmin = 1.0000E-05  failed
    TRAN: initial timepoint: Trouble with node 'net-_r1-pad1_'.
    Warning: Standard Gmin stepping failed.
    Note: Try 'set gminsteps = 1' to enable adaptive Gmin stepping.
    Note: Starting source stepping:
-- hit return for more, ? for help -- 
        DC sources scaled to   0.0000%  succeeded
        DC sources scaled to  10.0000%  failed
    Warning: Source stepping failed.
    Note: Try 'set srcsteps = 1' to enable adaptive source stepping algorithm.
    TRAN: initial timepoint: Trouble with node 'net-_r1-pad1_'.
Error: Iteration limit reached.
Error: run simulation(s) aborted.

To begin with, apparently MacSpice has trouble with trnoise. So what the bleep have I done wrong, is there any way to make this work (so if I've understood correctly I would get a sine-ish wave with peaks at +/- 100 mV at output)? I'd like to get the simulation working so I'd have at least some hope for making it work on the breadboard.

  • You have ideal 0 Ohm impedance for all sources which is unrealistic. – Tony Stewart EE75 Jan 24 '22 at 18:54
  • Thanks for pointing that out. It’s certainly something I would need to take into account when I actually get simulation working, but currently I don’t think setting impedance values would affect the main problem at hand. – Joonas Joensuu Jan 25 '22 at 16:19
  • In Falstad, this you can't even put two caps in parallel without a fault because dV/dt would make Ic infinite in circulating currents. A higher CM impedance permits better attenuation. I suggest you add some R now – Tony Stewart EE75 Jan 25 '22 at 16:32
  • So with Transmission Line theory applied to simulations, 0 Ohms differential merges even and odd mode impedances for CM analysis. I'm not sure but I see math or declaration faults with this. – Tony Stewart EE75 Jan 25 '22 at 16:40

2 Answers2

2

This seems to be a ngspice installation problem, when code models are not found. And you have to set the compatibility to "LTSPICE and PSPICE" in Eeschema or set ngbehavior=ltps in .spiceinit.

There may be a bug in the circuit, as the line

X1 noise sine VCC VEE output 0 Net-_R1-Pad1_ Net-_R1-Pad2_ INA128

only invokes the pure sine of V3 between + and - input. Changing it to

X1 0 sine VCC VEE output 0 Net-_R1-Pad1_ Net-_R1-Pad2_ INA128

will yield something like (ngspice-36, Windows 10) this plot:

output plot

Holger
  • 146
  • 1
  • 4
1

LTSpice

Got the Netlist running under LTspice, which I just needed to reinstall.

Edit: Apparently LTSpice processes noise simulation differently from ngspice, so that bit failed, but that's more related to ngspice and the instamp as such worked as expected.

  • 2
    If you need (white) noise in LTspice then you need a behavioural source with `V=white(time*x)*y`, where `x` means a minimum of twice the bandwidth of interest. The levels are -0.5 V ... 0.5 V, by default, so choose `y` appropriately. – a concerned citizen Jan 25 '22 at 17:57