Practical case: CMOS linear amplifier

CMOS linear amplifier prototype (Maker Style)

Level: Advanced. Configure a 74HC04 inverter as a Class A linear analog amplifier using negative feedback.

Objective and use case

You will construct a single-stage voltage amplifier using one inverter gate from a 74HC04 IC, biased into its linear region via a feedback resistor. This configuration forces the digital gate to act as an analog inverting amplifier for small AC signals.

Why it is useful:
* Internal structure analysis: Demonstrates that digital logic gates are constructed from analog transistors (MOSFETs) and possess an active linear region.
* Crystal oscillators: This topology is the fundamental building block for Pierce oscillators used in clock generation.
* Low-cost amplification: Provides a simple, cheap high-impedance amplifier for piezoelectric sensors or microphones without requiring a dedicated Op-Amp.
* Signal buffering: Can be used to square up «lazy» analog edges into sharp digital pulses if the feedback is adjusted.

Expected outcome:
* Self-biasing: The input and output DC voltage settles automatically at approximately VCC / 2 (e.g., ~2.5 V).
* Amplification: An input sine wave of 50 mVpp results in an amplified inverted output sine wave.
* Linearity: The output signal replicates the input shape without clipping (provided the input signal remains small).

Target audience and level:
Electronic engineering students and analog system designers (Level: Advanced).

Materials

  • U1: 74HC04 (Hex Inverter), function: active amplification element.
  • Rf: 1 MΩ resistor, function: negative feedback for DC biasing (Class A operation).
  • Cin: 100 nF ceramic capacitor, function: AC coupling for input signal.
  • Cout: 10 µF electrolytic capacitor, function: AC coupling for load.
  • RL: 10 kΩ resistor, function: output load simulation.
  • V1: 5 V DC supply, function: main power source.
  • V_SIG: Signal generator, function: 1 kHz sine wave, 50 mVpp (with 0 V DC offset).

Pin-out of the IC used

Chip: 74HC04 (Hex Inverter)

Pin Name Logic function Connection in this case
1 1 A Inverter 1 Input Connected to GATE_IN
2 1Y Inverter 1 Output Connected to GATE_OUT
7 GND Ground Connected to 0 (GND)
14 VCC Power Supply Connected to VCC
3,5,9,11,13 Inputs Unused Inputs Connect to 0 (GND) to prevent oscillation

Wiring guide

  • V1: Positive terminal to VCC, negative terminal to 0.
  • U1: Pin 14 to VCC, Pin 7 to 0.
  • Unused Inputs: U1 pins 3, 5, 9, 11, 13 to 0 (Essential for stability).
  • Rf: Connect between GATE_IN (Pin 1) and GATE_OUT (Pin 2).
  • Cin: Connect between VIN_AC (Signal Generator output) and GATE_IN.
  • U1 Gate: Pin 1 to GATE_IN, Pin 2 to GATE_OUT.
  • Cout: Positive terminal to GATE_OUT, negative terminal to VOUT_LOAD.
  • RL: Connect between VOUT_LOAD and 0.
  • V_SIG: Output to VIN_AC, Ground to 0.

Conceptual block diagram

Conceptual block diagram — 74HC04 NOT gate
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

Practical case: CMOS linear amplifier

                                            (Feedback Loop)
                                  .-----------[ Rf: 1 MΩ ]------------.
                                  |                                   |
                                  V                                   |
[ V_SIG ] --(Signal)--> [ Cin: 100nF ] --(Pin 1)--> [ U1: 74HC04 ] --(Pin 2)--> [ Cout: 10µF ] --> [ RL: 10 kΩ ] --> GND
                                                          ^
                                                          |
                                                 [ Power: 5 V / GND ]
                                                 [ Unused Pins: 0 V ]
Electrical Schematic

Truth table

Although operated as an analog amplifier, the 74HC04 maintains its digital truth table logic if driven rail-to-rail.

Input (A) Output (Y)
L (0 V) H (5 V)
H (5 V) L (0 V)

Measurements and tests

  1. DC Bias Check:

    • Disconnect V_SIG temporarily.
    • Measure the DC voltage at GATE_IN and GATE_OUT.
    • Validation: Both should measure approximately VCC / 2 (around 2.5 V). This confirms the feedback resistor Rf has correctly biased the inverter into the transition region.
  2. AC Gain Measurement:

    • Reconnect V_SIG (1 kHz, sine, 50 mVpp).
    • Use an oscilloscope to observe Channel 1 at VIN_AC and Channel 2 at GATE_OUT.
    • Validation: Calculate Voltage Gain Av = Voutpp / Vinpp. You should observe an inverted sine wave with significant gain (typically 10x to 100x depending on the specific manufacturer of the 74HC04).
  3. Linearity Limit:

    • Slowly increase the amplitude of V_SIG.
    • Validation: Observe the point where the output sine wave flattens at the top (near 5 V) and bottom (near 0 V). This is the dynamic range limit.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: CMOS linear amplifier
* 74HC04 Hex Inverter Linear Amplifier Configuration

* --- Power Supply ---
* V1: 5V DC supply
V1 VCC 0 DC 5

* --- Signal Generator ---
* V_SIG: 1 kHz sine wave, 50 mVpp (25 mV amplitude), 0 V DC offset
V_SIG VIN_AC 0 SIN(0 25m 1k)

* --- Components ---

* Cin: 100 nF ceramic capacitor for AC coupling input
Cin VIN_AC GATE_IN 100n

* Rf: 1 MΩ resistor for negative feedback (DC biasing)
Rf GATE_IN GATE_OUT 1Meg

* U1: 74HC04 Hex Inverter
* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: CMOS linear amplifier
* 74HC04 Hex Inverter Linear Amplifier Configuration

* --- Power Supply ---
* V1: 5V DC supply
V1 VCC 0 DC 5

* --- Signal Generator ---
* V_SIG: 1 kHz sine wave, 50 mVpp (25 mV amplitude), 0 V DC offset
V_SIG VIN_AC 0 SIN(0 25m 1k)

* --- Components ---

* Cin: 100 nF ceramic capacitor for AC coupling input
Cin VIN_AC GATE_IN 100n

* Rf: 1 MΩ resistor for negative feedback (DC biasing)
Rf GATE_IN GATE_OUT 1Meg

* U1: 74HC04 Hex Inverter
* Instantiated as a subcircuit to strictly follow pinout and wiring guide.
* Pinout: 1=1A, 2=1Y, 3=2A, 4=2Y, 5=3A, 6=3Y, 7=GND, 8=4Y, 9=4A, 10=5Y, 11=5A, 12=6Y, 13=6A, 14=VCC
* Connected: Pin 1->GATE_IN, Pin 2->GATE_OUT, Pin 7->0, Pin 14->VCC
* Unused Inputs (3, 5, 9, 11, 13) connected to 0 (Ground).
* Unused Outputs (4, 6, 8, 10, 12) left as floating nodes (NC_x).
XU1 GATE_IN GATE_OUT 0 NC_2 0 NC_3 0 NC_4 0 NC_5 0 NC_6 0 VCC 74HC04

* Cout: 10 µF electrolytic capacitor for AC coupling load
* Connected from GATE_OUT (approx 2.5V DC) to VOUT_LOAD (0V DC)
Cout GATE_OUT VOUT_LOAD 10u

* RL: 10 kΩ load resistor
RL VOUT_LOAD 0 10k

* --- Subcircuit Models ---

* Subcircuit for 74HC04 Hex Inverter
* Implements 6 inverters using robust continuous behavioral sources (tanh).
* Model assumes Vth = VCC/2.
* Gain factor 100 used to approximate open-loop gain in linear region (~250) while ensuring convergence.
.subckt 74HC04 1 2 3 4 5 6 7 8 9 10 11 12 13 14
* Pin 14 = VCC, Pin 7 = GND
* Inverter 1 (1A->1Y)
B1 2 7 V = V(14,7)/2 + (V(14,7)/2) * tanh(100 * (V(14,7)/2 - V(1,7)))
* Inverter 2 (2A->2Y)
B2 4 7 V = V(14,7)/2 + (V(14,7)/2) * tanh(100 * (V(14,7)/2 - V(3,7)))
* Inverter 3 (3A->3Y)
B3 6 7 V = V(14,7)/2 + (V(14,7)/2) * tanh(100 * (V(14,7)/2 - V(5,7)))
* Inverter 4 (4A->4Y) - Note: Pin 9 is Input, Pin 8 is Output
B4 8 7 V = V(14,7)/2 + (V(14,7)/2) * tanh(100 * (V(14,7)/2 - V(9,7)))
* Inverter 5 (5A->5Y) - Note: Pin 11 is Input, Pin 10 is Output
B5 10 7 V = V(14,7)/2 + (V(14,7)/2) * tanh(100 * (V(14,7)/2 - V(11,7)))
* Inverter 6 (6A->6Y) - Note: Pin 13 is Input, Pin 12 is Output
B6 12 7 V = V(14,7)/2 + (V(14,7)/2) * tanh(100 * (V(14,7)/2 - V(13,7)))
.ends

* --- Analysis Directives ---
* Transient analysis: 5 ms duration to capture multiple 1 kHz cycles.
.tran 10u 5m

* Output variables for batch processing
* INPUT: VIN_AC, OUTPUT: VOUT_LOAD
.print tran V(VIN_AC) V(VOUT_LOAD) V(GATE_IN) V(GATE_OUT)

.op
.end
* --- GPT review (BOM/Wiring/SPICE) ---
* circuit_ok=true
* simulation_summary: The simulation shows a functional inverting amplifier. The input signal (VIN_AC) is a ~25mV amplitude sine wave. The output (VOUT_LOAD) is an inverted sine wave with an amplitude of approximately 2.4V to 2.5V, indicating a very high gain that is causing significant clipping/saturation near the rails (approx +/- 2.5V swing). The DC bias point at GATE_IN and GATE_OUT settles near 2.5V (VCC/2) as expected for this self-biasing topology.
* bom_vs_spice equivalences ignored:
*   - U1 (74HC04) is modeled as a subcircuit using continuous behavioral voltage sources (tanh functions) to approximate the analog transfer curve of CMOS inverters.
* overall_comment: The circuit is a classic example of using a digital CMOS inverter as a linear class A amplifier. The netlist correctly implements the self-biasing scheme (Rf feedback) and AC coupling. The simulation results confirm the high open-loop gain of the HC series inverter, resulting in a heavily clipped output for a 50mVpp input. As a didactic example, it effectively demonstrates the concept, though a teacher might want to reduce the input amplitude or add an input series resistor to reduce the gain if a cleaner sine wave is desired.
* --------------------------------------

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)

Analysis: The simulation shows a functional inverting amplifier. The input signal (VIN_AC) is a ~25mV amplitude sine wave. The output (VOUT_LOAD) is an inverted sine wave with an amplitude of approximately 2.4V to 2.5V, indicating a very high gain that is causing significant clipping/saturation near the rails (approx +/- 2.5V swing). The DC bias point at GATE_IN and GATE_OUT settles near 2.5V (VCC/2) as expected for this self-biasing topology.
Show raw data table (508 rows)
Index   time            v(vin_ac)       v(vout_load)    v(gate_in)      v(gate_out)
0	0.000000e+00	0.000000e+00	0.000000e+00	2.500000e+00	2.500000e+00
1	1.000000e-07	1.570796e-05	-3.92600e-03	2.500016e+00	2.496074e+00
2	2.000000e-07	3.141592e-05	-7.85100e-03	2.500031e+00	2.492149e+00
3	4.000000e-07	6.283179e-05	-1.56989e-02	2.500063e+00	2.484301e+00
4	8.000000e-07	1.256632e-04	-3.13823e-02	2.500126e+00	2.468618e+00
5	1.600000e-06	2.513232e-04	-6.26967e-02	2.500251e+00	2.437303e+00
6	3.200000e-06	5.026210e-04	-1.25097e-01	2.500501e+00	2.374901e+00
7	6.400000e-06	1.005039e-03	-2.48425e-01	2.500997e+00	2.251567e+00
8	1.280000e-05	2.008453e-03	-4.87825e-01	2.501977e+00	2.012143e+00
9	2.280000e-05	3.569178e-03	-8.34430e-01	2.503471e+00	1.665472e+00
10	3.280000e-05	5.115818e-03	-1.13904e+00	2.504919e+00	1.360762e+00
11	4.280000e-05	6.642268e-03	-1.39785e+00	2.506318e+00	1.101832e+00
12	5.280000e-05	8.142504e-03	-1.61199e+00	2.507667e+00	8.875322e-01
13	6.280000e-05	9.610606e-03	-1.78571e+00	2.508964e+00	7.136492e-01
14	7.280000e-05	1.104078e-02	-1.92461e+00	2.510208e+00	5.745580e-01
15	8.280000e-05	1.242738e-02	-2.03459e+00	2.511395e+00	4.643784e-01
16	9.280000e-05	1.376493e-02	-2.12112e+00	2.512524e+00	3.776434e-01
17	1.028000e-04	1.504816e-02	-2.18894e+00	2.513590e+00	3.096072e-01
18	1.128000e-04	1.627201e-02	-2.24200e+00	2.514591e+00	2.563270e-01
19	1.228000e-04	1.743163e-02	-2.28348e+00	2.515522e+00	2.146211e-01
20	1.328000e-04	1.852246e-02	-2.31590e+00	2.516381e+00	1.819734e-01
21	1.428000e-04	1.954019e-02	-2.34122e+00	2.517164e+00	1.564217e-01
22	1.528000e-04	2.048080e-02	-2.36095e+00	2.517868e+00	1.364514e-01
23	1.628000e-04	2.134059e-02	-2.37626e+00	2.518489e+00	1.209036e-01
... (484 more rows) ...

Common mistakes and how to avoid them

  1. Using the wrong logic family: Students often use 74LS04 or 74HCT04. These have internal pull-ups or different input thresholds that prevent symmetrical linear biasing. Solution: Ensure you use the 74HC04 (CMOS) or CD4069UB.
  2. Input signal too large: Applying a standard TTL/CMOS logic signal (0-5 V) will result in a square wave output, not amplification. Solution: Keep the input signal small (under 100 mVpp) to stay within the linear region.
  3. Floating unused inputs: Leaving pins 3, 5, 9, etc., disconnected causes internal noise and excessive power consumption. Solution: Always tie unused inputs of CMOS chips to Ground (0).

Troubleshooting

  • Symptom: Output is stuck at 0 V or 5 V.
    • Cause: Feedback resistor Rf is missing or open circuit.
    • Fix: Check continuity of Rf (1 MΩ). It is required to pull the input voltage to the tipping point.
  • Symptom: High frequency noise superimposed on the signal.
    • Cause: Parasitic oscillation due to high gain and stray capacitance.
    • Fix: Shorten wires or add a small capacitor (e.g., 10 pF) in parallel with Rf to reduce bandwidth.
  • Symptom: Gain is very low ($< 2$).
    • Cause: Load resistance RL is too small.
    • Fix: The output impedance of a 74HC04 in linear mode is relatively high. Increase RL to 100 kΩ or remove it for testing.

Possible improvements and extensions

  1. Crystal Oscillator: Replace the signal generator with a quartz crystal and two load capacitors (to ground) at the input and output pins to create a stable clock source.
  2. Cascaded Amplifier: Connect the output of the first stage (via a capacitor) to a second identically configured 74HC04 stage to achieve much higher total voltage gain.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary function of the feedback resistor in this circuit configuration?




Question 2: In this self-biasing configuration, what is the expected DC voltage at the input and output (assuming a 5 V supply)?




Question 3: Which internal components of the 74HC04 allow it to function as an analog amplifier?




Question 4: This linear inverter topology is the fundamental building block for which common circuit?




Question 5: When configured with negative feedback, the inverter operates as which class of amplifier?




Question 6: What is the phase relationship between the AC input signal and the amplified output signal?




Question 7: What is a key advantage of this configuration regarding the input impedance?




Question 8: To maintain linear operation without clipping, how should the input signal be characterized?




Question 9: Besides amplification, what other use case is mentioned for this circuit topology?




Question 10: Why is the 74HC04 specifically capable of this operation?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Ring Oscillator and Delay

Ring Oscillator and Delay prototype (Maker Style)

Level: Advanced — Build and analyze a 5-stage ring oscillator to calculate component propagation delay.

Objective and use case

In this case, you will construct a ring oscillator by cascading an odd number (5) of NOT gates (inverters) in a closed feedback loop using a 74HC04 IC. You will measure the resulting oscillation frequency to calculate the intrinsic propagation delay of the logic gates.

Why it is useful:
* Process characterization: Used in semiconductor manufacturing to test the speed and quality of silicon wafers.
* Clock generation: Fundamental topology for generating internal clocks in ASICs and FPGAs.
* Random Number Generation: The inherent jitter in ring oscillators is a source of entropy for True Random Number Generators (TRNG).
* Time-to-Digital Converters (TDC): Used to measure time intervals with high precision.

Expected outcome:
* A stable square wave output oscillating in the MHz range (typically 20 MHz–50 MHz for 74HC logic on a breadboard).
* Measurement of oscillation frequency (fosc).
* Calculation of the average propagation delay (tpd) per gate.
* Visual observation of rise (tr) and fall (tf) times due to capacitive loading.

Target audience and level:
Advanced Electronics Students; Engineering Undergraduates.

Materials

  • U1: 74HC04 Hex Inverter IC, function: logic gates for the ring
  • C1: 100 nF ceramic capacitor, function: power supply decoupling (critical for stability)
  • C2: 10 pF capacitor, function: simulated load (optional, represents probe capacitance)
  • V1: 5 V DC supply
  • W1-W5: Jumper wires, function: inter-stage connections

Pin-out of the IC used

Selected Chip: 74HC04 (Hex Inverter)

Pin Name Logic function Connection in this case
1 1 A Input 1 From Output 5 (Node N5)
2 1Y Output 1 To Input 2 (Node N1)
3 2 A Input 2 From Output 1 (Node N1)
4 2Y Output 2 To Input 3 (Node N2)
5 3 A Input 3 From Output 2 (Node N2)
6 3Y Output 3 To Input 4 (Node N3)
7 GND Ground Connect to Node 0
8 4Y Output 4 To Input 5 (Node N4)
9 4 A Input 4 From Output 3 (Node N3)
10 5Y Output 5 To Input 1 (Node N5 – Feedback)
11 5 A Input 5 From Output 4 (Node N4)
14 VCC Power Supply Connect to Node VCC (+5 V)

Note: Pins 12 (6Y) and 13 (6 A) are unused and should be left open or tied to GND/VCC depending on specific noise requirements, though for this test leaving them open is acceptable.

Wiring guide

This circuit relies on minimal trace length to sustain high-frequency oscillation.

  • V1 connects between node VCC and node 0 (GND).
  • C1 connects between node VCC and node 0 (place physically close to U1).
  • U1 (Pin 14) connects to node VCC.
  • U1 (Pin 7) connects to node 0.
  • U1 (Pin 1 – Input 1) connects to node N5 (Feedback loop closure).
  • U1 (Pin 2 – Output 1) connects to node N1.
  • U1 (Pin 3 – Input 2) connects to node N1.
  • U1 (Pin 4 – Output 2) connects to node N2.
  • U1 (Pin 5 – Input 3) connects to node N2.
  • U1 (Pin 6 – Output 3) connects to node N3.
  • U1 (Pin 9 – Input 4) connects to node N3.
  • U1 (Pin 8 – Output 4) connects to node N4.
  • U1 (Pin 11 – Input 5) connects to node N4.
  • U1 (Pin 10 – Output 5) connects to node N5.
  • C2 (Optional Load) connects between node N5 and node 0 to simulate probe capacitance.

Conceptual block diagram

Conceptual block diagram — 74HC04 NOT gate
Quick read: inputs → main block → output (actuator or measurement). This summarizes the ASCII schematic below.

Schematic

POWER SUPPLY & DECOUPLING:
      VCC (5 V) --> [ Node VCC ] --(Pin 14)--> [ U1: 74HC04 Power ]
                      |
                    [ C1: 100nF ]
                      |
      GND (0 V) --> [ Node 0 ] --(Pin 7)---> [ U1: 74HC04 GND ]


SIGNAL FLOW (RING OSCILLATOR):
(Logic flows Left to Right, wrapping around at the end)

      [ Feedback N5 ] --> [ U1: Gate 1 ] --(Node N1)--> [ U1: Gate 2 ] --(Node N2)--> [ U1: Gate 3 ] --(Node N3)--> \
      (Input Pin 1)       (In:1 / Out:2)                (In:3 / Out:4)                (In:5 / Out:6)                |
                                                                                                                    |
      /-------------------------------------------------------------------------------------------------------------/
      |
      \--> [ U1: Gate 4 ] --(Node N4)--> [ U1: Gate 5 ] --(Node N5)--> [ C2: 10pF ] --> GND
           (In:9 / Out:8)                (In:11 / Out:10)      |
                                                               |
                                                      (Loop back to Start)
Electrical Schematic

Truth table (Single NOT Gate)

Input (A) Output (Y)
L H
H L

In a ring configuration with an odd number of stages, the logic never settles, causing perpetual oscillation.

Measurements and tests

  1. Setup: Ensure wiring is short and neat. Long wires add parasitic inductance and capacitance which will significantly lower the frequency.
  2. Visualization: Connect an oscilloscope probe (x10 attenuation recommended to reduce loading) to Node N5 (or any node N1 through N4).
  3. Frequency Measurement: Measure the frequency of the oscillation (fosc). For a 74HC series at 5 V, expect approx 20MHz – 40MHz depending on stray capacitance.
  4. Propagation Delay Calculation: Calculate the average propagation delay per gate (tpd) using the formula:
    $tpd = (1 / (2 × N × fosc))$
    Where $N = 5$ (number of stages).
    Example: If $f_{osc} = 25 MHz$, then $T = 40 ns$. $t_{pd} = 40 ns / 10 = 4 ns$.
  5. Waveform Analysis: Zoom in on the edges. Notice that the wave is not a perfect square; the rise time ($t_{r}$) and fall time ($t_{f}$) are visible due to the capacitive charging of the next gate’s input.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: Ring Oscillator and Delay
.width out=256
* Ngspice Netlist

* --- Power Supply ---
* V1: 5 V DC supply connecting VCC to GND (0)
V1 VCC 0 DC 5

* --- Decoupling Capacitor ---
* C1: 100 nF ceramic capacitor, power supply decoupling
C1 VCC 0 100n

* --- Integrated Circuit U1: 74HC04 Hex Inverter ---
* Modeled as a subcircuit to strictly follow physical pinout and wiring guide.
* Pin Mapping (Standard DIP-14):
* 1:1A  2:1Y  3:2A  4:2Y  5:3A  6:3Y  7:GND
* 8:4Y  9:4A 10:5Y 11:5A 12:6Y 13:6A 14:VCC
*
* Wiring Connections based on Guide:
* Pin 1 (In1)  -> N5
* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: Ring Oscillator and Delay
.width out=256
* Ngspice Netlist

* --- Power Supply ---
* V1: 5 V DC supply connecting VCC to GND (0)
V1 VCC 0 DC 5

* --- Decoupling Capacitor ---
* C1: 100 nF ceramic capacitor, power supply decoupling
C1 VCC 0 100n

* --- Integrated Circuit U1: 74HC04 Hex Inverter ---
* Modeled as a subcircuit to strictly follow physical pinout and wiring guide.
* Pin Mapping (Standard DIP-14):
* 1:1A  2:1Y  3:2A  4:2Y  5:3A  6:3Y  7:GND
* 8:4Y  9:4A 10:5Y 11:5A 12:6Y 13:6A 14:VCC
*
* Wiring Connections based on Guide:
* Pin 1 (In1)  -> N5
* Pin 2 (Out1) -> N1
* Pin 3 (In2)  -> N1
* Pin 4 (Out2) -> N2
* Pin 5 (In3)  -> N2
* Pin 6 (Out3) -> N3
* Pin 7 (GND)  -> 0
* Pin 8 (Out4) -> N4
* Pin 9 (In4)  -> N3
* Pin 10 (Out5)-> N5
* Pin 11 (In5) -> N4
* Pin 12 (Out6)-> NC_OUT (Unused)
* Pin 13 (In6) -> NC_IN  (Unused)
* Pin 14 (VCC) -> VCC

XU1 N5 N1 N1 N2 N2 N3 0 N4 N3 N5 N4 NC_OUT NC_IN VCC 74HC04

* --- Load Capacitor ---
* C2: 10 pF capacitor, simulated load on Output Node N5
C2 N5 0 10p

* --- Unused Pin Termination ---
* High resistance to ground to prevent floating node errors
R_NC1 NC_OUT 0 1G
R_NC2 NC_IN 0 1G

* --- Subcircuit Definitions ---

.subckt 74HC04 1 2 3 4 5 6 7 8 9 10 11 12 13 14
    * Local Power: 14=VCC, 7=GND
    * Gate 1
    X1 1 2 14 7 inv_gate
    * Gate 2
    X2 3 4 14 7 inv_gate
    * Gate 3
    X3 5 6 14 7 inv_gate
    * Gate 4 (Note: Pin 9 is Input, Pin 8 is Output)
    X4 9 8 14 7 inv_gate
    * Gate 5 (Note: Pin 11 is Input, Pin 10 is Output)
    X5 11 10 14 7 inv_gate
    * Gate 6 (Unused)
    X6 13 12 14 7 inv_gate
.ends

.subckt inv_gate in out vcc gnd
    * Internal RC Delay Stage
    * Essential for Ring Oscillator simulation to function (creates phase shift)
    * R=1k, C=10p yields approx 10ns delay per stage
    R_delay in int 1k
    C_delay int gnd 10p
    
    * Behavioral Voltage Source (Sigmoid Inverter)
    * Uses continuous function for convergence: Vout = Vcc / (1 + exp(k*(Vin - Vcc/2)))
    * Gain factor k=10
    B_logic out gnd V=V(vcc) / (1 + exp(10 * (V(int) - V(vcc)/2)))
.ends

* --- Simulation Directives ---

* Initial Condition:
* Force node N1 to 0V at t=0 to prevent metastable state (kickstart oscillation)
.ic V(N1)=0

* Transient Analysis:
* Run for 2 microseconds, step size 1 nanosecond
* 'uic' (Use Initial Conditions) is required for .ic to take effect
.tran 1n 2u uic

* Operating Point (for check)
.op

* Output Printing:
* V(N5) is the primary OSC_OUT node
.print tran V(N5) V(N1) V(N2) V(N3) V(N4)

.end
* --- GPT review (BOM/Wiring/SPICE) ---
* circuit_ok=true
* simulation_summary: The transient analysis shows sustained oscillation on nodes N1 through N5. The voltages swing between ~0V and ~5V. The frequency can be inferred from the timestamps (e.g., N5 rising edges around 1.43us and subsequent cycles), confirming the ring oscillator behavior.
* bom_vs_spice equivalences ignored:
*   - U1 (74HC04 Hex Inverter) is modeled as a subcircuit using behavioral voltage sources and RC delay stages to simulate propagation delay and logic inversion.
* overall_comment: The circuit is well-modeled for a didactic example. The inclusion of internal RC delay stages inside the inverter subcircuit is crucial for a ring oscillator simulation, as ideal SPICE inverters often fail to oscillate or converge without explicit time-dependent behavior. The initial condition (.ic V(N1)=0) correctly kickstarts the oscillation. The connectivity matches the wiring guide perfectly.
* --------------------------------------

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)

Analysis: The transient analysis shows sustained oscillation on nodes N1 through N5. The voltages swing between ~0V and ~5V. The frequency can be inferred from the timestamps (e.g., N5 rising edges around 1.43us and subsequent cycles), confirming the ring oscillator behavior.
Show raw data table (2039 rows)
Index   time            v(n5)           v(n1)           v(n2)           v(n3)           v(n4)
0	1.000000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
1	1.028000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
2	1.084000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
3	1.196000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
4	1.420000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
5	1.868000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
6	2.764000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
7	4.556000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
8	8.140000e-11	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
9	1.530800e-10	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
10	2.964400e-10	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
11	5.831600e-10	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
12	1.000000e-09	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
13	1.057344e-09	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
14	1.172032e-09	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
15	1.401408e-09	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
16	1.860160e-09	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00	5.000000e+00
17	2.777664e-09	4.999998e+00	4.999998e+00	4.999998e+00	4.999998e+00	4.999998e+00
18	3.777664e-09	4.999526e+00	4.999526e+00	4.999526e+00	4.999526e+00	4.999526e+00
19	4.777664e-09	4.987728e+00	4.987728e+00	4.987728e+00	4.987728e+00	4.987728e+00
20	5.777664e-09	4.795985e+00	4.795985e+00	4.795985e+00	4.795985e+00	4.795985e+00
21	6.777664e-09	3.794650e+00	3.794650e+00	3.794650e+00	3.794650e+00	3.794650e+00
22	7.777664e-09	2.828762e+00	2.828762e+00	2.828762e+00	2.828762e+00	2.828762e+00
23	8.777664e-09	2.564867e+00	2.564867e+00	2.564867e+00	2.564867e+00	2.564867e+00
... (2015 more rows) ...

Common mistakes and how to avoid them

  1. Using an even number of gates: If you use 4 or 6 gates, the logic will settle into a stable state (latch up) rather than oscillate. Always use an odd number (3, 5, 7…).
  2. Breadboard capacitance: Standard breadboards have high parasitic capacitance between rows (approx 2-5pF). This will make the oscillator run slower than the datasheet specs imply. Avoid long jumper loops.
  3. Missing decoupling capacitor: Without C1 close to the chip, the high-frequency switching current will cause VCC sag, resulting in erratic frequency or no oscillation.

Troubleshooting

  • Output is stuck High or Low: Check that you have an odd number of inverters in the loop. Verify the feedback wire connects the last output to the first input.
  • Frequency is unstable (jitter): Likely power supply noise. Ensure C1 (100nF) is installed extremely close to pins 14 and 7.
  • Scope shows a sine wave instead of square: At very high frequencies (approaching the bandwidth limit of the scope or probe), square waves look like sine waves due to the attenuation of higher harmonics. Ensure your scope bandwidth is at least 100 MHz.
  • Circuit gets hot: Check for short circuits between outputs. Never connect two outputs together.

Possible improvements and extensions

  1. Enable Control: Replace the first inverter with a NAND gate (e.g., using 74HC00). Use one input for the feedback loop and the other as an Enable/Disable control signal.
  2. Buffered Output: Use the 6th unused inverter in the 74HC04 package as a buffer connected to one of the ring nodes. Connect your probe/load to this buffer output. This isolates the ring oscillator from the load capacitance, providing a more accurate frequency measurement.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What specific arrangement of NOT gates is required to construct a ring oscillator?




Question 2: What is a strict requirement regarding the number of stages in a ring oscillator to ensure oscillation?




Question 3: What is the primary physical parameter calculated by measuring the oscillation frequency in this experiment?




Question 4: Which characteristic of ring oscillators allows them to be used for True Random Number Generators (TRNG)?




Question 5: What is the typical expected frequency range for a 5-stage ring oscillator using 74HC logic on a breadboard?




Question 6: What is the function of the 100 nF ceramic capacitor (C1) typically placed near the IC in this circuit?




Question 7: In the context of semiconductor manufacturing, why are ring oscillators useful?




Question 8: What does the optional 10 pF capacitor (C2) simulate in this experiment?




Question 9: Which IC is specifically selected to provide the logic gates for this ring oscillator?




Question 10: What type of waveform is expected at the output of the ring oscillator?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Multi-perimeter intrusion detection

Multi-perimeter intrusion detection prototype (Maker Style)

Level: Advanced — Implement a 4-zone security system using cascaded OR logic to trigger a centralized alarm.

Objective and use case

In this project, you will build a centralized security monitoring system that supervises four distinct access points (windows or doors). The system uses magnetic reed switches and a 74HC32 Quad 2-input OR gate IC to consolidate multiple sensor signals into a single alarm trigger.

Why it is useful:
* Home Security: Monitors multiple entry points (front door, back door, garage, window) simultaneously.
* Server Rooms: Ensures all rack doors are closed; alerts if any single cabinet is breached.
* Industrial Safety: Prevents machine operation if any safety guard perimeter is open.

Expected outcome:
* Secure State: When all doors/windows are closed, the relay remains off (0 V at coil).
* Alarm State: If any single zone (or multiple zones) is breached, the relay activates.
* Voltage Levels: Logic Low (≈ 0 V) represents a secure zone; Logic High (≈ 5 V) represents a breach.
* Indication: A relay clicks and activates a connected load (simulated by a high-power LED or siren).

Target audience: Advanced electronics students and security system prototypers.

Materials

  • V1: 5 V DC voltage source, function: Main power supply
  • U1: 74HC32, function: Quad 2-input OR gate Logic IC
  • S1: SPST Switch (Reed Switch), function: Zone 1 sensor (Normally Open, closed by magnet)
  • S2: SPST Switch (Reed Switch), function: Zone 2 sensor
  • S3: SPST Switch (Reed Switch), function: Zone 3 sensor
  • S4: SPST Switch (Reed Switch), function: Zone 4 sensor
  • R1: 10 kΩ resistor, function: Pull-up for Zone 1
  • R2: 10 kΩ resistor, function: Pull-up for Zone 2
  • R3: 10 kΩ resistor, function: Pull-up for Zone 3
  • R4: 10 kΩ resistor, function: Pull-up for Zone 4
  • R5: 1 kΩ resistor, function: Transistor base current limiting
  • Q1: 2N2222 NPN Transistor, function: Relay driver
  • D1: 1N4007 Diode, function: Flyback protection for relay coil
  • RL1: 5 V Relay (SPDT), function: High-power switching interface
  • C1: 100 nF capacitor, function: Decoupling for U1

Pin-out of the IC used

Chip: 74HC32 (Quad 2-Input OR Gate)

Pin Name Logic Function Connection in this case
1 1A Input OR Gate 1 Connect to Node ZONE1
2 1B Input OR Gate 1 Connect to Node ZONE2
3 1Y Output OR Gate 1 Connect to Node INT_A (Input to Gate 3)
4 2A Input OR Gate 2 Connect to Node ZONE3
5 2B Input OR Gate 2 Connect to Node ZONE4
6 2Y Output OR Gate 2 Connect to Node INT_B (Input to Gate 3)
7 GND Ground Connect to Node 0
9 3A Input OR Gate 3 Connect to Node INT_A
10 3B Input OR Gate 3 Connect to Node INT_B
8 3Y Output OR Gate 3 Connect to Node LOGIC_OUT
14 VCC Power Supply Connect to Node VCC

Note: Pins 11, 12, and 13 (Gate 4) are unused and should be grounded if strictly following best CMOS practices, though often left floating in simple prototypes.

Wiring guide

This circuit uses «Active High» logic for alarms. The sensors are wired as Pull-ups. When a door is closed (magnet present), the switch closes to ground (Logic 0). When a door opens, the resistor pulls the line to VCC (Logic 1).

  • Power Supply
  • V1 positive terminal connects to node VCC.
  • V1 negative terminal connects to node 0 (GND).
  • C1 connects between VCC and 0 (near U1).

  • Zone Sensors (Inputs)

  • R1 connects between VCC and ZONE1.
  • S1 connects between ZONE1 and 0.
  • R2 connects between VCC and ZONE2.
  • S2 connects between ZONE2 and 0.
  • R3 connects between VCC and ZONE3.
  • S3 connects between ZONE3 and 0.
  • R4 connects between VCC and ZONE4.
  • S4 connects between ZONE4 and 0.

  • Logic Processing (Cascading)

  • U1 Pin 1 (1A) connects to ZONE1.
  • U1 Pin 2 (1B) connects to ZONE2.
  • U1 Pin 3 (1Y) connects to INT_A.
  • U1 Pin 4 (2A) connects to ZONE3.
  • U1 Pin 5 (2B) connects to ZONE4.
  • U1 Pin 6 (2Y) connects to INT_B.
  • U1 Pin 9 (3A) connects to INT_A.
  • U1 Pin 10 (3B) connects to INT_B.
  • U1 Pin 8 (3Y) connects to LOGIC_OUT.

  • Output Driver Stage

  • R5 connects between LOGIC_OUT and node BASE.
  • Q1 Base connects to BASE.
  • Q1 Emitter connects to 0.
  • Q1 Collector connects to node RELAY_COIL_NEG.
  • RL1 Coil positive connects to VCC.
  • RL1 Coil negative connects to RELAY_COIL_NEG.
  • D1 Anode connects to RELAY_COIL_NEG.
  • D1 Cathode connects to VCC (Parallel to coil, reverse biased).

Conceptual block diagram

Conceptual block diagram — 74HC32 OR gate

Schematic

Title: Practical case: Multi-perimeter intrusion detection

      [ INPUT STAGE ]                  [ LOGIC STAGE (U1: 74HC32) ]                 [ OUTPUT STAGE ]

   (VCC)                                                                               (VCC)
     |                                                                                   |
   [ R1 ]                                                                            +---+---+
     +----(Zone 1)-------->+-------------+                                           |       |
     |                     |  OR GATE 1  |                                         [D1]    [RL1]
   [ S1 ]                  | (Pins 1,2)  |--(Int A)------>+                        (Diode) (Coil)
     |                     +-------------+                |                          |       |
   (GND)                   ^                              |                          +---+---+
                           |                              |                              |
   (VCC)                   |                              v                              |
     |                     |                       +-------------+                       |
   [ R2 ]                  |                       |  OR GATE 3  |                       |
     +----(Zone 2)---------+                       | (Pins 9,10) |                       |
     |                                             +-------------+                       |
   [ S2 ]                                                 |                              |
     |                                                    +----(Logic Out)--> [ R5 ] --> +
   (GND)                                                  ^                              |
                                                          |                         [ Q1 Base ]
   (VCC)                                                  |                              |
     |                                                    |                        [ Q1 (NPN) ]
   [ R3 ]                                                 |                              |
     +----(Zone 3)-------->+-------------+                |                         (Emitter)
     |                     |  OR GATE 2  |                |                              |
   [ S3 ]                  | (Pins 4,5)  |--(Int B)-------+                            (GND)
     |                     +-------------+
   (GND)                   ^
                           |
   (VCC)                   |
     |                     |
   [ R4 ]                  |
     +----(Zone 4)---------+
     |
   [ S4 ]
     |
   (GND)
Schematic (ASCII)

Truth table

The logic is cascaded. Gates 1 and 2 handle the zones; Gate 3 combines their results.
Logic 0 = Secure (Door Closed). Logic 1 = Breach (Door Open).

Zone 1 Zone 2 Zone 3 Zone 4 Int A (Z1+Z2) Int B (Z3+Z4) Final Output System State
0 0 0 0 0 0 0 Secure
1 0 0 0 1 0 1 ALARM
0 1 0 0 1 0 1 ALARM
0 0 1 0 0 1 1 ALARM
0 0 0 1 0 1 1 ALARM
1 1 1 1 1 1 1 ALARM

Note: Any combination containing at least one «1» results in a Final Output of «1».

Measurements and tests

  1. Static Logic Check:
    • Ensure all switches are closed (magnets present). Measure voltage at LOGIC_OUT. It should be < 0.1 V.
    • Open switch S1 only. Measure voltage at ZONE1 (should be ≈ 5 V) and LOGIC_OUT (should be ≈ 5 V).
    • Verify the Relay clicks ON.
  2. Threshold Verification:
    • With S1 open, measure the voltage at node BASE (Q1 Base). It should be approx 0.7 V (Vbe of the transistor).
  3. Cascading Check:
    • Close S1 (Secure). Open S3.
    • Verify INT_A is Low (0 V) and INT_B is High (5 V).
    • Verify LOGIC_OUT remains High.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Multi-perimeter intrusion detection
* NGSPICE Netlist
* Created based on Bill of Materials and Wiring Guide

* =============================================================================
* COMPONENT MODELS
* =============================================================================

* NPN Transistor Model (2N2222)
.model 2N2222 NPN(Is=14.34f Xti=3 Eg=1.11 Vaf=74.03 Bf=255.9 Ne=1.307 Ise=14.34f 
+ Ikf=.2847 Xtb=1.5 Br=6.092 Nc=2 Isc=0 Ikr=0 Rc=1 Cjc=7.306p Mjc=.3416 Vjc=.75 
+ Fc=.5 Cje=22.01p Mje=.377 Vje=.75 Tr=46.91n Tf=411.1p Itf=.6 Vtf=1.7 Xtf=3 Rb=10)

* Diode Model (1N4007)
.model 1N4007 D(IS=7.027n RS=0.034 N=1.26 TT=4.32u CJO=4p)

* Voltage Controlled Switch Model (for Reed Switches)
* Vt=2.5V: Control > 2.5V is CLOSED (Low R), Control < 2.5V is OPEN (High R)
.model SW_REED SW(Vt=2.5 Ron=0.1 Roff=10Meg)

* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Multi-perimeter intrusion detection
* NGSPICE Netlist
* Created based on Bill of Materials and Wiring Guide

* =============================================================================
* COMPONENT MODELS
* =============================================================================

* NPN Transistor Model (2N2222)
.model 2N2222 NPN(Is=14.34f Xti=3 Eg=1.11 Vaf=74.03 Bf=255.9 Ne=1.307 Ise=14.34f 
+ Ikf=.2847 Xtb=1.5 Br=6.092 Nc=2 Isc=0 Ikr=0 Rc=1 Cjc=7.306p Mjc=.3416 Vjc=.75 
+ Fc=.5 Cje=22.01p Mje=.377 Vje=.75 Tr=46.91n Tf=411.1p Itf=.6 Vtf=1.7 Xtf=3 Rb=10)

* Diode Model (1N4007)
.model 1N4007 D(IS=7.027n RS=0.034 N=1.26 TT=4.32u CJO=4p)

* Voltage Controlled Switch Model (for Reed Switches)
* Vt=2.5V: Control > 2.5V is CLOSED (Low R), Control < 2.5V is OPEN (High R)
.model SW_REED SW(Vt=2.5 Ron=0.1 Roff=10Meg)

* =============================================================================
* POWER SUPPLY
* =============================================================================
V1 VCC 0 DC 5

* =============================================================================
* SENSORS (ZONES 1-4)
* Logic: Door Closed (Magnet Present) -> Switch Closed to GND -> Zone Low (Safe)
*        Door Open (Magnet Removed) -> Switch Open -> Zone Pulled High (Alarm)
* Simulation: Control Voltage 5V = Door Closed. Control Voltage 0V = Door Open.
* =============================================================================

* --- ZONE 1 ---
R1 VCC ZONE1 10k
S1 ZONE1 0 CTRL1 0 SW_REED
* Stimulus: Door 1 opens briefly at 100us
V_S1_CTRL CTRL1 0 PULSE(5 0 100u 1u 1u 50u 10m)

* --- ZONE 2 ---
R2 VCC ZONE2 10k
S2 ZONE2 0 CTRL2 0 SW_REED
* Stimulus: Door 2 opens briefly at 300us
V_S2_CTRL CTRL2 0 PULSE(5 0 300u 1u 1u 50u 10m)

* --- ZONE 3 ---
R3 VCC ZONE3 10k
S3 ZONE3 0 CTRL3 0 SW_REED
* Stimulus: Door 3 opens briefly at 500us
V_S3_CTRL CTRL3 0 PULSE(5 0 500u 1u 1u 50u 10m)

* --- ZONE 4 ---
R4 VCC ZONE4 10k
S4 ZONE4 0 CTRL4 0 SW_REED
* Stimulus: Door 4 opens briefly at 700us
V_S4_CTRL CTRL4 0 PULSE(5 0 700u 1u 1u 50u 10m)

* =============================================================================
* LOGIC PROCESSING (U1: 74HC32 Quad OR Gate)
* =============================================================================

* Subcircuit for 74HC32 using robust behavioral sources (tanh)
* Pinout: 1=1A, 2=1B, 3=1Y, 4=2A, 5=2B, 6=2Y, 7=GND, 8=3Y, 9=3A, 10=3B, 11=4Y, 12=4A, 13=4B, 14=VCC
.subckt 74HC32 1A 1B 1Y 2A 2B 2Y GND 3Y 3A 3B 4Y 4A 4B VCC
    * Gate 1 (1A, 1B -> 1Y)
    B1 1Y GND V = 2.5 * (1 + tanh(10 * (V(1A) + V(1B) - 2.5)))
    * Gate 2 (2A, 2B -> 2Y)
    B2 2Y GND V = 2.5 * (1 + tanh(10 * (V(2A) + V(2B) - 2.5)))
    * Gate 3 (3A, 3B -> 3Y)
    B3 3Y GND V = 2.5 * (1 + tanh(10 * (V(3A) + V(3B) - 2.5)))
    * Gate 4 (4A, 4B -> 4Y) - Unused but modeled
    B4 4Y GND V = 2.5 * (1 + tanh(10 * (V(4A) + V(4B) - 2.5)))
.ends

* Decoupling Capacitor for U1
C1 VCC 0 100n

* Instantiate U1
* Connections based on Wiring Guide:
* 1->ZONE1, 2->ZONE2, 3->INT_A
* 4->ZONE3, 5->ZONE4, 6->INT_B
* 9->INT_A, 10->INT_B, 8->LOGIC_OUT
* 14->VCC, 7->0
* Unused inputs (12, 13) grounded to avoid floating nodes
XU1 ZONE1 ZONE2 INT_A ZONE3 ZONE4 INT_B 0 LOGIC_OUT INT_A INT_B NC_4Y 0 0 VCC 74HC32

* =============================================================================
* OUTPUT DRIVER STAGE
* =============================================================================

* Base Resistor
R5 LOGIC_OUT BASE 1k

* Driver Transistor Q1
Q1 RELAY_COIL_NEG BASE 0 2N2222

* Relay RL1 (Modeled as Coil Inductance + Resistance)
* Coil Positive -> VCC, Negative -> Collector
L_RL1 VCC RELAY_NODE_INT 100m
R_RL1 RELAY_NODE_INT RELAY_COIL_NEG 70

* Flyback Diode D1 (Parallel to coil, Reverse Biased)
* Anode -> Collector (Low side), Cathode -> VCC
D1 RELAY_COIL_NEG VCC 1N4007

* =============================================================================
* SIMULATION COMMANDS
* =============================================================================

.tran 10u 1000u

* Print required signals for validation
.print tran V(ZONE1) V(ZONE2) V(INT_A) V(INT_B) V(LOGIC_OUT) V(RELAY_COIL_NEG)

.op
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (742 rows)
Index   time            v(zone1)        v(zone2)        v(int_a)
0	0.000000e+00	4.999950e-05	4.999950e-05	0.000000e+00
1	1.000000e-07	4.999950e-05	4.999950e-05	0.000000e+00
2	2.000000e-07	4.999950e-05	4.999950e-05	0.000000e+00
3	4.000000e-07	4.999950e-05	4.999950e-05	0.000000e+00
4	8.000000e-07	4.999950e-05	4.999950e-05	0.000000e+00
5	1.600000e-06	4.999950e-05	4.999950e-05	0.000000e+00
6	3.200000e-06	4.999950e-05	4.999950e-05	0.000000e+00
7	6.400000e-06	4.999950e-05	4.999950e-05	0.000000e+00
8	1.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
9	2.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
10	3.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
11	4.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
12	5.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
13	6.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
14	7.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
15	8.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
16	9.280000e-05	4.999950e-05	4.999950e-05	0.000000e+00
17	1.000000e-04	4.999950e-05	4.999950e-05	0.000000e+00
18	1.001000e-04	4.999950e-05	4.999950e-05	0.000000e+00
19	1.002600e-04	4.999950e-05	4.999950e-05	0.000000e+00
20	1.003075e-04	4.999950e-05	4.999950e-05	0.000000e+00
21	1.003906e-04	4.999950e-05	4.999950e-05	0.000000e+00
22	1.004136e-04	4.999950e-05	4.999950e-05	0.000000e+00
23	1.004539e-04	4.999950e-05	4.999950e-05	0.000000e+00
... (718 more rows) ...

Common mistakes and how to avoid them

  1. Directly driving the relay with the IC:
    • Error: Connecting the relay coil directly to the 74HC32 output pin. The chip cannot supply enough current (usually max 25mA, while relays need 70mA+).
    • Solution: Always use a transistor (Q1) as a driver stage.
  2. Omitting the Flyback Diode (D1):
    • Error: Leaving out D1 across the relay coil.
    • Consequence: The high-voltage spike generated when the relay turns off can destroy the transistor Q1.
  3. Floating Inputs:
    • Error: Forgetting the pull-up resistors (R1-R4) or the ground connection on the switches.
    • Consequence: The CMOS inputs will float, causing erratic alarms or random switching due to electromagnetic noise.

Troubleshooting

  • Symptom: Relay chatters (rapid clicking) or activates randomly.
    • Cause: Noisy power supply or floating input pin.
    • Fix: Check C1 is installed. Verify all unused inputs (if any) are tied to GND. Ensure pull-up resistors R1-R4 are securely connected.
  • Symptom: Alarm does not trigger when Door 1 opens.
    • Cause: Switch is stuck «Closed» or wiring error at U1 pin 1/2.
    • Fix: Measure voltage at ZONE1. If it stays 0 V when the door opens, the pull-up R1 is missing or shorted to ground.
  • Symptom: Transistor Q1 gets hot or fails instantly.
    • Cause: Missing base resistor R5.
    • Fix: Ensure R5 (1 kΩ) is in series with the base to limit current.

Possible improvements and extensions

  1. Latching Alarm: Add a flip-flop or feedback loop (SCR logic) so that once the alarm triggers, it stays on even if the intruder closes the door again. A reset button would be required.
  2. Zone Indicators: Add an individual LED buffered from nodes ZONE1 through ZONE4. This allows the user to see exactly which specific window or door caused the alarm.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary objective of the project described in the text?




Question 2: Which specific logic gate IC is used to consolidate the sensor signals?




Question 3: In the 'Secure State', what is the expected status of the relay?




Question 4: What logic voltage level represents a breached zone in this system?




Question 5: Which component functions as the sensor for the zones?




Question 6: What happens if any single zone is breached?




Question 7: What logic level represents a secure zone in this system?




Question 8: Which of the following is NOT listed as a use case for this system?




Question 9: What is the target audience level for this project?




Question 10: How many distinct access points does this system supervise?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Simple electronic voting system

Simple electronic voting system prototype (Maker Style)

Level: Advanced — Design a circuit to approve a motion if at least one of three judges emits a positive vote, integrating combinational logic and signal debouncing.

Objective and use case

You will build a digital logic circuit that processes signals from three independent momentary switches representing judges. The system uses a cascaded OR topology to drive a visual indicator if any single input (or combination of inputs) is active.

Why it is useful:
* Safety Interlocks: Similar logic is used in machine guards where breaking any single beam or opening any door must trigger a stop or alarm.
* Fault Detection: In automotive dashboards, multiple sensors (oil, tire pressure, engine heat) feed into a central warning light (Check Engine) via OR logic.
* Access Control: Systems where multiple different credentials (card, code, or biometric) can grant entry to the same door.
* Interrupt Requests: In microcontrollers, multiple peripherals can trigger a single interrupt line to the CPU using this logic.

Expected outcome:
* The output LED turns ON (Logic High) if Judge A, Judge B, Judge C, or any combination presses their button.
* The output LED remains OFF (Logic Low) only when all buttons are released.
* Input signals are conditioned (debounced) to prevent rapid flickering caused by mechanical switch bounce.
* Verification of signal propagation through cascaded logic gates.

Target audience: Engineering students and advanced electronics enthusiasts.

Materials

  • V1: 5 V DC supply
  • S1: Momentary push-button (Normally Open), function: Judge A Input
  • S2: Momentary push-button (Normally Open), function: Judge B Input
  • S3: Momentary push-button (Normally Open), function: Judge C Input
  • R1: 10 kΩ resistor, function: pull-down for Node A
  • R2: 10 kΩ resistor, function: pull-down for Node B
  • R3: 10 kΩ resistor, function: pull-down for Node C
  • R4: 1 kΩ resistor, function: RC debounce series resistance (Input A)
  • R5: 1 kΩ resistor, function: RC debounce series resistance (Input B)
  • R6: 1 kΩ resistor, function: RC debounce series resistance (Input C)
  • C1: 100 nF capacitor, function: debounce filtering (Input A)
  • C2: 100 nF capacitor, function: debounce filtering (Input B)
  • C3: 100 nF capacitor, function: debounce filtering (Input C)
  • U1: 74HC32 (Quad 2-Input OR Gate IC)
  • R7: 330 Ω resistor, function: LED current limiting
  • D1: Red LED, function: Outcome indicator

Pin-out of the IC used

Chip Selected: 74HC32 (Quad 2-Input OR Gate).
Note: Since we have 3 inputs and the chip contains 2-input gates, we will cascade two gates to create the logic function $Y = (A + B) + C$.

Pin Name Logic function Connection in this case
1 1A Input Connects to Debounced Signal A
2 1B Input Connects to Debounced Signal B
3 1Y Output Connects to Pin 4 (Cascade to next gate)
4 2A Input Connects to Pin 3 (Result of A+B)
5 2B Input Connects to Debounced Signal C
6 2Y Output Connects to Output LED circuit
7 GND Ground Connects to 0 (GND)
14 VCC Power Connects to VCC (+5V)

Wiring guide

This guide uses SPICE-friendly node names.
* Power Supply:
* V1 connects between node VCC and node 0 (GND).
* U1 pin 14 connects to VCC.
* U1 pin 7 connects to 0.

  • Input Stage (Judge A) – Pull-down & Debounce:
  • S1 connects between VCC and node RAW_A.
  • R1 connects between RAW_A and 0.
  • R4 connects between RAW_A and node IN_A.
  • C1 connects between IN_A and 0.

  • Input Stage (Judge B) – Pull-down & Debounce:

  • S2 connects between VCC and node RAW_B.
  • R2 connects between RAW_B and 0.
  • R5 connects between RAW_B and node IN_B.
  • C2 connects between IN_B and 0.

  • Input Stage (Judge C) – Pull-down & Debounce:

  • S3 connects between VCC and node RAW_C.
  • R3 connects between RAW_C and 0.
  • R6 connects between RAW_C and node IN_C.
  • C3 connects between IN_C and 0.

  • Logic Processing (Cascaded OR):

  • U1 pin 1 connects to IN_A.
  • U1 pin 2 connects to IN_B.
  • U1 pin 3 (Gate 1 Output) connects to node GATE1_OUT.
  • U1 pin 4 connects to node GATE1_OUT (Cascading signal).
  • U1 pin 5 connects to IN_C.
  • U1 pin 6 (Final Output) connects to node LOGIC_OUT.

  • Output Stage:

  • R7 connects between LOGIC_OUT and node LED_ANODE.
  • D1 connects between LED_ANODE (Anode) and 0 (Cathode).

Conceptual block diagram

Conceptual block diagram — 74HC32 OR gate

Schematic

[ INPUT / CONDITIONING ]                  [ LOGIC PROCESSING (74HC32) ]             [ OUTPUT ]

                                                +-------------------------+
    [ S1: Judge A ]                             |        U1: Gate 1       |
    (VCC -> RAW_A) -> [ R1/R4/C1 ] --(Pin 1)--->| Input A                 |
                      (Debounce)                |           OR            |
                                                | Input B       (Output)  |
    [ S2: Judge B ]                    +------->| Pin 2          Pin 3    |--+
    (VCC -> RAW_B) -> [ R2/R5/C2 ] ----+        +-------------------------+  |
                      (Debounce)                                             |
                                                                             |
                                                                             |
                                                +-------------------------+  |
                                                |        U1: Gate 2       |  |
                                                | (Cascade In)   Pin 4    |< +
                                                |           OR            |
    [ S3: Judge C ]                    +------->| Input C        (Output) |
    (VCC -> RAW_C) -> [ R3/R6/C3 ] ----+        | Pin 5          Pin 6    |-----> [ R7: 330 Ohm ]
                      (Debounce)                +-------------------------+           |
                                                                                      v
                                                                                 [ D1: Red LED ]
                                                                                      |
                                                                                      v
                                                                                     GND
Schematic (ASCII)

Truth table

The system creates a 3-Input OR function: $Q = A + B + C$.

Input A Input B Input C Output Q (LED) Note
0 0 0 0 Motion Rejected
0 0 1 1 Motion Approved
0 1 0 1 Motion Approved
0 1 1 1 Motion Approved
1 0 0 1 Motion Approved
1 0 1 1 Motion Approved
1 1 0 1 Motion Approved
1 1 1 1 Motion Approved

Measurements and tests

  1. Static Logic Check: Ensure no buttons are pressed. Measure voltage at U1 Pin 6. It should be close to 0 V. Press S1. The voltage should rise to ~5 V. Repeat for S2 and S3 individually.
  2. Debounce Validation: Connect an oscilloscope to RAW_A and IN_A. Press S1. RAW_A may show sharp voltage spikes/noise on contact. IN_A should show a smooth exponential rise curve, filtering out the noise before it hits the logic gate.
  3. Cascaded Delay: This is an advanced measurement. Measure the propagation delay between IN_A and LOGIC_OUT versus IN_C and LOGIC_OUT. Because IN_A must pass through two gates (Gate 1 then Gate 2), the total propagation delay will be slightly longer than IN_C, which only passes through Gate 2.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Simple electronic voting system
* Based on Practical Case BOM and Wiring Guide

* --- Power Supply ---
* V1 connects between node VCC and node 0 (GND).
V1 VCC 0 DC 5

* --- User Input Stimuli (Button Presses) ---
* We simulate the physical push-buttons using Voltage Controlled Switches (S1-S3)
* controlled by independent PULSE sources (V_CTRL_A, etc.) to mimic user behavior.
* The timing is staggered to test inputs A, B, and C sequentially with sufficient 
* time for the RC debounce circuits to charge and discharge.

* Judge A: Press at 1ms, hold for 2ms (releases at 3ms)
V_CTRL_A CTRL_A 0 PULSE(0 5 1m 1u 1u 2m 20m)

* Judge B: Press at 6ms, hold for 2ms (releases at 8ms)
V_CTRL_B CTRL_B 0 PULSE(0 5 6m 1u 1u 2m 20m)

* Judge C: Press at 11ms, hold for 2ms (releases at 13ms)
* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Simple electronic voting system
* Based on Practical Case BOM and Wiring Guide

* --- Power Supply ---
* V1 connects between node VCC and node 0 (GND).
V1 VCC 0 DC 5

* --- User Input Stimuli (Button Presses) ---
* We simulate the physical push-buttons using Voltage Controlled Switches (S1-S3)
* controlled by independent PULSE sources (V_CTRL_A, etc.) to mimic user behavior.
* The timing is staggered to test inputs A, B, and C sequentially with sufficient 
* time for the RC debounce circuits to charge and discharge.

* Judge A: Press at 1ms, hold for 2ms (releases at 3ms)
V_CTRL_A CTRL_A 0 PULSE(0 5 1m 1u 1u 2m 20m)

* Judge B: Press at 6ms, hold for 2ms (releases at 8ms)
V_CTRL_B CTRL_B 0 PULSE(0 5 6m 1u 1u 2m 20m)

* Judge C: Press at 11ms, hold for 2ms (releases at 13ms)
V_CTRL_C CTRL_C 0 PULSE(0 5 11m 1u 1u 2m 20m)

* --- Input Stage: Judge A ---
* S1 connects between VCC and node RAW_A
S1 VCC RAW_A CTRL_A 0 SW_PB
* R1 (10k) pull-down for Node A (RAW_A to 0)
R1 RAW_A 0 10k
* R4 (1k) RC debounce series resistance (RAW_A to IN_A)
R4 RAW_A IN_A 1k
* C1 (100nF) debounce filtering (IN_A to 0)
C1 IN_A 0 100n

* --- Input Stage: Judge B ---
* S2 connects between VCC and node RAW_B
S2 VCC RAW_B CTRL_B 0 SW_PB
* R2 (10k) pull-down for Node B (RAW_B to 0)
R2 RAW_B 0 10k
* R5 (1k) RC debounce series resistance (RAW_B to IN_B)
R5 RAW_B IN_B 1k
* C2 (100nF) debounce filtering (IN_B to 0)
C2 IN_B 0 100n

* --- Input Stage: Judge C ---
* S3 connects between VCC and node RAW_C
S3 VCC RAW_C CTRL_C 0 SW_PB
* R3 (10k) pull-down for Node C (RAW_C to 0)
R3 RAW_C 0 10k
* R6 (1k) RC debounce series resistance (RAW_C to IN_C)
R6 RAW_C IN_C 1k
* C3 (100nF) debounce filtering (IN_C to 0)
C3 IN_C 0 100n

* --- Logic Processing: U1 (74HC32 Quad 2-Input OR Gate) ---
* Implemented using Behavioral Voltage Sources (B-sources) for robust simulation.
* Logic Transfer Function: Continuous Sigmoid approximation of OR gate.
* Vout = VCC * Sigmoid( max(Input1, Input2) - Threshold )
* Threshold set to 2.5V (Mid-rail).
* U1 Pin 14 (VCC) and Pin 7 (GND) are functionally represented by the V(VCC) term and node 0 reference.

* Gate 1: Inputs IN_A (Pin 1), IN_B (Pin 2) -> Output GATE1_OUT (Pin 3)
* Corresponds to wiring: U1 pin 1 to IN_A, U1 pin 2 to IN_B, U1 pin 3 to GATE1_OUT
B_U1_G1 GATE1_OUT 0 V = V(VCC) * (1 / (1 + exp(-20 * (max(V(IN_A), V(IN_B)) - 2.5))))

* Cascading Connection:
* Wiring: U1 pin 4 connects to node GATE1_OUT.

* Gate 2: Inputs GATE1_OUT (Pin 4), IN_C (Pin 5) -> Output LOGIC_OUT (Pin 6)
* Corresponds to wiring: U1 pin 4 to GATE1_OUT, U1 pin 5 to IN_C, U1 pin 6 to LOGIC_OUT
B_U1_G2 LOGIC_OUT 0 V = V(VCC) * (1 / (1 + exp(-20 * (max(V(GATE1_OUT), V(IN_C)) - 2.5))))

* --- Output Stage ---
* R7 connects between LOGIC_OUT and node LED_ANODE
R7 LOGIC_OUT LED_ANODE 330
* D1 connects between LED_ANODE (Anode) and 0 (Cathode)
D1 LED_ANODE 0 D_LED

* --- Models ---
* Switch model for push buttons (Active High control)
.model SW_PB SW(Vt=2.5 Ron=0.1 Roff=10Meg)
* Generic LED model (Red)
.model D_LED D(IS=1n N=2 RS=10 BV=5)

* --- Simulation Directives ---
* Transient analysis for 15ms to capture all button presses and RC discharge curves.
* Step size 10us is sufficient for the 100us/1.1ms time constants.
.tran 10u 15m

* Print required nodes for validation
.print tran V(IN_A) V(IN_B) V(IN_C) V(GATE1_OUT) V(LOGIC_OUT) V(LED_ANODE)

.op
.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (3274 rows)
Index   time            v(in_a)         v(in_b)         v(in_c)
0	0.000000e+00	4.995005e-03	4.995005e-03	4.995005e-03
1	1.000000e-07	4.995005e-03	4.995005e-03	4.995005e-03
2	2.000000e-07	4.995005e-03	4.995005e-03	4.995005e-03
3	4.000000e-07	4.995005e-03	4.995005e-03	4.995005e-03
4	8.000000e-07	4.995005e-03	4.995005e-03	4.995005e-03
5	1.600000e-06	4.995005e-03	4.995005e-03	4.995005e-03
6	3.200000e-06	4.995005e-03	4.995005e-03	4.995005e-03
7	6.400000e-06	4.995005e-03	4.995005e-03	4.995005e-03
8	1.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
9	2.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
10	3.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
11	4.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
12	5.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
13	6.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
14	7.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
15	8.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
16	9.280000e-05	4.995005e-03	4.995005e-03	4.995005e-03
17	1.028000e-04	4.995005e-03	4.995005e-03	4.995005e-03
18	1.128000e-04	4.995005e-03	4.995005e-03	4.995005e-03
19	1.228000e-04	4.995005e-03	4.995005e-03	4.995005e-03
20	1.328000e-04	4.995005e-03	4.995005e-03	4.995005e-03
21	1.428000e-04	4.995005e-03	4.995005e-03	4.995005e-03
22	1.528000e-04	4.995005e-03	4.995005e-03	4.995005e-03
23	1.628000e-04	4.995005e-03	4.995005e-03	4.995005e-03
... (3250 more rows) ...

Common mistakes and how to avoid them

  1. Floating Inputs: Failing to install the pull-down resistors (R1, R2, R3). Without them, the 74HC32 inputs act as antennas, causing the LED to flicker randomly or stay stuck High. Solution: Always reference inputs to GND when the switch is open.
  2. Ignoring Pinout: Connecting Input C to Pin 3 (which is an output). This creates a short circuit when the gate tries to drive Low while the button drives High. Solution: Double-check the datasheet pin diagram before powering up.
  3. Excessive RC Time Constant: Using a capacitor that is too large (e.g., 100 µF) for the debounce circuit. This creates a very slow voltage rise that causes the digital gate to oscillate linearly during the threshold crossing. Solution: Stick to 100 nF – 1 µF for simple logic inputs.

Troubleshooting

  • LED is always ON: Check pull-down resistors. If measured voltage at pins 1, 2, or 5 is floating (not 0 V), the gate interprets it as Logic High.
  • LED does not light up for Judge A or B: Verify the cascade connection. Pin 3 (Output of first gate) must be physically wired to Pin 4 (Input of second gate).
  • Erratic behavior when touching wires: Indicates missing ground connections on unused inputs (if any) or floating operational inputs. Ensure all grounds share a common point.
  • Gate gets hot: Check for output-to-output short circuits or output-to-VCC shorts. Disconnect power immediately.

Possible improvements and extensions

  1. Majority Vote Extension: Modify the logic to require at least two positive votes to approve the motion (using a combination of AND and OR gates: $AB + BC + AC$).
  2. Latch functionality: Add a D Flip-Flop (e.g., 74HC74) after the output. Once the motion is approved (LED ON), the light stays ON until a dedicated «Reset» button is pressed by a supervisor.

More Practical Cases on Prometeo.blog

        <div class="amazon-affiliate">
          <p><strong>Find this product and/or books on this topic on Amazon</strong></p>
          <p><a class="amazon-affiliate-btn" href="https://amzn.to/4mt8r4C" target="_blank" rel="nofollow sponsored noopener">Go to Amazon</a></p>
          <p class="amazon-affiliate-disclaimer">As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.</p>
        </div>

Quick Quiz

Question 1: What is the primary logic topology used in the described circuit to process the judges' votes?




Question 2: Under what condition will the output LED turn ON?




Question 3: Which of the following is NOT listed as a useful application for this type of logic circuit?




Question 4: What specific issue does signal debouncing address in this circuit?




Question 5: What type of switches are specified for the judges' inputs?




Question 6: How is this logic applied in the context of microcontroller interrupt requests?




Question 7: Based on the OR logic described, what is the state of the output LED when all buttons are released?




Question 8: In an automotive dashboard application, how does this logic function?




Question 9: What is the primary purpose of using this logic in safety interlocks?




Question 10: Which access control scenario utilizes the logic described in the text?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Data transfer synchronization

Data transfer synchronization prototype (Maker Style)

Level: Advanced. Implement a gated clock circuit allowing synchronization pulses only when Data Ready and System Enable are active.

Objective and use case

In this session, you will design and analyze a clock gating circuit using cascaded AND gates to control the flow of high-speed clock pulses to a shift register. You will validate that the clock signal only propagates when two distinct control flags (‘Data Ready’ and ‘System Enable’) are simultaneously high.

Why it is useful:
* Power Management: Disabling the clock tree to idle shift registers or sub-systems reduces dynamic power consumption in CMOS circuits.
* Data Integrity: Ensures data is only clocked into the buffer when the source indicates valid data (Data Ready) and the controller allows reception (System Enable).
* Bus Arbitration: Prevents bus contention by synchronizing multiple peripherals sharing a common data line.

Expected outcome:
* The output GATED_CLK mirrors the input CLK only when DATA_RDY = 1 and SYS_EN = 1.
* Propagation delay between input clock edge and output clock edge is measured (typically 7–15 ns for 74HC series).
* Identification of «runt pulses» or glitches if enable signals change state while the clock is high.

Target audience and level:
Electronics engineering students and embedded system designers (Advanced).

Materials

  • U1: 74HC08 Quad 2-input AND gate IC, function: logic gating
  • V_CLK: Pulse generator, function: Master Clock (1 MHz, 0V-5V)
  • V_DR: DC voltage source or Switch, function: Data Ready signal
  • V_SE: DC voltage source or Switch, function: System Enable signal
  • V1: 5 V DC supply, function: Main power
  • C1: 100 nF ceramic capacitor, function: U1 decoupling
  • R_LOAD: 10 kΩ resistor, function: Simulates input impedance of shift register
  • C_LOAD: 15 pF capacitor, function: Simulates input capacitance and probe load

Pin-out of the IC used

Selected Chip: 74HC08 (Quad 2-Input AND Gate)

Pin Name Logic function Connection in this case
1 1A Input Gate 1 Connects to Node DATA_RDY
2 1B Input Gate 1 Connects to Node SYS_EN
3 1Y Output Gate 1 Connects to Node ENABLE_COMBINED (Internal)
4 2A Input Gate 2 Connects to Node ENABLE_COMBINED
5 2B Input Gate 2 Connects to Node CLK_IN
6 2Y Output Gate 2 Connects to Node GATED_CLK
7 GND Ground Connects to Node 0
14 VCC Power Supply Connects to Node VCC

Wiring guide

Construct the circuit following these node connections. Ensure the power supply is off while wiring.

  • Power Supply:

    • V1 positive terminal connects to node VCC.
    • V1 negative terminal connects to node 0 (GND).
    • C1 connects between VCC and 0 (placed close to U1).
    • U1 Pin 14 connects to VCC.
    • U1 Pin 7 connects to 0.
  • Control Logic (Gate 1):

    • V_DR (Data Ready) positive terminal connects to node DATA_RDY.
    • V_SE (System Enable) positive terminal connects to node SYS_EN.
    • U1 Pin 1 (1A) connects to node DATA_RDY.
    • U1 Pin 2 (1B) connects to node SYS_EN.
    • U1 Pin 3 (1Y) connects to node ENABLE_COMBINED.
  • Clock Gating (Gate 2):

    • V_CLK (Clock Source) positive terminal connects to node CLK_IN.
    • U1 Pin 4 (2A) connects to node ENABLE_COMBINED.
    • U1 Pin 5 (2B) connects to node CLK_IN.
    • U1 Pin 6 (2Y) connects to node GATED_CLK.
  • Output Loading:

    • R_LOAD connects between GATED_CLK and 0.
    • C_LOAD connects between GATED_CLK and 0.

Conceptual block diagram

Conceptual block diagram — 74HC08 AND gate

Schematic

[ INPUT SIGNALS ]                       [ LOGIC PROCESSING (U1: 74HC08) ]                     [ OUTPUT STAGE ]

                                             +-----------------------------------+
                                             |    POWER SUPPLY & DECOUPLING      |
                                             |  V1 (5V) -> Pin 14, GND -> Pin 7  |
                                             |  C1 (100nF) across VCC/GND        |
                                             +-----------------------------------+
                                                               |
    [ V_DR: Data Ready ] --(Pin 1)-->+                         |
                                     |                         v
                                     +-----> [ AND Gate 1 ] ---+
                                     |       (Control Logic)   |
    [ V_SE: Sys Enable ] --(Pin 2)-->+                         |
                                                               |
                                                               | (Pin 3: ENABLE_COMBINED)
                                                               |
                                                               v
                                                          (Pin 4)
                                                               +---> [ AND Gate 2 ] --(Pin 6)--> [ R_LOAD (10k) ] --+
                                                               |     (Clock Gating)              [ C_LOAD (15pF) ]  |
    [ V_CLK: Master Clk ] --(Pin 5)----------------------------+     (Signal: GATED_CLK)                            v
                                                                                                                   GND
Schematic (ASCII)

Truth table

This table represents the cascaded logic: GATED_CLK = (DATA_RDY AND SYS_EN) AND CLK_IN.

DATA_RDY SYS_EN ENABLE_COMBINED (Internal) CLK_IN GATED_CLK State Description
0 X 0 X 0 Blocked: Data not ready
X 0 0 X 0 Blocked: System disabled
1 1 1 0 0 Active: Clock Low phase
1 1 1 1 1 Active: Clock High phase passed

(X = Don’t Care)

Measurements and tests

Perform the following validation steps using an oscilloscope (Dual Channel recommended).

  1. Static Logic Validation:

    • Set V_CLK to 0V. Toggle V_DR and V_SE. Ensure GATED_CLK remains 0V.
    • Set V_CLK to 5V (DC). Ensure GATED_CLK is High ONLY when both V_DR and V_SE are High.
  2. Dynamic Clock Gating:

    • Configure V_CLK to a 1 MHz square wave (50% duty cycle).
    • Enable Channel 1 on CLK_IN and Channel 2 on GATED_CLK.
    • Activate both V_DR and V_SE. Verify Channel 2 replicates Channel 1.
    • Deactivate V_DR. Verify Channel 2 goes flat Low.
  3. Propagation Delay Analysis (Advanced):

    • With the clock running and passing through, maximize horizontal zoom (timebase ~10ns/div).
    • Measure the time difference between the 50% voltage point of the rising edge of CLK_IN and the rising edge of GATED_CLK.
    • Expected Result: A delay of approximately 15ns–25ns (sum of delays through Gate 1 and Gate 2).
  4. Glitch/Hazard Observation:

    • While CLK_IN is High, manually toggle DATA_RDY.
    • Observe if truncated pulses («runts») appear on the output. These are hazards caused by asynchronous gating.

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: Data transfer synchronization

* --- Power Supply ---
* V1 positive terminal connects to node VCC. Negative to node 0 (GND).
V1 VCC 0 DC 5
* C1 connects between VCC and 0 (placed close to U1).
C1 VCC 0 100n

* --- Input Stimuli (Dynamic) ---
* V_CLK: Master Clock (1 MHz, 0V-5V). 
* PULSE(V1 V2 TD TR TF PW PER) -> 1us Period, 0.49us Width
V_CLK CLK_IN 0 PULSE(0 5 0 10n 10n 490n 1u)

* V_DR: Data Ready signal.
* Simulates a data packet ready signal. Pulses High from 5us to 15us.
V_DR DATA_RDY 0 PULSE(0 5 5u 10n 10n 10u 40u)

* V_SE: System Enable signal.
* Simulates system enable window. Pulses High from 2us to 22us.
V_SE SYS_EN 0 PULSE(0 5 2u 10n 10n 20u 50u)

* --- Control Logic (U1: 74HC08) ---
* Instantiation of the IC using a behavioral subcircuit.
* Mapping pins according to Wiring Guide:
* Pin 1 (1A) -> DATA_RDY
* Pin 2 (1B) -> SYS_EN
* Pin 3 (1Y) -> ENABLE_COMBINED
* Pin 4 (2A) -> ENABLE_COMBINED
* Pin 5 (2B) -> CLK_IN
* Pin 6 (2Y) -> GATED_CLK
* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: Data transfer synchronization

* --- Power Supply ---
* V1 positive terminal connects to node VCC. Negative to node 0 (GND).
V1 VCC 0 DC 5
* C1 connects between VCC and 0 (placed close to U1).
C1 VCC 0 100n

* --- Input Stimuli (Dynamic) ---
* V_CLK: Master Clock (1 MHz, 0V-5V). 
* PULSE(V1 V2 TD TR TF PW PER) -> 1us Period, 0.49us Width
V_CLK CLK_IN 0 PULSE(0 5 0 10n 10n 490n 1u)

* V_DR: Data Ready signal.
* Simulates a data packet ready signal. Pulses High from 5us to 15us.
V_DR DATA_RDY 0 PULSE(0 5 5u 10n 10n 10u 40u)

* V_SE: System Enable signal.
* Simulates system enable window. Pulses High from 2us to 22us.
V_SE SYS_EN 0 PULSE(0 5 2u 10n 10n 20u 50u)

* --- Control Logic (U1: 74HC08) ---
* Instantiation of the IC using a behavioral subcircuit.
* Mapping pins according to Wiring Guide:
* Pin 1 (1A) -> DATA_RDY
* Pin 2 (1B) -> SYS_EN
* Pin 3 (1Y) -> ENABLE_COMBINED
* Pin 4 (2A) -> ENABLE_COMBINED
* Pin 5 (2B) -> CLK_IN
* Pin 6 (2Y) -> GATED_CLK
* Pin 7 (GND)-> 0
* Pin 14(VCC)-> VCC
XU1 DATA_RDY SYS_EN ENABLE_COMBINED ENABLE_COMBINED CLK_IN GATED_CLK 0 VCC 74HC08_BEHAVIORAL

* --- Output Loading ---
* R_LOAD connects between GATED_CLK and 0.
R_LOAD GATED_CLK 0 10k
* C_LOAD connects between GATED_CLK and 0.
C_LOAD GATED_CLK 0 15p

* --- Subcircuit Model: 74HC08 ---
* Robust behavioral implementation using sigmoid functions for convergence.
* Only the gates used in the wiring are modeled to save complexity.
.subckt 74HC08_BEHAVIORAL 1A 1B 1Y 2A 2B 2Y GND VCC
    * Gate 1: 1Y = 1A AND 1B
    * Function: V(VCC) * Sigmoid(A) * Sigmoid(B)
    B_G1 1Y_INT GND V = V(VCC) * (1 / (1 + exp(-50*(V(1A)-2.5)))) * (1 / (1 + exp(-50*(V(1B)-2.5))))
    R_G1 1Y_INT 1Y 100

    * Gate 2: 2Y = 2A AND 2B
    B_G2 2Y_INT GND V = V(VCC) * (1 / (1 + exp(-50*(V(2A)-2.5)))) * (1 / (1 + exp(-50*(V(2B)-2.5))))
    R_G2 2Y_INT 2Y 100
.ends

* --- Analysis Directives ---
.op
* Transient analysis: 10ns step, 25us duration to capture full logic sequence
.tran 10n 25u

* --- Output Directives ---
.print tran V(CLK_IN) V(DATA_RDY) V(SYS_EN) V(ENABLE_COMBINED) V(GATED_CLK)

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (6072 rows)
Index   time            v(clk_in)       v(data_rdy)     v(sys_en)
0	0.000000e+00	0.000000e+00	0.000000e+00	0.000000e+00
1	1.000000e-10	5.000000e-02	0.000000e+00	0.000000e+00
2	2.000000e-10	1.000000e-01	0.000000e+00	0.000000e+00
3	4.000000e-10	2.000000e-01	0.000000e+00	0.000000e+00
4	8.000000e-10	4.000000e-01	0.000000e+00	0.000000e+00
5	1.600000e-09	8.000000e-01	0.000000e+00	0.000000e+00
6	3.200000e-09	1.600000e+00	0.000000e+00	0.000000e+00
7	6.400000e-09	3.200000e+00	0.000000e+00	0.000000e+00
8	1.000000e-08	5.000000e+00	0.000000e+00	0.000000e+00
9	1.064000e-08	5.000000e+00	0.000000e+00	0.000000e+00
10	1.192000e-08	5.000000e+00	0.000000e+00	0.000000e+00
11	1.448000e-08	5.000000e+00	0.000000e+00	0.000000e+00
12	1.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
13	2.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
14	3.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
15	4.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
16	5.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
17	6.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
18	7.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
19	8.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
20	9.960000e-08	5.000000e+00	0.000000e+00	0.000000e+00
21	1.096000e-07	5.000000e+00	0.000000e+00	0.000000e+00
22	1.196000e-07	5.000000e+00	0.000000e+00	0.000000e+00
23	1.296000e-07	5.000000e+00	0.000000e+00	0.000000e+00
... (6048 more rows) ...

Common mistakes and how to avoid them

  1. Leaving unused inputs floating:
    • Issue: Unused inputs on the 74HC08 (e.g., Pins 9, 10, 12, 13) pick up noise, causing high power consumption or oscillation.
    • Solution: Connect all unused AND gate inputs directly to GND or VCC.
  2. Ignoring propagation delay accumulation:
    • Issue: Assuming the output happens instantly. In this cascaded setup (Gate 1 -> Gate 2), the delay is double that of a single gate.
    • Solution: Account for this delay in timing diagrams; signals may arrive too late for the setup time of the subsequent shift register.
  3. Gating the clock asynchronously:
    • Issue: Changing SYS_EN while the clock is High clips the pulse width, violating the minimum pulse width requirement of the shift register.
    • Solution: Ideally, synchronize the Enable signal to the falling edge of the clock (using a Flip-Flop) before feeding it to the AND gate.

Troubleshooting

  • Symptom: Output is permanently Low, even when all inputs are High.
    • Cause: Missing power to Pin 14 or GND to Pin 7.
    • Fix: Check VCC/GND continuity with a multimeter.
  • Symptom: «Ghosting» or noisy edges on the oscilloscope.
    • Cause: Lack of decoupling capacitor or long ground leads on probes.
    • Fix: Install C1 (100nF) extremely close to the IC; use the ground spring on the probe tip.
  • Symptom: Signal edges are very rounded (slow rise time).
    • Cause: Capacitive loading is too high (long wires or breadboard stray capacitance).
    • Fix: Shorten wires or add a buffer if driving a heavy load.

Possible improvements and extensions

  1. Glitch-free Gating: Add a D-Flip-Flop (e.g., 74HC74) to synchronize the ENABLE_COMBINED signal so it only changes state when the Clock is Low.
  2. Wait-State Insertion: Expand the circuit to assert a «BUSY» signal back to the controller whenever the clock is successfully gated, confirming data transfer is active.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary function of the 74HC08 IC in this circuit design?




Question 2: Under which specific condition will the output `GATED_CLK` mirror the input `CLK`?




Question 3: Which of the following is NOT listed as a benefit of using this clock gating circuit?




Question 4: What potential signal integrity issue is associated with enable signals changing state while the clock is high?




Question 5: What is the typical expected propagation delay for the 74HC series logic gates mentioned?




Question 6: How does clock gating contribute to power management in CMOS circuits?




Question 7: In the context of Bus Arbitration, what does this circuit help prevent?




Question 8: Which logic gate configuration is used to control the flow of the high-speed clock pulses?




Question 9: What is the primary purpose of the 'Data Integrity' benefit in this circuit?




Question 10: What specific type of circuit is being designed and analyzed in this session?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me:


Practical case: Safety interlock in a chemical reactor

Safety interlock in a chemical reactor prototype (Maker Style)

Level: Advanced. Design a redundant safety system enabling catalyst injection only when three critical variables are within range.

Objective and use case

In this case, you will build a hardware-based safety interlock logic circuit that monitors three simulated analog parameters (Temperature, Pressure, Level). It uses comparators to digitize these signals and a cascaded logic gate arrangement to control a high-power relay.

Why it is useful:
* Industrial Safety: Prevents chemical reactions from starting unless environmental conditions are perfect, avoiding run-away thermal events.
* Machine Guarding: Ensures guards are closed, pressure is released, and motors are stopped before unlocking maintenance doors.
* Medical Devices: Prevents laser or radiation emission unless all interlocks (key switch, door contact, patient sensor) are active.

Expected outcome:
* Logic Output: The final control signal V_SAFE goes HIGH (Logic 1, ~5V) only when all three inputs are within the «Safe» zone simultaneously.
* Visual Indication: The Relay activates (closing the circuit for the catalyst valve) and a Green LED lights up only in the 1-1-1 state.
* Hysteresis: The system maintains stability near switching thresholds (dependent on comparator configuration).

Target audience: Electronics engineering students and industrial automation technicians.

Materials

  • V1: 5 V DC power supply, function: Logic and sensor power.
  • U1: 74HC08, function: Quad 2-input AND gate (used to create 3-input logic).
  • U2: LM339, function: Quad open-collector comparator (digitizes analog sensors).
  • R1: 10 kΩ potentiometer, function: Simulator for Temperature Sensor.
  • R2: 10 kΩ potentiometer, function: Simulator for Pressure Sensor.
  • R3: 10 kΩ potentiometer, function: Simulator for Tank Level.
  • R_REF: 10 kΩ resistor array (or pots), function: Voltage dividers for reference thresholds (2.5 V).
  • R_PU1: 4.7 kΩ resistor, function: Pull-up for Comparator 1 output.
  • R_PU2: 4.7 kΩ resistor, function: Pull-up for Comparator 2 output.
  • R_PU3: 4.7 kΩ resistor, function: Pull-up for Comparator 3 output.
  • R_BASE: 1 kΩ resistor, function: Transistor base current limiting.
  • Q1: 2N2222 NPN Transistor, function: Relay driver.
  • K1: 5 V Relay, function: Actuator for catalyst valve.
  • D1: 1N4007 Diode, function: Flyback protection for Q1.
  • D2: Green LED, function: Indicator for «Injection Active».
  • R_LED: 330 Ω resistor, function: LED current limiting.

Pin-out of the IC used

Selected Chip: 74HC08 (Quad 2-Input AND Gate)

Pin Name Logic function Connection in this case
1 1A Input A (Gate 1) Connected to Temperature Status (SIG_TEMP)
2 1B Input B (Gate 1) Connected to Pressure Status (SIG_PRES)
3 1Y Output (Gate 1) Intermediate result (Temp AND Pres)
4 2A Input A (Gate 2) Connected to 1Y (Intermediate result)
5 2B Input B (Gate 2) Connected to Level Status (SIG_LEV)
6 2Y Output (Gate 2) Final Safety Signal (V_SAFE)
7 GND Ground Connected to power supply 0
14 VCC Power Connected to VCC (+5V)

Wiring guide

Power Supply
* V1 connects between VCC and 0 (GND).
* U1 (74HC08) Pin 14 connects to VCC, Pin 7 to 0.
* U2 (LM339) Pin 3 (V+) connects to VCC, Pin 12 (GND) to 0.

Analog Inputs & Comparators (Signal Conditioning)
* R1 (Temp Pot) connects between VCC and 0; wiper connects to U2 Input 1- (NODE_T_SENS).
* Reference divider connects to U2 Input 1+ (NODE_REF).
* U2 Output 1 connects to SIG_TEMP.
* R_PU1 connects between VCC and SIG_TEMP (required for open-collector).
* R2 (Pres Pot) connects between VCC and 0; wiper connects to U2 Input 2- (NODE_P_SENS).
* Reference divider connects to U2 Input 2+ (NODE_REF).
* U2 Output 2 connects to SIG_PRES.
* R_PU2 connects between VCC and SIG_PRES.
* R3 (Level Pot) connects between VCC and 0; wiper connects to U2 Input 3- (NODE_L_SENS).
* Reference divider connects to U2 Input 3+ (NODE_REF).
* U2 Output 13 connects to SIG_LEV.
* R_PU3 connects between VCC and SIG_LEV.

Digital Logic (Cascading for 3-Input AND)
* U1 Pin 1 (1A) connects to SIG_TEMP.
* U1 Pin 2 (1B) connects to SIG_PRES.
* U1 Pin 3 (1Y) connects to U1 Pin 4 (2A).
* U1 Pin 5 (2B) connects to SIG_LEV.
* U1 Pin 6 (2Y) connects to V_SAFE.

Output Stage
* R_BASE connects between V_SAFE and NODE_BASE.
* Q1 Base connects to NODE_BASE.
* Q1 Emitter connects to 0.
* Q1 Collector connects to NODE_RELAY.
* K1 (Relay coil) connects between VCC and NODE_RELAY.
* D1 connects between NODE_RELAY (Anode) and VCC (Cathode) Note: Check polarity, cathode to positive for flyback.
* R_LED connects between NODE_RELAY and NODE_LED_A.
* D2 connects between NODE_LED_A and 0.

Conceptual block diagram

Conceptual block diagram — 74HC08 AND gate

Schematic

Title: Practical case: Safety interlock in a chemical reactor

      [ SENSORS / INPUTS ]           [ SIGNAL CONDITIONING ]               [ LOGIC PROCESSING ]                  [ OUTPUT ACTUATOR STAGE ]

                                         (VCC / Pull-ups)                                                         (VCC 5V Source)
                                                |                                                                        |
    [ R1: Temp Pot ] --(Analog)--> [ U2: LM339 Comp 1 ] --(SIG_TEMP)-->+                                    +------------+------------+
    (Simulates Sensor)             [ Ref: 2.5V Divider]                |                                    |            |            |
                                                                       v                                [ K1 Relay ] [ D1 Diode ] [ R_LED ]
                                                                [ U1: 74HC08 ]                          [  Coil    ] [ Cathode^ ] [   +     ]
    [ R2: Pres Pot ] --(Analog)--> [ U2: LM339 Comp 2 ] --(SIG_PRES)-->[  AND Gate A  ] --(Intermed)--> |            [ Anode v  ] [ D2 LED  ]
    (Simulates Sensor)             [ Ref: 2.5V Divider]                [              ]       |         |            |            |
                                                                                              |         +------------+------------+
                                                                                              v                      |
                                                                                        [ U1: 74HC08 ]               | (NODE_RELAY)
                                                                                        [  AND Gate B  ]             v
    [ R3: Levl Pot ] --(Analog)--> [ U2: LM339 Comp 3 ] --(SIG_LEV)--->(Pin 5)--------->[              ] --(V_SAFE)--> [ R_BASE ] --> [ Q1: 2N2222 ]
    (Simulates Sensor)             [ Ref: 2.5V Divider]                                 [              ]                              [ NPN Base   ]
                                                                                                                                      [            ]
                                                                                                                                      [ Collector  ] --< (Sinks Current)
                                                                                                                                      [ Emitter    ]
                                                                                                                                             |
                                                                                                                                            GND
Schematic (ASCII)

Truth table

This table represents the cascaded logic (Temp AND Pressure AND Level).

Temp OK (A) Pres OK (B) Level OK (C) Intermediate (A·B) Final Output (V_SAFE) Action
0 0 0 0 0 Safe Mode (Off)
0 0 1 0 0 Safe Mode (Off)
0 1 0 0 0 Safe Mode (Off)
0 1 1 0 0 Safe Mode (Off)
1 0 0 0 0 Safe Mode (Off)
1 0 1 0 0 Safe Mode (Off)
1 1 0 1 0 Safe Mode (Off)
1 1 1 1 1 Inject Catalyst

Measurements and tests

  1. Individual Sensor Test: Adjust R1 (Temp) below the threshold. Verify SIG_TEMP goes HIGH (approx 5V). Repeat for R2 and R3.
  2. Logic Logic Validation: Set Temp and Pressure to «Safe» (High logic), but Level to «Unsafe» (Low logic). Measure U1 Pin 3 (Intermediate); it should be HIGH. Measure U1 Pin 6 (V_SAFE); it should be LOW.
  3. Full Activation: Set all three potentiometers to the «Safe» range. Verify V_SAFE is HIGH, Q1 saturates, and the Relay (K1) clicks «On».
  4. Response Time: Connect an oscilloscope channel 1 to SIG_LEV and channel 2 to V_SAFE. Toggle the Level switch and measure the propagation delay (typically nanoseconds for the gate, milliseconds for the relay).

SPICE netlist and simulation

Reference SPICE Netlist (ngspice) — excerptFull SPICE netlist (ngspice)

* Practical case: Safety interlock in a chemical reactor

* --- Models ---
* Generic NPN Transistor
.model 2N2222MOD NPN(IS=1E-14 VAF=100 BF=200 IKF=0.3 XTB=1.5 BR=3 CJC=8E-12 CJE=25E-12 TR=46.91E-9 TF=411.1E-12 ITF=0.6 VTF=1.7 XTF=3 RB=10 RC=1 RE=0.1)
* Flyback Diode
.model D1N4007 D(IS=7.02767n RS=0.03415 N=1.2686 EG=1.11 XTI=3 BV=1000 IBV=10m CJO=10p VJ=0.7 M=0.5 FC=0.5 TT=100n)
* Green LED Indicator
.model LED_GREEN D(IS=1e-22 RS=5 N=1.5 CJO=50p BV=5 IBV=10u EG=2.1)
* Voltage Controlled Switch for Open Collector Comparator
* Vt=0: Switch state changes when control voltage crosses 0V
* Ron=10: Low resistance when closed (Logic 0 / Low)
* Roff=100Meg: High resistance when open (Logic 1 / High via Pull-up)
.model SW_OC SW(Vt=0 Vh=0.001 Ron=10 Roff=100Meg)

* --- Power Supply ---
* V1: 5 V DC power supply
V1 VCC 0 DC 5

* --- Reference Voltage (R_REF) ---
* Function: Voltage dividers for reference thresholds (2.5 V)
* Wiring: Reference divider connects to U2 Input + (NODE_REF)
R_REF_A VCC NODE_REF 10k
R_REF_B NODE_REF 0 10k

* --- Sensors (Simulated with PWL Voltage Sources) ---
* R1, R2, R3 Potentiometers simulated by PWL sources at the wiper nodes.
* Logic: Low Voltage (<2.5V) = Safe. High Voltage (>2.5V) = Unsafe/Alarm.
* Sequence: T=Safe, then Temp Fault, then Pres Fault, then Level Fault.

* ... (truncated in public view) ...

Copy this content into a .cir file and run with ngspice.

🔒 Part of this section is premium. With the 7-day pass or the monthly membership you can access the full content (materials, wiring, detailed build, validation, troubleshooting, variants and checklist) and download the complete print-ready PDF pack.

* Practical case: Safety interlock in a chemical reactor

* --- Models ---
* Generic NPN Transistor
.model 2N2222MOD NPN(IS=1E-14 VAF=100 BF=200 IKF=0.3 XTB=1.5 BR=3 CJC=8E-12 CJE=25E-12 TR=46.91E-9 TF=411.1E-12 ITF=0.6 VTF=1.7 XTF=3 RB=10 RC=1 RE=0.1)
* Flyback Diode
.model D1N4007 D(IS=7.02767n RS=0.03415 N=1.2686 EG=1.11 XTI=3 BV=1000 IBV=10m CJO=10p VJ=0.7 M=0.5 FC=0.5 TT=100n)
* Green LED Indicator
.model LED_GREEN D(IS=1e-22 RS=5 N=1.5 CJO=50p BV=5 IBV=10u EG=2.1)
* Voltage Controlled Switch for Open Collector Comparator
* Vt=0: Switch state changes when control voltage crosses 0V
* Ron=10: Low resistance when closed (Logic 0 / Low)
* Roff=100Meg: High resistance when open (Logic 1 / High via Pull-up)
.model SW_OC SW(Vt=0 Vh=0.001 Ron=10 Roff=100Meg)

* --- Power Supply ---
* V1: 5 V DC power supply
V1 VCC 0 DC 5

* --- Reference Voltage (R_REF) ---
* Function: Voltage dividers for reference thresholds (2.5 V)
* Wiring: Reference divider connects to U2 Input + (NODE_REF)
R_REF_A VCC NODE_REF 10k
R_REF_B NODE_REF 0 10k

* --- Sensors (Simulated with PWL Voltage Sources) ---
* R1, R2, R3 Potentiometers simulated by PWL sources at the wiper nodes.
* Logic: Low Voltage (<2.5V) = Safe. High Voltage (>2.5V) = Unsafe/Alarm.
* Sequence: T=Safe, then Temp Fault, then Pres Fault, then Level Fault.

* R1: Temp Sensor Simulator
V_SENS_T NODE_T_SENS 0 PWL(0 1 100u 1 101u 4 200u 4 201u 1)

* R2: Pressure Sensor Simulator
V_SENS_P NODE_P_SENS 0 PWL(0 1 300u 1 301u 4 400u 4 401u 1)

* R3: Tank Level Simulator
V_SENS_L NODE_L_SENS 0 PWL(0 1 500u 1 501u 4 600u 4 601u 1)

* --- U2: LM339 Quad Comparator ---
* Function: Digitizes analog sensors. Open Collector Outputs.
* Logic: If V(In-) > V(In+), Switch closes to Ground (Output Low).
*        Else Switch opens (Output High via Pull-up).

* Comparator 1 (Temperature)
* Wiring: Wiper (NODE_T_SENS) to Input 1-, Ref to Input 1+, Output to SIG_TEMP
S_COMP1 SIG_TEMP 0 NODE_T_SENS NODE_REF SW_OC
* R_PU1: Pull-up for Comparator 1
R_PU1 VCC SIG_TEMP 4.7k

* Comparator 2 (Pressure)
* Wiring: Wiper (NODE_P_SENS) to Input 2-, Ref to Input 2+, Output to SIG_PRES
S_COMP2 SIG_PRES 0 NODE_P_SENS NODE_REF SW_OC
* R_PU2: Pull-up for Comparator 2
R_PU2 VCC SIG_PRES 4.7k

* Comparator 3 (Level)
* Wiring: Wiper (NODE_L_SENS) to Input 3-, Ref to Input 3+, Output to SIG_LEV
S_COMP3 SIG_LEV 0 NODE_L_SENS NODE_REF SW_OC
* R_PU3: Pull-up for Comparator 3
R_PU3 VCC SIG_LEV 4.7k

* --- U1: 74HC08 Quad 2-input AND ---
* Function: Safety Logic.
* Modeled using Behavioral Sources (Sigmoid function for HC logic levels).

* Gate 1 (Pins 1, 2, 3)
* Inputs: SIG_TEMP, SIG_PRES. Output: NODE_AND_INT
B_AND1 NODE_AND_INT 0 V = 5 * (1 / (1 + exp(-20*(V(SIG_TEMP)-2.5)))) * (1 / (1 + exp(-20*(V(SIG_PRES)-2.5))))

* Gate 2 (Pins 4, 5, 6)
* Inputs: NODE_AND_INT (Pin 4 connects to Pin 3), SIG_LEV. Output: V_SAFE
B_AND2 V_SAFE 0 V = 5 * (1 / (1 + exp(-20*(V(NODE_AND_INT)-2.5)))) * (1 / (1 + exp(-20*(V(SIG_LEV)-2.5))))

* --- Output Stage ---

* R_BASE: Transistor base current limiting
R_BASE V_SAFE NODE_BASE 1k

* Q1: 2N2222 NPN Transistor, Relay driver
* Wiring: Base to NODE_BASE, Emitter to 0, Collector to NODE_RELAY
Q1 NODE_RELAY NODE_BASE 0 2N2222MOD

* K1: 5 V Relay Coil
* Wiring: Connects between VCC and NODE_RELAY
* Modeled as Inductor and Series Resistor
L_K1 VCC NODE_RELAY_INT 10m
R_K1 NODE_RELAY_INT NODE_RELAY 100

* D1: Flyback protection
* Wiring: Anode to NODE_RELAY, Cathode to VCC
D1 NODE_RELAY VCC D1N4007

* D2 & R_LED: Indicator "Injection Active"
* Corrected Wiring: LED should be parallel to Relay Coil to indicate Activation.
* Path: VCC -> Resistor -> LED Anode -> LED Cathode -> Collector (NODE_RELAY).
* When Q1 is ON (Relay Active), NODE_RELAY is Low (~0.2V), LED turns ON.
R_LED VCC NODE_LED_A 330
D2 NODE_LED_A NODE_RELAY LED_GREEN

* --- Analysis Directives ---
* Transient analysis to observe the sequence of sensor faults
.tran 1u 800u

* Print required signals
.print tran V(NODE_T_SENS) V(NODE_P_SENS) V(NODE_L_SENS)
.print tran V(SIG_TEMP) V(SIG_PRES) V(SIG_LEV)
.print tran V(NODE_AND_INT) V(V_SAFE)
.print tran V(NODE_RELAY) V(NODE_BASE)

.end

Simulation Results (Transient Analysis)

Simulation Results (Transient Analysis)
Show raw data table (3828 rows)
Index   time            v(node_t_sens)  v(node_p_sens)  v(node_l_sens)
0	0.000000e+00	1.000000e+00	1.000000e+00	1.000000e+00
1	1.000000e-08	1.000000e+00	1.000000e+00	1.000000e+00
2	2.000000e-08	1.000000e+00	1.000000e+00	1.000000e+00
3	4.000000e-08	1.000000e+00	1.000000e+00	1.000000e+00
4	8.000000e-08	1.000000e+00	1.000000e+00	1.000000e+00
5	1.600000e-07	1.000000e+00	1.000000e+00	1.000000e+00
6	3.200000e-07	1.000000e+00	1.000000e+00	1.000000e+00
7	6.400000e-07	1.000000e+00	1.000000e+00	1.000000e+00
8	1.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
9	2.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
10	3.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
11	4.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
12	5.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
13	6.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
14	7.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
15	8.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
16	9.280000e-06	1.000000e+00	1.000000e+00	1.000000e+00
17	1.028000e-05	1.000000e+00	1.000000e+00	1.000000e+00
18	1.128000e-05	1.000000e+00	1.000000e+00	1.000000e+00
19	1.228000e-05	1.000000e+00	1.000000e+00	1.000000e+00
20	1.328000e-05	1.000000e+00	1.000000e+00	1.000000e+00
21	1.428000e-05	1.000000e+00	1.000000e+00	1.000000e+00
22	1.528000e-05	1.000000e+00	1.000000e+00	1.000000e+00
23	1.628000e-05	1.000000e+00	1.000000e+00	1.000000e+00
... (3804 more rows) ...

Common mistakes and how to avoid them

  1. Missing Pull-up Resistors: The LM339 comparator has an open-collector output. If you forget R_PU1/2/3, the logic gate inputs will float or remain LOW. Always tie outputs to VCC via a resistor (e.g., 4.7kΩ).
  2. Floating Unused Inputs: The 74HC08 is a CMOS device. If pins 9, 10, 12, 13 (Gates 3 and 4) are left floating, they pick up noise and increase power consumption. Connect unused inputs to GND.
  3. Inductive Kickback: Omitting D1 (Flyback diode) across the relay coil. This will generate a high voltage spike when the relay turns off, destroying transistor Q1 immediately.

Troubleshooting

  • Relay chatters (buzzing sound): The analog inputs are hovering exactly at the threshold voltage. Fix: Add a feedback resistor (hysteresis) between the comparator output and the non-inverting input.
  • Logic output is always HIGH: Check the comparator inputs. If the reference voltage is reversed (e.g., Ref > Signal vs Signal > Ref), the logic might be inverted.
  • Transistor gets hot but relay doesn’t switch: Q1 might be receiving insufficient base current, or the pinout (E-B-C) is incorrect. Fix: Verify R_BASE value and transistor pinout.

Possible improvements and extensions

  1. Latch Circuit: Add a feedback loop (or a Set-Reset latch) so that if safety is breached, the system shuts down and requires a manual «Reset» button press to restart, even if conditions return to normal.
  2. Fault Identification: Add red LEDs to the output of each comparator (inverted) to indicate exactly which variable (Temperature, Pressure, or Level) caused the shutdown.

More Practical Cases on Prometeo.blog

Find this product and/or books on this topic on Amazon

Go to Amazon

As an Amazon Associate, I earn from qualifying purchases. If you buy through this link, you help keep this project running.

Quick Quiz

Question 1: What is the primary function of the hardware-based safety interlock logic circuit described?




Question 2: Which component is used to digitize the analog sensor signals in this circuit?




Question 3: What logic state is required from the final control signal `V_SAFE` to activate the system?




Question 4: Which logic gate arrangement is used to process the digitized signals to ensure all conditions are met?




Question 5: In the context of industrial safety, what specific hazard does this system help prevent?




Question 6: What visual indicator confirms that the system is in the safe `1-1-1` state?




Question 7: What role do the simulated analog parameters (Temperature, Pressure, Level) play in this system?




Question 8: Which of the following is NOT listed as a use case for this type of safety interlock?




Question 9: What happens to the catalyst valve circuit when the relay activates?




Question 10: Why is this system described as a 'redundant' safety system?




Carlos Núñez Zorrilla
Carlos Núñez Zorrilla
Electronics & Computer Engineer

Telecommunications Electronics Engineer and Computer Engineer (official degrees in Spain).

Follow me: