1. Purpose and prerequisites
Combinational logic calculates an output from the inputs present now. AND combines requirements, OR combines alternatives, NOT reverses a condition, and XOR detects a difference. These functions become the equations inside decoders, adders and processor control logic. This build places all four chips on one board so the same A and B can be compared simultaneously.
Before starting: know how the breadboard’s five-hole strips and split power rails work. Use regulated 5 V, qualified button modules with built-in pull-downs and the specified 5 V indicators. The bare seven-segment displays use the source inventory’s segment resistors. No observation buffer or added clock-conditioning circuit is used.
2. Behavior, symbols and observations
A and B are active-high data levels. There is no clock and no remembered state. The NOT gate uses A only. One gate per package is used; all other inputs are tied to GND and their outputs stay open. The 4069 has a different pin assignment from the other three chips: its first output is pin 2, not pin 3.

3. Parts you need
| Part | Quantity | LSSK row | Purpose |
|---|---|---|---|
| CD4081B · DIP | 1 | 10 | Logic IC |
| CD4071B · DIP | 1 | 20 | Logic IC |
| CD4069UB · DIP | 1 | 24 | Logic IC |
| CD4070B · DIP | 1 | 2 | Logic IC |
| 830-contact breadboard | 1 | 45 | Main board(s) |
| 5 V regulated power module | 1 | 56 | Regulated output to logic rails |
| USB-to-9 V cable | 1 | 57 | Input to compatible regulator module |
| Active-high button module | 2 | 65 | One per data/control bit; built-in pull-down |
| 5 V current-limited LED | 4 | 46 | Direct logic indication |
| M–M jumper | 42 | 70 | Board and inter-board wiring |
| M–F lead | 16 | 71 | External modules/display terminals; adapt connector ends to actual parts |
CSV · Quantities cover this build, not supplier packs. All 58 leads are listed in the wiring schedule; no reserve is included.
4. Chip functions, pins and polarity

Pin diagrams are top views with the notch UP. In the horizontal breadboard drawing the notch turns LEFT, so pin 1 is below the trench. Signal names ending in _n and labels with / are active low. Q1/A1 on a chip corresponds to bit [0] in RTL. Power pins are physical connections and are omitted from ideal HDL models.
U1 · CD4081B · all pins
Manufacturer pin/function reference
| Pin | Function | Direction | Net | Hole |
|---|---|---|---|---|
| 1 | A1 | Input | a | B1.f7 |
| 2 | B1 | Input | b | B1.f8 |
| 3 | Y1 | Output | y_and | B1.f9 |
| 4 | Y2 | Output | NC — leave open | B1.f10 |
| 5 | B2 | Input | GND | B1.f11 |
| 6 | A2 | Input | GND | B1.f12 |
| 7 | VSS | Power | GND | B1.f13 |
| 8 | A3 | Input | GND | B1.e13 |
| 9 | B3 | Input | GND | B1.e12 |
| 10 | Y3 | Output | NC — leave open | B1.e11 |
| 11 | Y4 | Output | NC — leave open | B1.e10 |
| 12 | B4 | Input | GND | B1.e9 |
| 13 | A4 | Input | GND | B1.e8 |
| 14 | VDD | Power | +5V | B1.e7 |
U2 · CD4071B · all pins
Manufacturer pin/function reference
| Pin | Function | Direction | Net | Hole |
|---|---|---|---|---|
| 1 | A1 | Input | a | B1.f20 |
| 2 | B1 | Input | b | B1.f21 |
| 3 | Y1 | Output | y_or | B1.f22 |
| 4 | Y2 | Output | NC — leave open | B1.f23 |
| 5 | B2 | Input | GND | B1.f24 |
| 6 | A2 | Input | GND | B1.f25 |
| 7 | VSS | Power | GND | B1.f26 |
| 8 | A3 | Input | GND | B1.e26 |
| 9 | B3 | Input | GND | B1.e25 |
| 10 | Y3 | Output | NC — leave open | B1.e24 |
| 11 | Y4 | Output | NC — leave open | B1.e23 |
| 12 | B4 | Input | GND | B1.e22 |
| 13 | A4 | Input | GND | B1.e21 |
| 14 | VDD | Power | +5V | B1.e20 |
U3 · CD4069UB · all pins
Manufacturer pin/function reference
| Pin | Function | Direction | Net | Hole |
|---|---|---|---|---|
| 1 | A1 | Input | a | B1.f33 |
| 2 | Y1 | Output | y_not | B1.f34 |
| 3 | A2 | Input | GND | B1.f35 |
| 4 | Y2 | Output | NC — leave open | B1.f36 |
| 5 | A3 | Input | GND | B1.f37 |
| 6 | Y3 | Output | NC — leave open | B1.f38 |
| 7 | VSS | Power | GND | B1.f39 |
| 8 | Y4 | Output | NC — leave open | B1.e39 |
| 9 | A4 | Input | GND | B1.e38 |
| 10 | Y5 | Output | NC — leave open | B1.e37 |
| 11 | A5 | Input | GND | B1.e36 |
| 12 | Y6 | Output | NC — leave open | B1.e35 |
| 13 | A6 | Input | GND | B1.e34 |
| 14 | VDD | Power | +5V | B1.e33 |
U4 · CD4070B · all pins
Manufacturer pin/function reference
| Pin | Function | Direction | Net | Hole |
|---|---|---|---|---|
| 1 | A1 | Input | a | B1.f46 |
| 2 | B1 | Input | b | B1.f47 |
| 3 | Y1 | Output | y_xor | B1.f48 |
| 4 | Y2 | Output | NC — leave open | B1.f49 |
| 5 | B2 | Input | GND | B1.f50 |
| 6 | A2 | Input | GND | B1.f51 |
| 7 | VSS | Power | GND | B1.f52 |
| 8 | A3 | Input | GND | B1.e52 |
| 9 | B3 | Input | GND | B1.e51 |
| 10 | Y3 | Output | NC — leave open | B1.e50 |
| 11 | Y4 | Output | NC — leave open | B1.e49 |
| 12 | B4 | Input | GND | B1.e48 |
| 13 | A4 | Input | GND | B1.e47 |
| 14 | VDD | Power | +5V | B1.e46 |
5. Schematic 1 · Generic logic

This abstraction specifies the behavior. The following RTL has the same named inputs and outputs as the pin-connected design. A vector such as q[3:0] is four wires, with q[0] the least-significant bit.
6. Schematic 2 · Chip connections

Identical net names join, including names on different packages. Distinct outputs are never joined. Each display segment path is decoder output → its own 560 Ω resistor → matching display anode; the full endpoint table below includes these passive connections. Button/clock modules use VCC=+5 V, GND=GND and OUT=the named input.
7. Schematic 3 · Breadboard and assembly

B1/B2 identify boards. Each a–e strip at one column is connected internally; f–j is a separate strip. TP/BP are positive rails, TG/BG are ground. Bridge each illustrated rail at 25–26 and join top/bottom rails. Follow the actual board’s continuity if its rails differ. Matching inter-board W labels denote the two ends of one wire.
The boxes outside the main board show button, clock and display terminals by function, not connector pin order or an assumed display package. Support these parts beside the board and use the named leads; map the actual display pins first. The two regulator output leads are included; the upstream USB-to-9 V cable feeds only the compatible regulator input. Logic rails receive 5 V.
- Install U1=4081, U2=4071, U3=4069 and U4=4070 across the trench, with notches to the left. Wire all supplies and unused inputs before signals.
- Connect S1.OUT to all four first A inputs (pin 1). Connect S2.OUT to pin 2 of U1, U2 and U4. U3.2 is an output; never connect it to S2.
- Connect the four outputs to four specified 5 V indicators, with their cathodes at GND.
- Apply A,B = 00, 01, 10, 11. Record the four LEDs before looking at the table. For 00 only NOT lights; for 11 AND and OR light.
Exact jumper schedule
| ID | Net | From | To |
|---|---|---|---|
| W001 | +5V | B1.TP25 | B1.TP26 |
| W002 | GND | B1.TG25 | B1.TG26 |
| W003 | +5V | B1.BP25 | B1.BP26 |
| W004 | GND | B1.BG25 | B1.BG26 |
| W005 | +5V | B1.TP1 | B1.BP1 |
| W006 | GND | B1.TG1 | B1.BG1 |
| W007 | a | B1.j7 | B1.j20 |
| W008 | a | B1.i20 | B1.j33 |
| W009 | a | B1.i33 | B1.j46 |
| W010 | a | B1.i46 | S1.OUT |
| W011 | b | B1.j8 | B1.j21 |
| W012 | b | B1.i21 | B1.j47 |
| W013 | b | B1.i47 | S2.OUT |
| W014 | y_and | B1.j9 | L1.A |
| W015 | GND | B1.j11 | B1.BG2 |
| W016 | GND | B1.j12 | B1.BG3 |
| W017 | GND | B1.j13 | B1.BG4 |
| W018 | GND | B1.a13 | B1.TG2 |
| W019 | GND | B1.a12 | B1.TG3 |
| W020 | GND | B1.a9 | B1.TG4 |
| W021 | GND | B1.a8 | B1.TG5 |
| W022 | GND | B1.j24 | B1.BG5 |
| W023 | GND | B1.j25 | B1.BG6 |
| W024 | GND | B1.j26 | B1.BG7 |
| W025 | GND | B1.a26 | B1.TG6 |
| W026 | GND | B1.a25 | B1.TG7 |
| W027 | GND | B1.a22 | B1.TG8 |
| W028 | GND | B1.a21 | B1.TG9 |
| W029 | GND | B1.j35 | B1.BG8 |
| W030 | GND | B1.j37 | B1.BG9 |
| W031 | GND | B1.j39 | B1.BG10 |
| W032 | GND | B1.a38 | B1.TG10 |
| W033 | GND | B1.a36 | B1.TG11 |
| W034 | GND | B1.a34 | B1.TG12 |
| W035 | GND | B1.j50 | B1.BG11 |
| W036 | GND | B1.j51 | B1.BG12 |
| W037 | GND | B1.j52 | B1.BG13 |
| W038 | GND | B1.a52 | B1.TG13 |
| W039 | GND | B1.a51 | B1.TG14 |
| W040 | GND | B1.a48 | B1.TG15 |
| W041 | GND | B1.a47 | B1.TG16 |
| W042 | GND | S1.GND | B1.BG14 |
| W043 | GND | S2.GND | B1.BG15 |
| W044 | GND | PWR.GND | B1.BG16 |
| W045 | GND | L1.K | B1.BG17 |
| W046 | GND | L2.K | B1.BG18 |
| W047 | GND | L3.K | B1.BG19 |
| W048 | GND | L4.K | B1.BG20 |
| W049 | +5V | B1.a7 | B1.TP2 |
| W050 | +5V | B1.a20 | B1.TP3 |
| W051 | +5V | B1.a33 | B1.TP4 |
| W052 | +5V | B1.a46 | B1.TP5 |
| W053 | +5V | S1.VCC | B1.BP2 |
| W054 | +5V | S2.VCC | B1.BP3 |
| W055 | +5V | PWR.+5V | B1.BP4 |
| W056 | y_or | B1.j22 | L2.A |
| W057 | y_not | B1.j34 | L3.A |
| W058 | y_xor | B1.j48 | L4.A |
8. Generic synthesizable SystemVerilog
rtl/basic_gates.sv
// Synthesizable, zero-delay generic circuit. Segment order: { g, f, e, d, c, b, a }.
module basic_gates
(
input a,
input b,
output y_and,
output y_or,
output y_not,
output y_xor
);
assign y_and = a & b;
assign y_or = a | b;
assign y_not = ~ a;
assign y_xor = a ^ b;
endmodule
The style guide requires four-space indentation and plain input/output net ports. RTL, chip models and wrappers contain no timeunit, timeprecision or `timescale; each testbench file uses `timescale 1ns / 1ps before its module. always_ff describes edge-triggered state; assign/always_comb describe combinational logic. The display lesson deliberately uses always_latch because LE controls a transparent latch.
9. CMOS chip models
Models describe ideal powered logic with no propagation delays, loading, bounce or metastability. The 4511 model uses TI’s digit shapes. The 4029 model covers the wired JAM=0000 configuration. CD4013 SET_TIED_LOW=1 selects the synthesizable configuration used here; its general SET/RESET branch is for simulation. CD4511 TRANSPARENT=1 specializes the adder’s fixed LE=0 connection.
models/cd4069ub.sv
// Synthesizable ideal functional model; physical power pins omitted.
module cd4069ub
(
input p1_a1,
input p3_a2,
input p5_a3,
input p9_a4,
input p11_a5,
input p13_a6,
output p2_y1,
output p4_y2,
output p6_y3,
output p8_y4,
output p10_y5,
output p12_y6
);
assign p2_y1 = ~ p1_a1;
assign p4_y2 = ~ p3_a2;
assign p6_y3 = ~ p5_a3;
assign p8_y4 = ~ p9_a4;
assign p10_y5 = ~ p11_a5;
assign p12_y6 = ~ p13_a6;
endmodule
models/cd4070b.sv
// Synthesizable ideal functional model; physical power pins omitted.
module cd4070b
(
input p1_a1,
input p2_b1,
input p5_b2,
input p6_a2,
input p8_a3,
input p9_b3,
input p12_b4,
input p13_a4,
output p3_y1,
output p4_y2,
output p10_y3,
output p11_y4
);
assign p3_y1 = p1_a1 ^ p2_b1;
assign p4_y2 = p6_a2 ^ p5_b2;
assign p10_y3 = p8_a3 ^ p9_b3;
assign p11_y4 = p13_a4 ^ p12_b4;
endmodule
models/cd4071b.sv
// Synthesizable ideal functional model; physical power pins omitted.
module cd4071b
(
input p1_a1,
input p2_b1,
input p5_b2,
input p6_a2,
input p8_a3,
input p9_b3,
input p12_b4,
input p13_a4,
output p3_y1,
output p4_y2,
output p10_y3,
output p11_y4
);
assign p3_y1 = p1_a1 | p2_b1;
assign p4_y2 = p6_a2 | p5_b2;
assign p10_y3 = p8_a3 | p9_b3;
assign p11_y4 = p13_a4 | p12_b4;
endmodule
models/cd4081b.sv
// Synthesizable ideal functional model; physical power pins omitted.
module cd4081b
(
input p1_a1,
input p2_b1,
input p5_b2,
input p6_a2,
input p8_a3,
input p9_b3,
input p12_b4,
input p13_a4,
output p3_y1,
output p4_y2,
output p10_y3,
output p11_y4
);
assign p3_y1 = p1_a1 & p2_b1;
assign p4_y2 = p6_a2 & p5_b2;
assign p10_y3 = p8_a3 & p9_b3;
assign p11_y4 = p13_a4 & p12_b4;
endmodule
10. Pin-connected SystemVerilog
rtl/basic_gates_chips.sv
// Synthesizable pin-connected circuit, generated from netlist data.
// Supply pins and passive display components are physical only.
module basic_gates_chips
(
input a,
input b,
output y_and,
output y_or,
output y_not,
output y_xor
);
cd4081b u1
(
.p1_a1 (a),
.p2_b1 (b),
.p3_y1 (y_and),
.p4_y2 (),
.p5_b2 (1'b0),
.p6_a2 (1'b0),
.p8_a3 (1'b0),
.p9_b3 (1'b0),
.p10_y3 (),
.p11_y4 (),
.p12_b4 (1'b0),
.p13_a4 (1'b0)
);
cd4071b u2
(
.p1_a1 (a),
.p2_b1 (b),
.p3_y1 (y_or),
.p4_y2 (),
.p5_b2 (1'b0),
.p6_a2 (1'b0),
.p8_a3 (1'b0),
.p9_b3 (1'b0),
.p10_y3 (),
.p11_y4 (),
.p12_b4 (1'b0),
.p13_a4 (1'b0)
);
cd4069ub u3
(
.p1_a1 (a),
.p2_y1 (y_not),
.p3_a2 (1'b0),
.p4_y2 (),
.p5_a3 (1'b0),
.p6_y3 (),
.p8_y4 (),
.p9_a4 (1'b0),
.p10_y5 (),
.p11_a5 (1'b0),
.p12_y6 (),
.p13_a6 (1'b0)
);
cd4070b u4
(
.p1_a1 (a),
.p2_b1 (b),
.p3_y1 (y_xor),
.p4_y2 (),
.p5_b2 (1'b0),
.p6_a2 (1'b0),
.p8_a3 (1'b0),
.p9_b3 (1'b0),
.p10_y3 (),
.p11_y4 (),
.p12_b4 (1'b0),
.p13_a4 (1'b0)
);
endmodule
This implementation is generated from the same physical pin/net database as the schematic tables. Open unused outputs with empty named port connections; physical unused inputs remain tied to their listed levels.
11. Testbenches and simulator scripts
The core bench compares both implementations against independent expected values. The integration bench checks both variants through the full BGM wrappers and Tiny Tapeout wrapper, including segment order, scan selection and output enable. Inputs change after a sampling/settling step; clocks have independent generators. Necessary # 1 delays allow combinational/NBA settling or observe asynchronous reset before another edge. Watchdogs count cycles.
cd breadboard/basics_gates
./scripts/run_icarus.sh
./scripts/run_questa.sh
./scripts/run_verilator.sh
python3 scripts/check_synthesis.py| Tool | Recorded result |
|---|---|
| icarus14 | PASS |
| verilator | PASS |
| synthesis | PASS |
| icarus12 | PASS |
| questa | RUNTIME BLOCKED |
| questa_compile_all | PASS |
Compatibility target: Icarus 13, Questa and current Verilator. Available binaries here: Icarus 12 and 14 development, Verilator 5.053 development, Questa 2025.2. Icarus 13 itself is not installed. Questa compilation is checked separately from execution: this sandbox reports an invalid license host when loading simulation. No Questa runtime pass is claimed. Synthesis uses the built-in Yosys read_verilog -sv reader; Slang is optional with --frontend slang. The simulation runners provide a 1ns/1ps default for RTL without time declarations in Questa and Verilator.
tb/tb_basic_gates.sv
`timescale 1ns / 1ps
module tb_basic_gates;
localparam period = 20;
localparam timeout_cycles = 3000;
logic clk = 1'b0;
always # (period / 2) clk = ~ clk;
logic a = '0;
logic b = '0;
logic y_and_g;
logic y_and_c;
logic y_or_g;
logic y_or_c;
logic y_not_g;
logic y_not_c;
logic y_xor_g;
logic y_xor_c;
int checks = 0;
basic_gates dut_g
(
.a (a),
.b (b),
.y_and (y_and_g),
.y_or (y_or_g),
.y_not (y_not_g),
.y_xor (y_xor_g)
);
basic_gates_chips dut_c
(
.a (a),
.b (b),
.y_and (y_and_c),
.y_or (y_or_c),
.y_not (y_not_c),
.y_xor (y_xor_c)
);
task check (input logic expected_y_and, input logic expected_y_or, input logic expected_y_not, input logic expected_y_xor);
if (y_and_g !== expected_y_and || y_and_c !== expected_y_and)
$fatal (1, "y_and: generic=%h chips=%h expected=%h", y_and_g, y_and_c, expected_y_and);
if (y_or_g !== expected_y_or || y_or_c !== expected_y_or)
$fatal (1, "y_or: generic=%h chips=%h expected=%h", y_or_g, y_or_c, expected_y_or);
if (y_not_g !== expected_y_not || y_not_c !== expected_y_not)
$fatal (1, "y_not: generic=%h chips=%h expected=%h", y_not_g, y_not_c, expected_y_not);
if (y_xor_g !== expected_y_xor || y_xor_c !== expected_y_xor)
$fatal (1, "y_xor: generic=%h chips=%h expected=%h", y_xor_g, y_xor_c, expected_y_xor);
checks = checks + 1;
endtask
initial
begin
$dumpfile ("trace.vcd");
$dumpvars (0, tb_basic_gates);
for (int i = 0; i < 4; i ++)
begin
@ (posedge clk);
a = 1' (i / 2);
b = 1' (i % 2);
# 1; // Combinational settling after input changes.
case (i)
0: check (0, 0, 1, 0);
1: check (0, 1, 1, 1);
2: check (0, 1, 0, 1);
3: check (1, 1, 0, 0);
endcase
end
$display ("PASS basic_gates: %0d independent checks", checks);
$finish;
end
initial
begin
repeat (timeout_cycles) @ (posedge clk);
$fatal (1, "Timeout in clock cycles");
end
endmodule
tb/tb_integrations.sv
`timescale 1ns / 1ps
module tb_integrations;
localparam period = 20;
logic clk = 1'b0;
logic rst = 1'b0;
logic ena = 1'b1;
logic [7:0] data = '0;
logic [3:0] aux = '0;
logic [7:0] expected_led;
logic [20:0] expected_segments;
logic [7:0] lab_led [2], hack_led [2], tt_out [2];
logic [7:0] lab_seg [2], hack_seg [2], lab_digit [2], hack_digit [2];
logic [7:0] tt_uio [2], tt_oe [2];
always # (period / 2) clk = ~ clk;
exercise_bridge expected
(
.clk (clk),
.rst (rst),
.data (data),
.aux (aux),
.led (expected_led),
.segments (expected_segments)
);
for (genvar v = 0; v < 2; v ++)
begin : versions
wire [99:0] lab_gpio = { 96'b0, aux };
wire [3:0] hack_gpio = aux;
lab_top # (.CHIP_MODEL (v), .SCAN_BITS (4)) lab
(
.clk (clk),
.slow_clk (clk),
.rst (rst),
.key (4'b0),
.sw (data),
.led (lab_led [v]),
.abcdefgh (lab_seg [v]),
.digit (lab_digit [v]),
.x (10'b0),
.y (9'b0),
.red (),
.green (),
.blue (),
.mic (24'b0),
.sound (),
.uart_rx (1'b1),
.uart_tx (),
.gpio (lab_gpio)
);
hackathon_top # (.CHIP_MODEL (v), .SCAN_BITS (4)) hack
(
.clock (clk),
.slow_clock (clk),
.reset (rst),
.key (data),
.led (hack_led [v]),
.abcdefgh (hack_seg [v]),
.digit (hack_digit [v]),
.x (10'b0),
.y (9'b0),
.red (),
.green (),
.blue (),
.gpio (hack_gpio)
);
tt_um_basic_gates # (.CHIP_MODEL (v)) tt
(
.ui_in (data),
.uo_out (tt_out [v]),
.uio_in ({ 4'b0, aux }),
.uio_out (tt_uio [v]),
.uio_oe (tt_oe [v]),
.ena (ena),
.clk (clk),
.rst_n (~ rst)
);
end
initial
begin
@ (posedge clk);
# 1;
rst = 1'b1;
# 1; // Let asynchronous reset propagate through wrappers.
rst = 1'b0;
for (int i = 0; i < 80; i ++)
begin
logic [6:0] scan_seg;
logic [7:0] scan_digits;
logic [7:0] tt_expected;
int phase;
@ (posedge clk);
# 1; // NBA updates, scan mux and wrapper outputs settle.
phase = ((i + 1) % 16) / 4;
scan_digits = phase < 3 ? (8'b1 << phase) : 8'b0;
scan_seg = phase < 3 ? 7' (expected_segments >> (phase * 7)) : 7'b0;
tt_expected = expected_led;
for (int v = 0; v < 2; v ++)
begin
if (lab_led [v] !== expected_led || hack_led [v] !== expected_led)
$fatal (1, "Platform data mapping, variant %0d", v);
if (lab_digit [v] !== scan_digits || hack_digit [v] !== scan_digits)
$fatal (1, "Digit selection/polarity");
if (lab_seg [v] !== { scan_seg [0], scan_seg [1], scan_seg [2],
scan_seg [3], scan_seg [4], scan_seg [5], scan_seg [6], 1'b0 }
|| hack_seg [v] !== lab_seg [v])
$fatal (1, "BGM segment bit order");
if (tt_out [v] !== (ena ? tt_expected : 8'b0)
|| tt_oe [v] !== (ena ? 8'hf0 : 8'b0)
|| tt_uio [v] !== (ena ? { expected_led [3:0], 4'b0 } : 8'b0))
$fatal (1, "Tiny Tapeout polarity, selector or output enable");
end
data = 8' (i * 17);
aux = 4' (i);
ena = (i % 5 != 0);
end
$display ("PASS integrations: 80 steps, both variants, BGM scan and Tiny Tapeout mapping/enable");
$finish;
end
initial
begin
repeat (100) @ (posedge clk);
$fatal (1, "Integration timeout in cycles");
end
endmodule
scripts/run_icarus.sh
#!/usr/bin/env bash
set -euo pipefail
exec "$(dirname -- "${BASH_SOURCE[0]}")/run.sh" icarus
scripts/run_questa.sh
#!/usr/bin/env bash
set -euo pipefail
# Preserve explicit tool choices; otherwise find a local Quartus installation.
questa_bin=${QUESTA_BIN:-}
if [[ -z "$questa_bin" ]]; then
if command -v "${VSIM:-vsim}" > /dev/null 2>&1; then
questa_bin=$(dirname -- "$(command -v "${VSIM:-vsim}")")
else
for candidate in "$HOME"/altera_lite/*/questa_fse/bin \
"$HOME"/intelFPGA_lite/*/questa_fse/bin \
/opt/altera_lite/*/questa_fse/bin \
/opt/intelFPGA_lite/*/questa_fse/bin; do
if [[ -x "$candidate/vsim" ]]; then
questa_bin=$candidate
break
fi
done
fi
fi
if [[ -n "$questa_bin" ]]; then
export VLIB=${VLIB:-$questa_bin/vlib}
export VMAP=${VMAP:-$questa_bin/vmap}
export VLOG=${VLOG:-$questa_bin/vlog}
export VSIM=${VSIM:-$questa_bin/vsim}
fi
# Read the user's existing license; never copy it into the project or archive.
if [[ -z "${SALT_LICENSE_SERVER:-}" && -f "$HOME/flexlm/license.dat" ]]; then
export SALT_LICENSE_SERVER="$HOME/flexlm/license.dat"
fi
exec "$(dirname -- "${BASH_SOURCE[0]}")/run.sh" questa
scripts/run_verilator.sh
#!/usr/bin/env bash
set -euo pipefail
exec "$(dirname -- "${BASH_SOURCE[0]}")/run.sh" verilator
scripts/run.sh
#!/usr/bin/env bash
set -euo pipefail
exercise_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
simulator=${1:-icarus}
build_dir="$exercise_dir/build/$simulator"
mkdir -p "$build_dir"
cd "$build_dir"
sources=("$exercise_dir"/rtl/*.sv "$exercise_dir"/models/*.sv "$exercise_dir"/integration/*.sv "$exercise_dir"/integration/bgm_lab/*.sv "$exercise_dir"/integration/bgm_hackathon/*.sv "$exercise_dir"/integration/tinytapeout/project.v)
for bench in "$exercise_dir"/tb/*.sv; do
top=$(basename "$bench" .sv)
case "$simulator" in
icarus)
"${IVERILOG:-iverilog}" -g2012 -Wall -s "$top" -o "$top.vvp" "${sources[@]}" "$bench" > "$top.compile.log" 2>&1 || { cat "$top.compile.log"; exit 1; }
"${VVP:-vvp}" "$top.vvp" | tee "$top.log"
;;
questa)
[[ -f modelsim.ini ]] || "${VMAP:-vmap}" -c > /dev/null
[[ -d work ]] || "${VLIB:-vlib}" work
"${VLOG:-vlog}" -sv -timescale 1ns/1ps -work work "${sources[@]}" "$bench" > "$top.compile.log" 2>&1 || { cat "$top.compile.log"; exit 1; }
"${VSIM:-vsim}" -batch -onfinish exit "work.$top" -do "onerror {quit -code 1}; onbreak {quit -code 1}; run -all; quit -code 0" 2>&1 | tee "$top.log"
;;
verilator)
"${VERILATOR:-verilator}" --binary --timing --trace --timescale 1ns/1ps --top-module "$top" --Mdir "obj_$top" -Wno-PINCONNECTEMPTY -Wno-DECLFILENAME -j 2 "${sources[@]}" "$bench" > "$top.compile.log" 2>&1 || { cat "$top.compile.log"; exit 1; }
"./obj_$top/V$top" | tee "$top.log"
;;
*) echo "Usage: $0 {icarus|questa|verilator}" >&2; exit 2 ;;
esac
grep -q 'PASS ' "$top.log" || { echo "Missing PASS: $top" >&2; exit 1; }
done
scripts/check_synthesis.py
#!/usr/bin/env python3
"""Check both cores using the built-in Yosys reader, or optionally Slang."""
import argparse
import os
from pathlib import Path
import subprocess
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--frontend', choices=['verilog', 'slang'], default='verilog')
args = parser.parse_args()
exercise = Path(__file__).resolve().parents[1]
build = exercise / 'build/synthesis'
build.mkdir(parents=True, exist_ok=True)
sources = sorted((exercise / 'rtl').glob('*.sv'))
sources += sorted((exercise / 'models').glob('*.sv'))
# Fixed relative source names also work when the exercise directory has spaces.
filenames = ' '.join(p.relative_to(exercise).as_posix() for p in sources)
yosys = os.environ.get('YOSYS', 'yosys')
for top in ['basic_gates', 'basic_gates_chips']:
read = (f'read_slang --top {top}' if args.frontend == 'slang'
else 'read_verilog -sv')
commands = (f'{read} {filenames}; '
f'synth -top {top} -flatten; check -assert; stat')
log = build / f'{top}.log'
with log.open('w') as output:
plugin = ['-m', 'slang'] if args.frontend == 'slang' else []
result = subprocess.run([yosys, '-Q'] + plugin + ['-p', commands],
cwd=exercise, stdout=output, stderr=subprocess.STDOUT)
if result.returncode:
print(log.read_text())
raise SystemExit(result.returncode)
print(f'PASS synthesis: {top} (Yosys, {args.frontend} frontend); {log}')
if __name__ == '__main__':
main()
12. BGM lab_top integration
data[0]=A; data[1]=B. led[3:0]={XOR, NOT A, OR, AND}.
The full lab_top interface is supplied: sw[7:0] provides data, GPIO[3:0] provides aux, slow_clk clocks sequential lessons, and rst resets them. LEDs show the mapped logical outputs. Use at least eight switches for the adder and at least three digit positions for its scanned display. Unused sound/video outputs have defined values.
CHIP_MODEL=0 selects generic RTL; 1 selects chip-connected RTL. The adapter converts internal segment order {g,f,e,d,c,b,a} to BGM {a,b,c,d,e,f,g,dp}, active high. The scan module cycles SUM, B, A and a blank slot using the fast clock; it is platform display logic, not an extra breadboard clock phase. For the other lessons, only the first display slot has data or the display is blank.
python3 scripts/stage_integration.py bgm_lab /tmp/basics_gates_bgm_labStage into an empty directory, then copy the selected wrapper and all staged RTL/models into a new BGM lab/problem. Add the listed files in sources.f to the board project; replace its existing top, do not compile two copies. The wrapper alone is not a board pin-constraint file. Board-specific polarity and constraints remain the BGM infrastructure’s responsibility.
integration/bgm_lab/lab_top.sv
// Full BGM interface. Requires w_sw >= 8 and w_gpio >= 4.
// The adder uses three display positions; the 4511 lesson uses one.
module lab_top
# (
parameter SCAN_BITS = 16,
parameter CHIP_MODEL = 0,
parameter clk_mhz = 50,
parameter w_key = 4,
parameter w_sw = 8,
parameter w_led = 8,
parameter w_digit = 8,
parameter w_gpio = 100,
parameter screen_width = 640,
parameter screen_height = 480,
parameter w_red = 4,
parameter w_green = 4,
parameter w_blue = 4,
parameter w_x = $clog2 (screen_width),
parameter w_y = $clog2 (screen_height)
)
(
input clk,
input slow_clk,
input rst,
// Keys, switches, LEDs
input [w_key - 1:0] key,
input [w_sw - 1:0] sw,
output [w_led - 1:0] led,
// A dynamic seven-segment display
output [ 7:0] abcdefgh,
output [w_digit - 1:0] digit,
// Graphics
input [w_x - 1:0] x,
input [w_y - 1:0] y,
output [w_red - 1:0] red,
output [w_green - 1:0] green,
output [w_blue - 1:0] blue,
// Microphone, sound output and UART
input [ 23:0] mic,
output [ 15:0] sound,
input uart_rx,
output uart_tx,
// General-purpose Input/Output
inout [w_gpio - 1:0] gpio
);
logic [7:0] exercise_led;
logic [20:0] segments;
logic [7:0] scan_digit;
exercise_bridge # (.CHIP_MODEL (CHIP_MODEL)) exercise
(
.clk (slow_clk),
.rst (rst),
.data (8' (sw)),
.aux (4' (gpio)),
.led (exercise_led),
.segments (segments)
);
exercise_scan # (.SCAN_BITS (SCAN_BITS)) scan
(
.clk (clk),
.rst (rst),
.segments (segments),
.abcdefgh (abcdefgh),
.digit (scan_digit)
);
assign led = w_led' (exercise_led);
assign digit = w_digit' (scan_digit);
assign sound = '0;
assign uart_tx = 1'b1;
assign red = '0;
assign green = '0;
assign blue = '0;
assign gpio = 'z;
endmodule
integration/exercise_bridge.sv
// Synthesizable platform adapter. Not part of the breadboard circuit.
module exercise_bridge
# (
parameter CHIP_MODEL = 0
)
(
input clk,
input rst,
input [7:0] data,
input [3:0] aux,
output [7:0] led,
output [20:0] segments
);
logic y_and;
logic y_or;
logic y_not;
logic y_xor;
generate
if (CHIP_MODEL == 0)
begin : generic_version
basic_gates dut
(
.a (data [0]),
.b (data [1]),
.y_and (y_and),
.y_or (y_or),
.y_not (y_not),
.y_xor (y_xor)
);
end
else
begin : chip_version
basic_gates_chips dut
(
.a (data [0]),
.b (data [1]),
.y_and (y_and),
.y_or (y_or),
.y_not (y_not),
.y_xor (y_xor)
);
end
endgenerate
assign led = { 4'b0, y_xor, y_not, y_or, y_and };
assign segments = '0;
endmodule
integration/exercise_scan.sv
// Synthesizable scan adapter: fast infrastructure clock, not slow exercise clock.
module exercise_scan
# (
parameter SCAN_BITS = 16
)
(
input clk,
input rst,
input [20:0] segments,
output [7:0] abcdefgh,
output logic [7:0] digit
);
logic [SCAN_BITS - 1:0] phase;
logic [6:0] selected;
always_ff @ (posedge clk or posedge rst)
if (rst)
phase <= '0;
else
phase <= phase + 1'b1;
always_comb
begin
selected = '0;
digit = '0;
case (phase [SCAN_BITS - 1 -: 2])
2'd0: begin selected = segments [ 6: 0]; digit = 8'b0000_0001; end
2'd1: begin selected = segments [13: 7]; digit = 8'b0000_0010; end
2'd2: begin selected = segments [20:14]; digit = 8'b0000_0100; end
default: begin end
endcase
end
// BGM order [7:0] = { a,b,c,d,e,f,g,dp }, active high.
assign abcdefgh = { selected [0], selected [1], selected [2],
selected [3], selected [4], selected [5],
selected [6], 1'b0 };
endmodule
13. BGM hackathon_top integration
data[0]=A; data[1]=B. led[3:0]={XOR, NOT A, OR, AND}.
BGM names this module hackathon_top (with h). This wrapper matches the current 800×480 example: x[9:0], y[8:0]. key[7:0] provides data; GPIO[3:0] provides aux. slow_clock clocks the lesson; reset is active high. Keys are live levels, so hold the required combination or use the board’s input facilities. The fast clock drives display scanning only.
CHIP_MODEL=0 selects generic RTL; 1 selects chip-connected RTL. The adapter converts internal segment order {g,f,e,d,c,b,a} to BGM {a,b,c,d,e,f,g,dp}, active high. The scan module cycles SUM, B, A and a blank slot using the fast clock; it is platform display logic, not an extra breadboard clock phase. For the other lessons, only the first display slot has data or the display is blank.
python3 scripts/stage_integration.py bgm_hackathon /tmp/basics_gates_bgm_hackathonStage into an empty directory, then copy the selected wrapper and all staged RTL/models into a new BGM lab/problem. Add the listed files in sources.f to the board project; replace its existing top, do not compile two copies. The wrapper alone is not a board pin-constraint file. Board-specific polarity and constraints remain the BGM infrastructure’s responsibility.
integration/bgm_hackathon/hackathon_top.sv
// The BGM module is spelled hackathon_top, with "h".
module hackathon_top
# (
parameter SCAN_BITS = 16,
parameter CHIP_MODEL = 0
)
(
input clock,
input slow_clock,
input reset,
input [7:0] key,
output [7:0] led,
// A dynamic seven-segment display
output [7:0] abcdefgh,
output [7:0] digit,
// LCD screen interface
input [9:0] x,
input [8:0] y,
output [4:0] red,
output [5:0] green,
output [4:0] blue,
inout [3:0] gpio
);
logic [7:0] exercise_led;
logic [20:0] segments;
logic [7:0] scan_digit;
exercise_bridge # (.CHIP_MODEL (CHIP_MODEL)) exercise
(
.clk (slow_clock),
.rst (reset),
.data (key),
.aux (gpio),
.led (exercise_led),
.segments (segments)
);
exercise_scan # (.SCAN_BITS (SCAN_BITS)) scan
(
.clk (clock),
.rst (reset),
.segments (segments),
.abcdefgh (abcdefgh),
.digit (scan_digit)
);
assign led = exercise_led;
assign digit = scan_digit;
assign red = '0;
assign green = '0;
assign blue = '0;
assign gpio = 'z;
endmodule
14. Tiny Tapeout project.v integration
data[0]=A; data[1]=B. led[3:0]={XOR, NOT A, OR, AND}.
ui_in[7:0] supplies data; uio_in[3:0] supplies aux. uio[7:4] outputs led[3:0]; uio[3:0] remains input. ena=0 disables all bidirectional output enables and drives output values low. rst_n is inverted. Supply a slow external clock for the sequential demos. Compile project.v as SystemVerilog together with the listed dependencies. Keep all time declarations out of RTL; use `timescale 1ns / 1ps only in testbenches, matching the Tiny Tapeout template test/tb.v.
uo_out shows the raw eight LED bits. On a seven-segment board these light individual segments in TT order {dp,g,f,e,d,c,b,a}; they are not decimal numbers. This keeps the one-to-one logic observation from the breadboard.
These are alternative HDL implementations inside FPGA/ASIC infrastructure, not instructions to connect 5 V breadboard outputs to FPGA or Tiny Tapeout pins.
python3 scripts/stage_integration.py tinytapeout /tmp/basics_gates_ttThe staging helper writes a matching sources.f and info_fragment.yaml with flat file names. Merge that fragment into the Tiny Tapeout template and include these sources in its SystemVerilog input list.
integration/tinytapeout/project.v
// Synthesizable Tiny Tapeout top; project.v must be compiled as SystemVerilog.
module tt_um_basic_gates
# (
parameter CHIP_MODEL = 0
)
(
input [7:0] ui_in,
input [7:0] uio_in,
input ena,
input clk,
input rst_n,
output [7:0] uo_out,
output [7:0] uio_out,
output [7:0] uio_oe
);
logic [7:0] led;
logic [20:0] segments;
logic [6:0] selected;
exercise_bridge # (.CHIP_MODEL (CHIP_MODEL)) exercise
(
.clk (clk),
.rst (~ rst_n),
.data (ui_in),
.aux (uio_in [3:0]),
.led (led),
.segments (segments)
);
// Raw LEDs appear as segment bits a..g,dp; no decimal decode is implied.
assign selected = led [6:0];
assign uo_out = ena ? led : '0;
assign uio_out = ena ? { led [3:0], 4'b0 } : '0;
assign uio_oe = ena ? 8'hf0 : '0;
endmodule
integration/tinytapeout/info_fragment.yaml
project:
top_module: "tt_um_basic_gates"
source_files:
- "rtl/basic_gates.sv"
- "rtl/basic_gates_chips.sv"
- "models/cd4069ub.sv"
- "models/cd4070b.sv"
- "models/cd4071b.sv"
- "models/cd4081b.sv"
- "integration/exercise_bridge.sv"
- "integration/tinytapeout/project.v"
# Merge into your template; keep its remaining required metadata.
scripts/stage_integration.py
#!/usr/bin/env python3
"""Stage one platform example and all dependencies into a new directory."""
from pathlib import Path
import argparse, shutil
p=argparse.ArgumentParser()
p.add_argument('platform',choices=['bgm_lab','bgm_hackathon','tinytapeout'])
p.add_argument('destination',type=Path)
a=p.parse_args()
root=Path(__file__).resolve().parents[1]
if a.destination.exists() and any(a.destination.iterdir()):
p.error('Choose an empty directory to avoid overwriting an existing project.')
a.destination.mkdir(parents=True,exist_ok=True)
files=list((root/'rtl').glob('*.sv'))+list((root/'models').glob('*.sv'))+list((root/'integration').glob('*.sv'))
files+=list((root/'integration'/a.platform).glob('*.sv'))+list((root/'integration'/a.platform).glob('*.v'))
for f in files:shutil.copy2(f,a.destination/f.name)
(a.destination/'sources.f').write_text(''.join(f.name+'\n' for f in files))
if a.platform=='tinytapeout':
import re
original=(root/'integration/tinytapeout/info_fragment.yaml').read_text()
top=re.search(r'top_module: "([^"]+)"',original).group(1)
(a.destination/'info_fragment.yaml').write_text('project:\n top_module: "'+top+'"\n source_files:\n'+''.join(' - "'+f.name+'"\n' for f in files))
print('Staged',len(files),'HDL files in',a.destination)
15. Experiments, troubleshooting and sources
Explain why OR and XOR differ only at 11. Predict A XOR A and A AND NOT A. Rewire one chip at a time only with power off; two outputs must never be wired together.
| Observation | Check first |
|---|---|
| Nothing responds | 5 V at the IC, common GND, rail bridges, notch direction |
| Wrong bit or segment | Bit 0 versus chip bit 1; the actual display pin map |
| Unexpected sequential behavior | Reset, input stability at ↑clk, clock-module OUT and control polarity |
Verification covers ideal RTL behavior and the static breadboard netlist. No physical assembly, LED current/brightness measurement, analog clock-level qualification or full FPGA place-and-route/ASIC signoff was performed. The source module variants still need checking on the actual hardware.
- Original Basics exercise list
- LSSK component inventory
- Exercise specification
- Basics-Graphics-Music
- Source and BGM interface provenance
- Referenced inventory rows
- CD4069UB manufacturer datasheet
- CD4070B manufacturer datasheet
- CD4071B manufacturer datasheet
- CD4081B manufacturer datasheet
Rebuild with python3 breadboard/tools/build_basics.py --png. Drawings, source files, pin tables and translations are generated from the maintained files under breadboard/tools/. Simulator logs and validation records stay with each lesson.