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.
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.
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.
Here I should have specified hopefully the correct pin numbers.
BUT... when I then run the simulation, I get this wonderful 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:
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.