How do I simulate a 74LS74 FlipFlop using NGSPICE 41?

Is there a basic circuit that uses the 74LS74 flip flop that I can explore. I just want to understand the basic simulator setup (using 2 units of the 74LS74) and how to apply a digital stimulus and show the output. I see the multi.lib and the dig000_excerpt.lib in the properties of the 74LS74 symbols but dont know if I need to include these libraries in my own project and why. Thanks.

PS I’m particularly interested in using the V7.99 nightly version as it supports V41 of ngspice.

This forum has some threads with lots of ngSpice examples, including the 74ls74:

That’s were the discussion has started.

The idea might be to do a step-by-step setup of such a simulation project.

However the simulator does not tell you what to simulate. So you have to provide a circuit idea, and then the resulting circuit diagram.

I have something in mind. I will post a schematic during the week or next weekend. Thanks.

74LS is bipolar low power schottky logic. Do you really want that?

I have not used NGSPICE but I have encountered difficulty in other simulators with trying to include digital ICs in analog circuits. Simply put, I do not think that there are so many analog models out there for digital ICs. I am discussing what used to be called “Small Scale Integration”. Certainly a gate or inverter would be included, and probably a flip flop as well. I have some general interest in this topic.

For example, if you make a simple oscillator with a single schmitt trigger inverter (at least the one that I tried) it turns out to be a power hog, even if the oscillation frequency is low. I think this was a 74HC part. I think the input stage draws high current when the input voltage is in or near the transition zone. I have such an oscillator on a test board, and it draws 15 - 20 mA when running on 5V. That power level will not fry an egg, but it will cause a SOT-23 chip to run noticeably warm and is probably not a good design just for that reason alone.

Here is an example circuit.
PortusHaywoodDecoder_Divider.kicad_sch (64.6 KB)
I’m using 7.99 nightly version and the schematic is imported from Altium designer.
I’ve not made any attempts to set the schematic up for any simulation yet as It took me a while to just do the schematic in Altium. The actual import into kicad was trouble free.

What a horrible divider.
But why do you use 74LSxx parts? It’s a logic family that’s practically dead and buried. These days, 74HCxx is the standard.

Why is it horrible? How can it be improved? I’m only interested in how ngspice can be used to simulate a d type flip flop. A 74HC74 can easily be substituted in the REAL circuit if it can be of benefit. It’s used in this context.
PortusHaywoodForQSPICE.pdf (194.8 KB)

My apologies. I have an allergic reaction to “ripple counters”, which yours is.
This is the better solution:

Ah, understand better now having followed your link.
You’re analyzing a 1979 circuit from “wireless World”. Ignore my previous post, please.

There is now some action required (don’t be frightened, just do it step by step):


Add spice power supply (VDC source from Simulation_Spice library).

Define input, add input supply for DIVIDER (PULSE source) and TP2 (VDC or PULSE source).

Find and attach 2N3904 transistor models (not all models from the web are functionable!).

Add and attach 7474 subcircuit (to allow dual 7474 in one footprint/package).
Find and attach 7474 model (for both see More simulation examples for KiCad/Eeschema/ngspice - #3 by holger or Spice models and model parameters for ngspice circuit simulator).

Add value from ALTIUM_VALUE to VALUE fileds (in Symbol Properties window) for each resistor and capacitor.

Add load resistors 10Meg to the outputs Q1 and Q2 (and its inverted ones) invers, to get analog signals for plotting.

Add .param vcc=5 into a text box to enable 5V operation of 7474.

Provide adequate simulator settings:
(no current or power measurements, ltps compatibility, tran with timing according to DIVIDER input).

This is the current status: KiCad 8, ngspice-42, 74HC74 model from,
digi7474.7z (7.9 KB),
simulation time 14 ms.


I have a question, I need a FlipFlop (not a 74LS74 (the cd4013)) which is essentially identical to yours but instead of having reverse Set and Reset they are normal, that means at low, they allow data to write to click, and at high, they activate the set and reset functionality.
I wanted to see if it was within my abilities to edit this simple thing.

and the spice code follows:

+     optional:  DPWR=$G_DPWR DGND=$G_DGND
+     params:  MNTYMXDLY=0 IO_LEVEL=0
.model DLY_HC74 ueff(tppcqlhTY=20ns tppcqlhMX=46ns tppcqhlTY=20ns
+                 tppcqhlMX=46ns twpclMN=25ns
+                 tpclkqlhTY=20ns tpclkqlhMX=35ns tpclkqhlTY=20ns
+                 tpclkqhlMX=35ns twclkhMN=20ns twclklMN=20ns
+                 tsudclkMN=25ns tsupcclkhMN=6ns)
.ENDS 74HC74

Which is quite a mouthful but I have no idea how to invert these (besides using a cmos inverter but that is overkill)

Edit: Under closer inspection it seems set and reset are not implemented for 74HC74, anyway. Which is a shame because I wanted to simulate a circuit that implements this functionality

Why do you think so? Why not test it?

Please have a look at and search for cd4013. In I have described how to then create a model suitable for the symbol (if there is any).

For editing the U devices you might have a look at a PSPICE manual. Or post such a question at the ngspice Sourceforge users’ discussion forum.

Oh, 1PREBAR 1CLRBAR flew over my head, I didn’t think

I see the model is DLY_HC74 is there a way to see all inner models in ngspice, so I can find the best match for my d latch without inverted set/reset