Digital logic
BetterSPICE has two kinds of digital parts. The simple gates below have no supply pins and switch at half their supply parameter. The logic families (74HC, 74LS, CD4000 and others) have real supply pins, real thresholds and output drive (Logic families). Both run in the same analogue simulation as the rest of the circuit, so edges have real rise times and real loading.
39.1Simple gates, flip-flop and counter
| Type | Key | Pins | Variants | Class |
|---|---|---|---|---|
not, and, or, nand, nor, xor, dff, counter4 (U) | library | not: in, out. Gates: in1, in2, out. dff: d, clk, q, qn. counter4: clk, q0 … q3 | none | approximate |
The supply is the parameter vdd. Outputs are referenced to ground behind rout. An input is high above vdd/2, with no hysteresis and no input current. Each output edge starts half a propagation delay after the input crosses and lasts one tpd. The D flip-flop samples d on the rising clock edge. The counter counts rising clock edges and wraps from 15 to 0. q0 is the least significant bit.
| Parameter | Key | Unit | Default | Range | Value comes from | What it does |
|---|---|---|---|---|---|---|
| Supply | vdd | V | 5 | > 0. Slider 1 to 15 V. | Default, inspector | High level and threshold basis. |
| Propagation delay | tpd | s | 10 ns | ≥ 0 | Default, inspector | |
| Output resistance | rout | Ω | 50 | > 0 | File or All parameters only |
Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.
39.2Flip-flops and latches (JK, T, D latch, SR latch)
| Type | Key | Pins | Variants | Class |
|---|---|---|---|---|
jkff, tff, dlatch, srlatch (U) | library | jkff: j, clk, k, set, rst, q, qn. tff: t, clk, set, rst, q, qn. dlatch: d, en, q, qn. srlatch: s, r, q, qn | none | approximate |
The same electrical model as the D flip-flop: the supply vdd, inputs high above vdd/2, outputs behind rout, each output edge half a propagation delay after the input and one tpd long. All four power up with q low.
The JK flip-flop acts on the rising clock edge: J and K both low hold, J high sets, K high resets, both high toggle. The T flip-flop toggles on the rising edge while t is high and holds while it is low. Both have an asynchronous set (S) and reset (R), active high. An open set or reset pin reads low, so it can stay unconnected. Set and reset together drive q and qn both high, as a 74xx part does, and the stored bit returns when they are released.
The D latch is transparent while en is high: q follows d. While en is low it holds. The SR latch is the pair of cross-coupled NOR gates: s sets, r resets, and with both low it holds. s and r both high is the forbidden input: q and qn are both low. The input released last wins. Released in the same instant, the latch settles reset. A real pair goes metastable there and can settle either way.
| Parameter | Key | Unit | Default | Range | Value comes from | What it does |
|---|---|---|---|---|---|---|
| Supply | vdd | V | 5 | > 0. Slider 1 to 15 V. | Default, inspector | High level and threshold basis. |
| Propagation delay | tpd | s | 10 ns | ≥ 0 | Default, inspector | |
| Output resistance | rout | Ω | 50 | > 0 | File or All parameters only |
Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.
39.3Logic families
The 74xx and 4000-series parts and the single gates with supply pins take their thresholds, output drive, delay and supply current from a logic family, chosen with the family parameter. Their outputs are driven from their own VCC and GND pins, so a weak supply or a long line shows up as it would on a board, and a supply outside the family's range warns W_SUPPLY.
| Family | Supply | Input low / high | Output R high / low | Edge | Delay | Quiescent | Inputs above VCC |
|---|---|---|---|---|---|---|---|
hc (default) | 2 to 6 V | 0.3 / 0.7 VCC | 50 / 40 Ω | 6 ns | 9 ns | 2 µA | clamped |
hct | 4.5 to 5.5 V | 0.8 / 2.0 V | 50 / 40 Ω | 6 ns | 12 ns | 2 µA | clamped |
ahc | 2 to 5.5 V | 0.3 / 0.7 VCC | 25 / 20 Ω | 3 ns | 5 ns | 2 µA | clamped |
lvc | 1.65 to 5.5 V | below 2.7 V: 0.35 / 0.65 VCC, else 0.8 / 2.0 V | 15 / 12 Ω | 2 ns | 4 ns | 1 µA | tolerant |
cd4000 | 3 to 18 V | 0.3 / 0.7 VDD | 500 Ω at 5 V | 50 ns | 100 ns | 1 µA | clamped |
ls | 4.75 to 5.25 V | 0.8 / 2.0 V | 100 / 25 Ω | 8 ns | 10 ns | 4 mA | tolerant |
Drive, edge and delay are taken at 5 V for parts with supply pins. Inputs have 3.5 pF and, unless the family is tolerant, clamp diodes to VCC and GND. Schmitt inputs (the 14 and 1G14, and the buf_st and inv_st gates, or any part with schmitt = 1) have a hysteresis of 0.15 VCC. Output changes come tpd after the input, and a glitch shorter than tpd is swallowed (inertial delay). Below the family's minimum supply the outputs release.
| Parameter | Key | Unit | Default | Range | Value comes from | What it does |
|---|---|---|---|---|---|---|
| Logic family | family | hc (cd4000 for 4017, 4040, 4060, 4511) | hc, hct, ahc, lvc, cd4000, ls | Default, inspector, part file | ||
| Propagation delay | tpd | s | from the family | ≥ 0 | Default, inspector, part file | |
| Supply (gates without supply pins) | vcc | V | 5 | > 0 | Default, inspector, part file | |
| Open drain | od | 0 / 1 | 0 | Default, inspector, part file | Outputs have no high side. | |
| Schmitt inputs | schmitt | 0 / 1 | 0 | Default, inspector, part file |
Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.
39.4Single gates
| Type | Pins | Variants | Class |
|---|---|---|---|
gate (U) | buf, inv, buf_st, inv_st: in, out. tri_buf, tri_inv: in, oe (active low), out. 2-input: in1, in2, out. 3, 4 and 8-input: in1 …, out. Variants ending _p add VCC, GND. | and2 to and8, nand2 to nand8, or2 to or8, nor2 to nor8, xor2, xnor2, buf, inv, buf_st, inv_st, tri_buf, tri_inv, each also with _p | approximate |
Placed with Alt+G. Without _p the gate is powered from its vcc parameter and switches relative to ground, with no clamps and no supply current.
39.574xx and 4000-series packages
| Type | Pins | Variants | Class |
|---|---|---|---|
logic (U) | The package pins in order, VCC and GND included. | see the table | approximate |
Placed with Alt+L. Every package simulates its full function, with its pins in package order.
| Variant | Function | Notes |
|---|---|---|
| 00, 08, 32, 86 | Quad 2-input NAND, AND, OR, XOR | |
| 02 | Quad 2-input NOR | |
| 04, 14 | Hex inverter, hex Schmitt inverter | |
| u04 | Hex unbuffered inverter (74HCU04) | A continuous high-gain stage (gain 20, rout 300 Ω) for crystal oscillators. Set from the file or an AI agent. |
| 125 | Quad tri-state buffer | nOE active low. |
| 74 | Dual D flip-flop with preset and clear | Clocks on the rising edge. |
| 138 | 3-to-8 decoder | Enabled with G1 high, nG2A and nG2B low. Outputs active low. |
| 151 | 8-to-1 multiplexer | Y and nW. |
| 157 | Quad 2-to-1 multiplexer | |
| 161 | 4-bit synchronous counter | Asynchronous clear, synchronous load, ENP and ENT, ripple carry. |
| 164 | 8-bit serial-in parallel-out shift register | Data = A AND B. |
| 165 | 8-bit parallel-in serial-out shift register | |
| 244 | Octal buffer, two enables | |
| 245 | Octal bus transceiver | DIR high: A to B. |
| 573 | Octal transparent latch | |
| 574 | Octal D flip-flop | |
| 595 | 8-bit shift register with output latch | SRCLK shifts, RCLK latches, QH' cascades. |
| 123 | Dual retriggerable monostable | The pulse width follows the external R and C, about 0.45 RC. |
| 4017 | Decade counter (Johnson) | CO high for counts 0 to 4. |
| 4040 | 12-stage ripple counter | Counts on the falling edge. |
| 4060 | 14-stage counter with oscillator | An RC or crystal around PHI, PHO and PHOB oscillates. |
| 4511 | BCD to 7-segment latch and decoder | Blanks above 9. |
| 1g00, 1g08, 1g32, 1g86 | Single NAND, AND, OR, XOR (SOT-23-5) | |
| 1g04, 1g14 | Single inverter, Schmitt inverter | |
| 1g125 | Single tri-state buffer |
- Open Counters and registers, a 74HC595 example, or wire a ctrl block to SER, SRCLK and RCLK of a 595 with LEDs on QA to QH.
- Open the logic analyzer and add QA to QH.
You should seeEach SRCLK edge shifts a bit in, and the LEDs change all at once on the RCLK edge.