Electronic – LTspice: when I turn a schematic into a subcircuit it behaves differently. Why

ltspicesimulationspice

I'm trying to model a low frequency LED flasher based on a BEAM Pummer (basically a pair of CMOS inverters wired as an oscillator, plus a charge pump) in LTspice. I have the base flasher circuit attached to a voltage source and LED output, and it seems to be working correctly, producing ~40mA current spikes through the LED every ~2s or so.

But when I try to make a .subckt definition with the flasher part only, and include that in a test circuit, it doesn't work correctly: I get a noisy µA-level output through the led wired to the output pins for a few ns, then the oscillator locks up.

  • The SPICE error log reports Singular matrix: Check node d:u1:6#int1 Iteration No. 19 which doesn't show up with the standalone version. I'm not sure how to find node d:u1:6#int1.
  • My initial guess was that a GND connection wasn't being made properly, but I tried to pass a ground reference through an external pin several different ways and it didn't made any difference.
  • There's a quirk in that I need to use a PULSE voltage supply with 100% duty cycle rather than a steady DC voltage in the standalone version, or the oscillator won't start. Could this be related? Setting the test circuit's voltage to PULSE didn't seem to make any difference.

What else might I be doing wrong? I've triple checked the .subckt netlist pin order against the order defined in the symbol file, and I'm pretty sure it's correct. The docs tell me that GND should already be globally connected. Is it a startup thing? Two inverters are wired in a chain to make the oscillator, do I need to explicitly set the input of one to 5V and the other to 0V at startup?

For reference, there's a zip file here containing the test schematic and the .sub and .asy definitions, as well as the standalone version of the flasher subcircuit to prove that it does actually work.

Any help greatly appreciated!

Best Answer

To answer my own question: it seems LTspice requires text files to be saved with Windows Latin 1 code page, CRLF line endings. I'm using Wine on a Mac, and my text-editor saves as UTF-8 by default. I'm guessing LTspice misinterprets the UTF-8 µ on capacitor values as something invalid, but confusingly doesn't throw an error message.

Related Topic