1. Purpose and prerequisites
Clock a 4-bit binary counter and a 4-stage Johnson counter together; display both vectors and the greater/equal/less comparison.
This lesson connects a circuit’s logic contract to physical package pins and an RTL implementation. Start with the power/breadboard guide and the SystemVerilog rules.
Use regulated 5 V at the logic rails and a common ground. A USB-to-9 V cable feeds the regulator input, never a logic pin. Begin at a slow clock. The supplied simulations are ideal digital checks; these assemblies have not been measured on hardware.
2. Behavior, symbols and observations
Both counters share clock/reset. CD4063 compares their current unsigned bit patterns, not their position in each cycle. Display only comparison outputs; counter buses also drive logic and are probe-only.
| Port | Direction | Bits |
|---|---|---|
| clk | input | 1 |
| rst | input | 1 |
| binary | output | 4 |
| johnson | output | 4 |
| lt | output | 1 |
| eq | output | 1 |
| gt | output | 1 |

3. Parts you need
| Part | Quantity | LSSK row |
|---|---|---|
| CD4029B · DIP | 1 | 4 |
| CD4069UB · DIP | 1 | 24 |
| CD4015B · DIP | 1 | 5 |
| CD4063B · DIP | 1 | 32 |
| 830-contact breadboard | 1 | 45 |
| 5 V regulated power module | 1 | 56 |
| USB-to-9 V cable to regulator input | 1 | 57 |
| Qualified button channels (sets of five) | 1 | 66 |
| Assembled 555 clock module | 1 | 54 |
| 5 V current-limited LED | 3 | 46 |
| M–M jumper | 44 | 70 |
| External-module lead (M–F assumed) | 14 | 71 |
CSV · Jumper schedule · Pin/net data
Counts describe this exact layout, without spare jumpers. The button quantity counts independent channels: buy 1 sets of five if using that source listing. Qualify the module’s 0/5 V output and built-in bias first; a bare switch is not equivalent. External connector genders and shared module power terminals must be adapted to the actual part.
4. Chip functions, pins and polarity
CD4015B
Two 4-stage shift registers · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | clk_b | input |
| 2 | q4_b | output |
| 3 | q3_a | output |
| 4 | q2_a | output |
| 5 | q1_a | output |
| 6 | rst_a | input |
| 7 | d_a | input |
| 8 | vss | supply |
| 9 | clk_a | input |
| 10 | q4_a | output |
| 11 | q3_b | output |
| 12 | q2_b | output |
| 13 | q1_b | output |
| 14 | rst_b | input |
| 15 | d_b | input |
| 16 | vdd | supply |
CD4029B
Binary / BCD counter · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | pe | input |
| 2 | q4 | output |
| 3 | j4 | input |
| 4 | j1 | input |
| 5 | ci_n | input |
| 6 | q1 | output |
| 7 | co_n | output |
| 8 | vss | supply |
| 9 | binary | input |
| 10 | up | input |
| 11 | q2 | output |
| 12 | j2 | input |
| 13 | j3 | input |
| 14 | q3 | output |
| 15 | clk | input |
| 16 | vdd | supply |
CD4063B
4-bit compare + cascade · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | b3 | input |
| 2 | lt_in | input |
| 3 | eq_in | input |
| 4 | gt_in | input |
| 5 | gt | output |
| 6 | eq | output |
| 7 | lt | output |
| 8 | vss | supply |
| 9 | b0 | input |
| 10 | a0 | input |
| 11 | b1 | input |
| 12 | a1 | input |
| 13 | a2 | input |
| 14 | b2 | input |
| 15 | a3 | input |
| 16 | vdd | supply |
CD4069UB
CD4069UB · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | a1 | input |
| 2 | y1 | output |
| 3 | a2 | input |
| 4 | y2 | output |
| 5 | a3 | input |
| 6 | y3 | output |
| 7 | vss | supply |
| 8 | y4 | output |
| 9 | a4 | input |
| 10 | y5 | output |
| 11 | a5 | input |
| 12 | y6 | output |
| 13 | a6 | input |
| 14 | vdd | supply |
A suffix _n means active LOW. Power pins are physical only and omitted from simulation models. NC means unconnected; it is never a command to ground an output.
5. Schematic 1 · Generic logic

Net labels join the drawing without long crossing wires. Logic gates and state/storage blocks have no package dependency in this view. The RTL in section 8 defines the behavior of every block.
6. Schematic 2 · Chip connections

| Device | Pin | Signal | Net |
|---|---|---|---|
| U1 | 1 | pe | rst |
| U1 | 2 | q4 | binary[3] |
| U1 | 3 | j4 | GND |
| U1 | 4 | j1 | GND |
| U1 | 5 | ci_n | GND |
| U1 | 6 | q1 | binary[0] |
| U1 | 7 | co_n | NC |
| U1 | 8 | vss | GND |
| U1 | 9 | binary | +5V |
| U1 | 10 | up | +5V |
| U1 | 11 | q2 | binary[1] |
| U1 | 12 | j2 | GND |
| U1 | 13 | j3 | GND |
| U1 | 14 | q3 | binary[2] |
| U1 | 15 | clk | clk |
| U1 | 16 | vdd | +5V |
| U2 | 1 | a1 | johnson[3] |
| U2 | 2 | y1 | n1 |
| U2 | 3 | a2 | GND |
| U2 | 4 | y2 | NC |
| U2 | 5 | a3 | GND |
| U2 | 6 | y3 | NC |
| U2 | 7 | vss | GND |
| U2 | 8 | y4 | NC |
| U2 | 9 | a4 | GND |
| U2 | 10 | y5 | NC |
| U2 | 11 | a5 | GND |
| U2 | 12 | y6 | NC |
| U2 | 13 | a6 | GND |
| U2 | 14 | vdd | +5V |
| U3 | 1 | clk_b | GND |
| U3 | 2 | q4_b | NC |
| U3 | 3 | q3_a | johnson[2] |
| U3 | 4 | q2_a | johnson[1] |
| U3 | 5 | q1_a | johnson[0] |
| U3 | 6 | rst_a | rst |
| U3 | 7 | d_a | n1 |
| U3 | 8 | vss | GND |
| U3 | 9 | clk_a | clk |
| U3 | 10 | q4_a | johnson[3] |
| U3 | 11 | q3_b | NC |
| U3 | 12 | q2_b | NC |
| U3 | 13 | q1_b | NC |
| U3 | 14 | rst_b | GND |
| U3 | 15 | d_b | GND |
| U3 | 16 | vdd | +5V |
| U4 | 1 | b3 | johnson[3] |
| U4 | 2 | lt_in | GND |
| U4 | 3 | eq_in | +5V |
| U4 | 4 | gt_in | GND |
| U4 | 5 | gt | gt |
| U4 | 6 | eq | eq |
| U4 | 7 | lt | lt |
| U4 | 8 | vss | GND |
| U4 | 9 | b0 | johnson[0] |
| U4 | 10 | a0 | binary[0] |
| U4 | 11 | b1 | johnson[1] |
| U4 | 12 | a1 | binary[1] |
| U4 | 13 | a2 | binary[2] |
| U4 | 14 | b2 | johnson[2] |
| U4 | 15 | a3 | binary[3] |
| U4 | 16 | vdd | +5V |
7. Schematic 3 · Breadboard and assembly

- Disconnect power. Bridge each split power rail as shown; verify that +5 V and GND are separate.
- Place each DIP across the center gap with its notch LEFT and pin 1 BELOW the gap. Pin diagrams in section 6 instead show the notch UP.
- Wire supplies, fixed controls and unused inputs first. Follow jumpers.csv from W001 onward; matching wire labels across boards denote one wire.
- Connect data/control modules, then the indicators and clock. Do not leave CMOS inputs floating. Start/reset/load as specified in section 2.
- Record sixteen settled samples. The combined pattern repeats after sixteen clocks: binary period 16, Johnson period 8.
LEDs are assigned only to outputs that do not also feed another CMOS input. Feedback and inter-chip data nodes are observed in simulation or with a high-impedance probe; a low-current indicator is not assumed to be a logic buffer.
Connectivity check verifies connected nets, isolated outputs, occupied holes and split-rail bridges. This checks the drawing’s topology, not electrical timing or contact quality.
Complete jumper list
| 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 | rst | B1.j5 | B1.j38 |
| W008 | rst | B1.i38 | S1.OUT |
| W009 | binary[3] | B1.j6 | B1.a48 |
| W010 | GND | B1.j7 | B1.BG2 |
| W011 | GND | B1.j8 | B1.BG3 |
| W012 | GND | B1.j9 | B1.BG4 |
| W013 | GND | B1.j12 | B1.BG5 |
| W014 | GND | B1.a9 | B1.TG2 |
| W015 | GND | B1.a8 | B1.TG3 |
| W016 | GND | B1.j21 | B1.BG6 |
| W017 | GND | B1.j23 | B1.BG7 |
| W018 | GND | B1.j25 | B1.BG8 |
| W019 | GND | B1.a24 | B1.TG4 |
| W020 | GND | B1.a22 | B1.TG5 |
| W021 | GND | B1.a20 | B1.TG6 |
| W022 | GND | B1.j33 | B1.BG9 |
| W023 | GND | B1.j40 | B1.BG10 |
| W024 | GND | B1.a35 | B1.TG7 |
| W025 | GND | B1.a34 | B1.TG8 |
| W026 | GND | B1.j48 | B1.BG11 |
| W027 | GND | B1.j50 | B1.BG12 |
| W028 | GND | B1.j54 | B1.BG13 |
| W029 | GND | S1.GND | B1.BG14 |
| W030 | GND | CLK.GND | B1.BG15 |
| W031 | GND | PWR.GND | B1.BG16 |
| W032 | GND | L1.K | B1.BG17 |
| W033 | GND | L2.K | B1.BG18 |
| W034 | GND | L3.K | B1.BG19 |
| W035 | binary[0] | B1.j10 | B1.a53 |
| W036 | +5V | B1.a12 | B1.TP2 |
| W037 | +5V | B1.a11 | B1.TP3 |
| W038 | +5V | B1.a5 | B1.TP4 |
| W039 | +5V | B1.a19 | B1.TP5 |
| W040 | +5V | B1.a33 | B1.TP6 |
| W041 | +5V | B1.j49 | B1.BP2 |
| W042 | +5V | B1.a47 | B1.TP7 |
| W043 | +5V | S1.VCC | B1.BP3 |
| W044 | +5V | CLK.VCC | B1.BP4 |
| W045 | +5V | PWR.+5V | B1.BP5 |
| W046 | binary[1] | B1.a10 | B1.a51 |
| W047 | binary[2] | B1.a7 | B1.a50 |
| W048 | clk | B1.a6 | B1.a40 |
| W049 | clk | B1.b40 | CLK.OUT |
| W050 | johnson[3] | B1.j19 | B1.a39 |
| W051 | johnson[3] | B1.b39 | B1.j47 |
| W052 | n1 | B1.j20 | B1.j39 |
| W053 | johnson[2] | B1.j35 | B1.a49 |
| W054 | johnson[1] | B1.j36 | B1.a52 |
| W055 | johnson[0] | B1.j37 | B1.a54 |
| W056 | gt | B1.j51 | L3.A |
| W057 | eq | B1.j52 | L2.A |
| W058 | lt | B1.j53 | L1.A |
8. Generic synthesizable SystemVerilog
rtl/counter_stream_compare.sv
// Synthesizable generic design.
module counter_stream_compare
(
input clk,
input rst,
output logic [3:0] binary,
output logic [3:0] johnson,
output lt,
output eq,
output gt
);
always_ff @ (posedge clk or posedge rst)
if (rst)
begin
binary <= '0;
johnson <= '0;
end
else
begin
binary <= binary + 1'b1;
johnson <= { johnson [2:0], ~ johnson [3] };
end
assign lt = binary < johnson;
assign eq = binary == johnson;
assign gt = binary > johnson;
endmodule
RTL contains no timescale declaration. State uses always_ff and nonblocking assignments; combinational behavior uses assign/always_comb. Four-space indentation follows the local style rules.
9. CMOS chip models
Read each model’s opening comment: it states whether the model is synthesizable and which tied-pin subset it covers. These are functional teaching models, not transistor-level models or manufacturer timing libraries.
models/cd4015b.sv
// Synthesizable ideal functional model; physical power pins omitted.
module cd4015b
(
input p1_clk_b,
input p6_rst_a,
input p7_d_a,
input p9_clk_a,
input p14_rst_b,
input p15_d_b,
output p2_q4_b,
output p3_q3_a,
output p4_q2_a,
output p5_q1_a,
output p10_q4_a,
output p11_q3_b,
output p12_q2_b,
output p13_q1_b
);
logic [3:0] a, b;
always_ff @ (posedge p9_clk_a or posedge p6_rst_a)
if (p6_rst_a)
a <= '0;
else
a <= { a [2:0], p7_d_a };
always_ff @ (posedge p1_clk_b or posedge p14_rst_b)
if (p14_rst_b)
b <= '0;
else
b <= { b [2:0], p15_d_b };
assign { p10_q4_a, p3_q3_a, p4_q2_a, p5_q1_a } = a;
assign { p2_q4_b, p11_q3_b, p12_q2_b, p13_q1_b } = b;
endmodule
models/cd4029b.sv
// Synthesizable ideal functional model; physical power pins omitted.
// Exercise subset: JAM pins 3,4,12,13 are tied LOW physically.
// PE loads zero asynchronously. Dynamic JAM and illegal BCD states are
// outside this model. Reset before changing BINARY/DECADE mode.
module cd4029b
(
input p1_pe,
input p5_ci_n,
input p9_binary,
input p10_up,
input p15_clk,
output p2_q4,
output p6_q1,
output p7_co_n,
output p11_q2,
output p14_q3
);
logic [3:0] count;
always_ff @ (posedge p15_clk or posedge p1_pe)
if (p1_pe)
count <= '0;
else if (~ p5_ci_n)
begin
if (p10_up)
begin
if (~ p9_binary && count == 4'd9)
count <= '0;
else
count <= count + 1'b1;
end
else if (~ p9_binary && count == 4'd0)
count <= 4'd9;
else
count <= count - 1'b1;
end
assign { p2_q4, p14_q3, p11_q2, p6_q1 } = count;
assign p7_co_n = p5_ci_n | ~ (p10_up
? (p9_binary ? count == 4'd15 : count == 4'd9)
: count == 4'd0);
endmodule
models/cd4063b.sv
// Synthesizable ideal digital model; power and propagation delays omitted.
// Cascade inputs are mutually exclusive: LT/EQ/GT = 100, 010 or 001.
module cd4063b
(
input p1_b3,
input p2_lt_in,
input p3_eq_in,
input p4_gt_in,
input p9_b0,
input p10_a0,
input p11_b1,
input p12_a1,
input p13_a2,
input p14_b2,
input p15_a3,
output p5_gt,
output p6_eq,
output p7_lt
);
wire [3:0] a = { p15_a3, p13_a2, p12_a1, p10_a0 };
wire [3:0] b = { p1_b3, p14_b2, p11_b1, p9_b0 };
assign p7_lt = a == b ? p2_lt_in : (a < b);
assign p6_eq = a == b ? p3_eq_in : (a == b);
assign p5_gt = a == b ? p4_gt_in : (a > b);
endmodule
models/cd4069ub.sv
// Synthesizable ideal digital model; power and propagation delays 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
10. Pin-connected SystemVerilog
rtl/counter_stream_compare_chips.sv
// Pin connections are generated from the same netlist as the diagrams.
module counter_stream_compare_chips
(
input clk,
input rst,
output [3:0] binary,
output [3:0] johnson,
output lt,
output eq,
output gt
);
logic n1;
cd4029b u1
(
.p1_pe (rst),
.p2_q4 (binary [3]),
.p5_ci_n (1'b0),
.p6_q1 (binary [0]),
.p7_co_n (),
.p9_binary (1'b1),
.p10_up (1'b1),
.p11_q2 (binary [1]),
.p14_q3 (binary [2]),
.p15_clk (clk)
);
cd4069ub u2
(
.p1_a1 (johnson [3]),
.p2_y1 (n1),
.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)
);
cd4015b u3
(
.p1_clk_b (1'b0),
.p2_q4_b (),
.p3_q3_a (johnson [2]),
.p4_q2_a (johnson [1]),
.p5_q1_a (johnson [0]),
.p6_rst_a (rst),
.p7_d_a (n1),
.p9_clk_a (clk),
.p10_q4_a (johnson [3]),
.p11_q3_b (),
.p12_q2_b (),
.p13_q1_b (),
.p14_rst_b (1'b0),
.p15_d_b (1'b0)
);
cd4063b u4
(
.p1_b3 (johnson [3]),
.p2_lt_in (1'b0),
.p3_eq_in (1'b1),
.p4_gt_in (1'b0),
.p5_gt (gt),
.p6_eq (eq),
.p7_lt (lt),
.p9_b0 (johnson [0]),
.p10_a0 (binary [0]),
.p11_b1 (johnson [1]),
.p12_a1 (binary [1]),
.p13_a2 (binary [2]),
.p14_b2 (johnson [2]),
.p15_a3 (binary [3])
);
endmodule
This top has exactly the generic top’s interface. Its connections are generated from the same pin data used for the diagrams and wiring schedule.
11. Testbenches and simulator scripts
tb/tb.sv
`timescale 1ns / 1ps
module tb;
localparam period = 20;
localparam vector_count = 200;
logic [22:0] vectors [0:vector_count-1];
logic [10:0] expected, check_mask;
logic clk = 1'b0;
always # (period / 2) clk = ~ clk;
logic rst = '0;
logic [3:0] binary_rtl;
logic [3:0] binary_chips;
logic [3:0] johnson_rtl;
logic [3:0] johnson_chips;
logic lt_rtl;
logic lt_chips;
logic eq_rtl;
logic eq_chips;
logic gt_rtl;
logic gt_chips;
counter_stream_compare dut_rtl
(
.clk (clk),
.rst (rst),
.binary (binary_rtl),
.johnson (johnson_rtl),
.lt (lt_rtl),
.eq (eq_rtl),
.gt (gt_rtl)
);
counter_stream_compare_chips dut_chips
(
.clk (clk),
.rst (rst),
.binary (binary_chips),
.johnson (johnson_chips),
.lt (lt_chips),
.eq (eq_chips),
.gt (gt_chips)
);
initial
begin
$readmemh ("vectors.hex", vectors);
@ (posedge clk);
# 1;
for (int i = 0; i < vector_count; i ++)
begin
rst = vectors [i] [0 +: 1];
expected = vectors [i] [1 +: 11];
check_mask = vectors [i] [12 +: 11];
@ (posedge clk);
# 1; // Allow nonblocking state and combinational outputs to settle.
if (({ gt_rtl, eq_rtl, lt_rtl, johnson_rtl, binary_rtl } & check_mask) !== (expected & check_mask))
$fatal (1, "counter_stream_compare_rtl vector %0d got=%h expected=%h mask=%h", i, { gt_rtl, eq_rtl, lt_rtl, johnson_rtl, binary_rtl }, expected, check_mask);
if (({ gt_chips, eq_chips, lt_chips, johnson_chips, binary_chips } & check_mask) !== (expected & check_mask))
$fatal (1, "counter_stream_compare_chips vector %0d got=%h expected=%h mask=%h", i, { gt_chips, eq_chips, lt_chips, johnson_chips, binary_chips }, expected, check_mask);
end
$display ("PASS counter_stream_compare: 200 oracle vectors");
$finish;
end
initial
begin
repeat (vector_count * 3 + 20) @ (posedge clk);
$fatal (1, "Cycle watchdog");
end
endmodule
tb/tb_integrations.sv
`timescale 1ns / 1ps
module tb_integrations;
localparam period = 20;
logic clk = 1'b0;
logic rst = 1'b1;
logic ena = 1'b1;
logic [15:0] data = 16'ha000;
logic [31:0] reference_result;
logic [7:0] lab_led, hack_led;
logic [7:0] lab_seg, hack_seg, lab_digit, hack_digit;
logic [7:0] tt_out [4], tt_io [4], tt_oe [4];
logic [7:0] tt_display;
logic [20:0] reference_segments;
logic [6:0] hex_digit;
wire [99:0] lab_gpio = { 92'b0, data [15:8] };
wire [3:0] hack_gpio = data [11:8];
always # (period / 2) clk = ~ clk;
logic [3:0] o_binary;
logic [3:0] o_johnson;
logic o_lt;
logic o_eq;
logic o_gt;
counter_stream_compare reference_core
(
.clk (clk),
.rst (rst),
.binary (o_binary),
.johnson (o_johnson),
.lt (o_lt),
.eq (o_eq),
.gt (o_gt)
);
assign reference_result = { 21'b0, o_gt, o_eq, o_lt, o_johnson, o_binary };
always_comb
case (reference_result [3:0])
0: hex_digit = 7'h3f;
1: hex_digit = 7'h06;
2: hex_digit = 7'h5b;
3: hex_digit = 7'h4f;
4: hex_digit = 7'h66;
5: hex_digit = 7'h6d;
6: hex_digit = 7'h7d;
7: hex_digit = 7'h07;
8: hex_digit = 7'h7f;
9: hex_digit = 7'h67;
10: hex_digit = 7'h77;
11: hex_digit = 7'h7c;
12: hex_digit = 7'h39;
13: hex_digit = 7'h5e;
14: hex_digit = 7'h79;
15: hex_digit = 7'h71;
default: hex_digit = '0;
endcase
assign reference_segments = { 14'b0, hex_digit };
lab_top # (.SCAN_BITS (4)) lab
(
.clk (clk),
.slow_clk (clk),
.rst (rst),
.key (4'b0),
.sw (data [7:0]),
.led (lab_led),
.abcdefgh (lab_seg),
.digit (lab_digit),
.x (10'b0),
.y (9'b0),
.red (),
.green (),
.blue (),
.mic (24'b0),
.sound (),
.uart_rx (1'b1),
.uart_tx (),
.gpio (lab_gpio)
);
hackathon_top # (.SCAN_BITS (4), .UPPER_INPUTS (4'ha)) hack
(
.clock (clk),
.slow_clock (clk),
.reset (rst),
.key (data [7:0]),
.led (hack_led),
.abcdefgh (hack_seg),
.digit (hack_digit),
.x (10'b0),
.y (9'b0),
.red (),
.green (),
.blue (),
.gpio (hack_gpio)
);
for (genvar v = 0; v < 4; v ++)
begin : views
tt_um_counter_stream_compare # (.OUTPUT_VIEW (v)) tt
(
.clk (clk),
.rst_n (~ rst),
.ena (ena),
.ui_in (data [7:0]),
.uio_in (data [15:8]),
.uo_out (tt_out [v]),
.uio_out (tt_io [v]),
.uio_oe (tt_oe [v])
);
end
tt_um_counter_stream_compare # (.DISPLAY_MODE (1)) display_tt
(
.clk (clk),
.rst_n (~ rst),
.ena (ena),
.ui_in (data [7:0]),
.uio_in (data [15:8]),
.uo_out (tt_display),
.uio_out (),
.uio_oe ()
);
initial
begin
@ (posedge clk);
# 1;
rst = 1'b0;
for (int i = 0; i < 160; i ++)
begin
data = { 4'ha, 12' (i * 137) };
ena = i % 7 != 0;
@ (posedge clk);
# 1;
if (lab_led !== reference_result [7:0] || hack_led !== reference_result [7:0])
$fatal (1, "BGM input/output mapping");
if (lab_seg !== hack_seg || lab_digit !== hack_digit)
$fatal (1, "BGM scan disagreement");
for (int v = 0; v < 4; v ++)
begin
if (tt_out [v] !== (ena ? reference_result [v * 8 +: 8] : 8'b0))
$fatal (1, "TinyTapeout output byte %0d", v);
if (tt_io [v] !== 8'b0 || tt_oe [v] !== 8'b0)
$fatal (1, "TinyTapeout bidirectional pins must be inputs");
end
if (tt_display !== (ena ? { 1'b0, reference_segments [6:0] } : 8'b0))
$fatal (1, "TinyTapeout segment mapping");
for (int digit_index = 0; digit_index < 3; digit_index ++)
if (lab_digit == (8'b1 << digit_index))
begin
logic [6:0] active_segments;
active_segments = reference_segments [digit_index * 7 +: 7];
if (lab_seg !== { active_segments [0], active_segments [1], active_segments [2],
active_segments [3], active_segments [4], active_segments [5], active_segments [6], 1'b0 })
$fatal (1, "BGM segment order");
end
end
$display ("PASS integrations");
$finish;
end
initial
begin
repeat (200) @ (posedge clk);
$fatal (1, "Cycle watchdog");
end
endmodule
Run from this lesson directory:
bash scripts/run_iverilog.sh
bash scripts/run_verilator.sh
bash scripts/run_questa.sh
bash scripts/check_integrations.shThe testbench begins with `timescale 1ns / 1ps. It checks both designs against independent arithmetic, queues or input-history expectations. A separate clock process and cycle watchdog are used. Simulator logs and exact vector count are stored under research/.
200 vectors. Test manifest · Source list
| Check | Result |
|---|---|
| iverilog12 | PASS |
| iverilog14 | PASS |
| verilator | PASS |
| integrations | PASS |
| questa_compile | PASS |
| questa_integrations_compile | PASS |
| yosys_generic | PASS |
| yosys_chips | PASS |
| yosys_tinytapeout | PASS |
| wrappers | PASS |
Questa scripts use /home/verilog/altera_lite/25.1std/questa_fse/bin and /home/verilog/flexlm/license.dat by default. QUESTA_BIN, SALT_LICENSE_SERVER and LM_LICENSE_FILE can override them. Compilation and runtime are reported separately. The current sandbox run stops with “couldn’t open socket: not owner”; no completed Questa simulation is claimed. Run the script in an ordinary user terminal for licensed simulation.
12. BGM lab_top integration
Copy rtl/, the required models/ if selecting CHIP_MODEL=1, and integration/exercise_adapter.sv plus exercise_scan.sv into the BGM source set. Replace lab_top with the supplied integration/lab_top.sv. Default CHIP_MODEL=0 uses the generic design. Use slow_clk for the exercise and clk for display scanning. The GPIO inputs must be driven externally.
data[7:0]=SW, data[15:8]=GPIO[7:0]. LED shows result[OUTPUT_VIEW*8 +: 8]. The dynamic display shows the exercise’s segment outputs, or the low result nibble in hexadecimal.
| RTL | Packed bus |
|---|---|
| binary | result[3:0] |
| johnson | result[7:4] |
| lt | result[8:8] |
| eq | result[9:9] |
| gt | result[10:10] |
integration/exercise_adapter.sv
module exercise_adapter
# (
parameter CHIP_MODEL = 0
)
(
input clk,
input rst,
input [15:0] data,
output [31:0] result,
output [20:0] segments
);
logic [3:0] io_binary;
logic [3:0] io_johnson;
logic io_lt;
logic io_eq;
logic io_gt;
generate
if (CHIP_MODEL == 0)
begin : generic_design
counter_stream_compare dut
(
.clk (clk),
.rst (rst),
.binary (io_binary),
.johnson (io_johnson),
.lt (io_lt),
.eq (io_eq),
.gt (io_gt)
);
end
else
begin : physical_design
counter_stream_compare_chips dut
(
.clk (clk),
.rst (rst),
.binary (io_binary),
.johnson (io_johnson),
.lt (io_lt),
.eq (io_eq),
.gt (io_gt)
);
end
endgenerate
assign result = { 21'b0, { io_gt, io_eq, io_lt, io_johnson, io_binary } };
logic [6:0] digit_zero;
always_comb
case (result [3:0])
0: digit_zero = 7'h3f;
1: digit_zero = 7'h06;
2: digit_zero = 7'h5b;
3: digit_zero = 7'h4f;
4: digit_zero = 7'h66;
5: digit_zero = 7'h6d;
6: digit_zero = 7'h7d;
7: digit_zero = 7'h07;
8: digit_zero = 7'h7f;
9: digit_zero = 7'h67;
10: digit_zero = 7'h77;
11: digit_zero = 7'h7c;
12: digit_zero = 7'h39;
13: digit_zero = 7'h5e;
14: digit_zero = 7'h79;
15: digit_zero = 7'h71;
default: digit_zero = '0;
endcase
assign segments = { 14'b0, digit_zero };
endmodule
integration/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 OUTPUT_VIEW = 0,
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 [31:0] result;
logic [20:0] segments;
exercise_adapter # (.CHIP_MODEL (CHIP_MODEL)) adapter
(
.clk (slow_clk),
.rst (rst),
.data ({ 8' (gpio), 8' (sw) }),
.result (result),
.segments (segments)
);
assign led = w_led' (result [OUTPUT_VIEW * 8 +: 8]);
logic [7:0] scan_digit;
exercise_scan # (.SCAN_BITS (SCAN_BITS)) scan
(
.clk (clk),
.rst (rst),
.segments (segments),
.abcdefgh (abcdefgh),
.digit (scan_digit)
);
assign digit = w_digit' (scan_digit);
assign red = '0;
assign green = '0;
assign blue = '0;
assign sound = '0;
assign uart_tx = 1'b1;
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
Use the supplied hackathon_top for the BGM 800×480 interface. data[7:0]=KEY, data[11:8]=GPIO, data[15:12]=UPPER_INPUTS (a four-bit compile-time parameter). For exercises needing more than twelve independent inputs, vary UPPER_INPUTS between builds or use lab_top/TinyTapeout for all live bits.
integration/hackathon_top.sv
module hackathon_top
# (
parameter OUTPUT_VIEW = 0,
parameter SCAN_BITS = 16,
parameter [3:0] UPPER_INPUTS = 0
)
(
input clock,
input slow_clock,
input reset,
input [7:0] key,
input [9:0] x,
input [8:0] y,
output [7:0] led,
output [7:0] abcdefgh,
output [7:0] digit,
output [4:0] red,
output [5:0] green,
output [4:0] blue,
inout [3:0] gpio
);
logic [31:0] result;
logic [20:0] segments;
exercise_adapter adapter
(
.clk (slow_clock),
.rst (reset),
.data ({ UPPER_INPUTS, gpio, key }),
.result (result),
.segments (segments)
);
assign led = result [OUTPUT_VIEW * 8 +: 8];
exercise_scan # (.SCAN_BITS (SCAN_BITS)) scan
(
.clk (clock),
.rst (reset),
.segments (segments),
.abcdefgh (abcdefgh),
.digit (digit)
);
assign red = '0;
assign green = '0;
assign blue = '0;
endmodule
14. Tiny Tapeout project.v integration
Copy rtl/ and integration/exercise_adapter.sv plus integration/project.v into the TinyTapeout project source list; set top_module to tt_um_counter_stream_compare. ui_in maps to data[7:0], uio_in to data[15:8]. All bidirectional pins are inputs (uio_oe=0); rst_n is inverted for the active-high exercise reset. No BGM scanner is needed here.
DISPLAY_MODE=0 puts one raw result byte on uo_out; OUTPUT_VIEW selects bytes 0…3. DISPLAY_MODE=1 drives the first seven-segment digit, with uo_out[6:0]={g,f,e,d,c,b,a} and bit7=0. ena=0 blanks outputs. The three physical breadboard displays cannot all appear simultaneously on eight TinyTapeout output pins.
integration/project.v
module tt_um_counter_stream_compare
# (
parameter OUTPUT_VIEW = 0,
parameter DISPLAY_MODE = 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 [31:0] result;
logic [20:0] segments;
exercise_adapter adapter
(
.clk (clk),
.rst (~ rst_n),
.data ({ uio_in, ui_in }),
.result (result),
.segments (segments)
);
assign uo_out = ~ ena ? 8'b0 : DISPLAY_MODE ? { 1'b0, segments [6:0] } : result [OUTPUT_VIEW * 8 +: 8];
assign uio_out = '0;
assign uio_oe = '0;
endmodule
15. Experiments, troubleshooting and sources
Record sixteen settled samples. The combined pattern repeats after sixteen clocks: binary period 16, Johnson period 8.
If the result is wrong, check power and package orientation, then fixed control polarities, then the first differing internal net. For sequential circuits check reset/load and clock edges before changing equations. Record expected and observed values for every experiment.
July 31 curriculum · Habr curriculum · LSSK inventory · Coverage of all 61 source entries