1. Purpose and prerequisites
Set DATA before each rising edge of the assembled clock. Build a recognizer for a teacher-assigned binary pattern of length 2–4; show state and MATCH on LEDs.
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
State records the longest suffix matching a proper prefix. Arrow labels are input / registered MATCH after the edge. Overlap is supported. CD40174 CLEAR is active LOW; an inverter converts rst. A teacher can generate another 2–4-bit task with tools/custom_sequence.py.
| Port | Direction | Bits |
|---|---|---|
| clk | input | 1 |
| rst | input | 1 |
| x | input | 1 |
| match | output | 1 |


3. Parts you need
| Part | Quantity | LSSK row |
|---|---|---|
| CD4069UB · DIP | 1 | 24 |
| CD4081B · DIP | 4 | 10 |
| CD4071B · DIP | 2 | 20 |
| CD40174B · DIP | 1 | 26 |
| 830-contact breadboard | 2 | 45 |
| 5 V regulated power module | 1 | 56 |
| USB-to-9 V cable to regulator input | 1 | 57 |
| Qualified button channels (sets of five) | 2 | 66 |
| Assembled 555 clock module | 1 | 54 |
| 5 V current-limited LED | 1 | 46 |
| M–M jumper | 89 | 70 |
| External-module lead (M–F assumed) | 13 | 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
CD40174B
Six D flip-flops, clear LOW · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | clear_n | input |
| 2 | q0 | output |
| 3 | d0 | input |
| 4 | d1 | input |
| 5 | q1 | output |
| 6 | d2 | input |
| 7 | q2 | output |
| 8 | vss | supply |
| 9 | clk | input |
| 10 | q3 | output |
| 11 | d3 | input |
| 12 | q4 | output |
| 13 | d4 | input |
| 14 | d5 | input |
| 15 | q5 | output |
| 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 |
CD4071B
CD4071B · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | a1 | input |
| 2 | b1 | input |
| 3 | y1 | output |
| 4 | y2 | output |
| 5 | b2 | input |
| 6 | a2 | input |
| 7 | vss | supply |
| 8 | a3 | input |
| 9 | b3 | input |
| 10 | y3 | output |
| 11 | y4 | output |
| 12 | b4 | input |
| 13 | a4 | input |
| 14 | vdd | supply |
CD4081B
CD4081B · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | a1 | input |
| 2 | b1 | input |
| 3 | y1 | output |
| 4 | y2 | output |
| 5 | b2 | input |
| 6 | a2 | input |
| 7 | vss | supply |
| 8 | a3 | input |
| 9 | b3 | input |
| 10 | y3 | output |
| 11 | y4 | output |
| 12 | b4 | input |
| 13 | a4 | 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 | a1 | state[0] |
| U1 | 2 | y1 | n1 |
| U1 | 3 | a2 | state[1] |
| U1 | 4 | y2 | n2 |
| U1 | 5 | a3 | x |
| U1 | 6 | y3 | n3 |
| U1 | 7 | vss | GND |
| U1 | 8 | y4 | n26 |
| U1 | 9 | a4 | rst |
| U1 | 10 | y5 | NC |
| U1 | 11 | a5 | GND |
| U1 | 12 | y6 | NC |
| U1 | 13 | a6 | GND |
| U1 | 14 | vdd | +5V |
| U2 | 1 | a1 | n1 |
| U2 | 2 | b1 | n2 |
| U2 | 3 | y1 | n4 |
| U2 | 4 | y2 | n5 |
| U2 | 5 | b2 | n3 |
| U2 | 6 | a2 | n4 |
| U2 | 7 | vss | GND |
| U2 | 8 | a3 | state[0] |
| U2 | 9 | b3 | n2 |
| U2 | 10 | y3 | n6 |
| U2 | 11 | y4 | n7 |
| U2 | 12 | b4 | n3 |
| U2 | 13 | a4 | n6 |
| U2 | 14 | vdd | +5V |
| U3 | 1 | a1 | n1 |
| U3 | 2 | b1 | state[1] |
| U3 | 3 | y1 | n8 |
| U3 | 4 | y2 | n9 |
| U3 | 5 | b2 | n3 |
| U3 | 6 | a2 | n8 |
| U3 | 7 | vss | GND |
| U3 | 8 | a3 | state[0] |
| U3 | 9 | b3 | state[1] |
| U3 | 10 | y3 | n10 |
| U3 | 11 | y4 | n11 |
| U3 | 12 | b4 | n3 |
| U3 | 13 | a4 | n10 |
| U3 | 14 | vdd | +5V |
| U4 | 1 | a1 | n1 |
| U4 | 2 | b1 | n2 |
| U4 | 3 | y1 | n12 |
| U4 | 4 | y2 | n13 |
| U4 | 5 | b2 | x |
| U4 | 6 | a2 | n12 |
| U4 | 7 | vss | GND |
| U4 | 8 | a3 | state[0] |
| U4 | 9 | b3 | n2 |
| U4 | 10 | y3 | n14 |
| U4 | 11 | y4 | n15 |
| U4 | 12 | b4 | x |
| U4 | 13 | a4 | n14 |
| U4 | 14 | vdd | +5V |
| U5 | 1 | a1 | n1 |
| U5 | 2 | b1 | state[1] |
| U5 | 3 | y1 | n16 |
| U5 | 4 | y2 | n17 |
| U5 | 5 | b2 | x |
| U5 | 6 | a2 | n16 |
| U5 | 7 | vss | GND |
| U5 | 8 | a3 | state[0] |
| U5 | 9 | b3 | state[1] |
| U5 | 10 | y3 | n18 |
| U5 | 11 | y4 | n19 |
| U5 | 12 | b4 | x |
| U5 | 13 | a4 | n18 |
| U5 | 14 | vdd | +5V |
| U6 | 1 | a1 | n13 |
| U6 | 2 | b1 | n15 |
| U6 | 3 | y1 | n20 |
| U6 | 4 | y2 | n21 |
| U6 | 5 | b2 | n17 |
| U6 | 6 | a2 | n20 |
| U6 | 7 | vss | GND |
| U6 | 8 | a3 | n21 |
| U6 | 9 | b3 | n19 |
| U6 | 10 | y3 | n22 |
| U6 | 11 | y4 | n23 |
| U6 | 12 | b4 | n11 |
| U6 | 13 | a4 | n7 |
| U6 | 14 | vdd | +5V |
| U7 | 1 | a1 | n23 |
| U7 | 2 | b1 | n17 |
| U7 | 3 | y1 | n24 |
| U7 | 4 | y2 | n25 |
| U7 | 5 | b2 | GND |
| U7 | 6 | a2 | n19 |
| U7 | 7 | vss | GND |
| U7 | 8 | a3 | GND |
| U7 | 9 | b3 | GND |
| U7 | 10 | y3 | NC |
| U7 | 11 | y4 | NC |
| U7 | 12 | b4 | GND |
| U7 | 13 | a4 | GND |
| U7 | 14 | vdd | +5V |
| U8 | 1 | clear_n | n26 |
| U8 | 2 | q0 | state[0] |
| U8 | 3 | d0 | n22 |
| U8 | 4 | d1 | n24 |
| U8 | 5 | q1 | state[1] |
| U8 | 6 | d2 | n25 |
| U8 | 7 | q2 | match |
| U8 | 8 | vss | GND |
| U8 | 9 | clk | clk |
| U8 | 10 | q3 | NC |
| U8 | 11 | d3 | GND |
| U8 | 12 | q4 | NC |
| U8 | 13 | d4 | GND |
| U8 | 14 | d5 | GND |
| U8 | 15 | q5 | NC |
| U8 | 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.
- Trace 10111011 and a stream of all zeros/all ones. Draw the prefix-state graph before wiring. Explain where the machine goes after a match.
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 | +5V | B2.TP25 | B2.TP26 |
| W008 | GND | B2.TG25 | B2.TG26 |
| W009 | +5V | B2.BP25 | B2.BP26 |
| W010 | GND | B2.BG25 | B2.BG26 |
| W011 | +5V | B2.TP1 | B2.BP1 |
| W012 | GND | B2.TG1 | B2.BG1 |
| W013 | +5V | B1.BP50 | B2.TP50 |
| W014 | GND | B1.BG50 | B2.TG50 |
| W015 | state[0] | B1.j5 | B1.a25 |
| W016 | state[0] | B1.b25 | B1.a39 |
| W017 | state[0] | B1.b39 | B1.a53 |
| W018 | state[0] | B1.b53 | B2.a11 |
| W019 | state[0] | B2.b11 | B2.j48 |
| W020 | n1 | B1.j6 | B1.j19 |
| W021 | n1 | B1.i19 | B1.j33 |
| W022 | n1 | B1.i33 | B1.j47 |
| W023 | n1 | B1.i47 | B2.j5 |
| W024 | state[1] | B1.j7 | B1.j34 |
| W025 | state[1] | B1.i34 | B1.a38 |
| W026 | state[1] | B1.b38 | B2.j6 |
| W027 | state[1] | B2.i6 | B2.a10 |
| W028 | state[1] | B2.b10 | B2.j51 |
| W029 | n2 | B1.j8 | B1.j20 |
| W030 | n2 | B1.i20 | B1.a24 |
| W031 | n2 | B1.b24 | B1.j48 |
| W032 | n2 | B1.i48 | B1.a52 |
| W033 | x | B1.j9 | B1.j51 |
| W034 | x | B1.i51 | B1.a49 |
| W035 | x | B1.b49 | B2.j9 |
| W036 | x | B2.i9 | B2.a7 |
| W037 | x | B2.b7 | S2.OUT |
| W038 | n3 | B1.j10 | B1.j23 |
| W039 | n3 | B1.i23 | B1.a21 |
| W040 | n3 | B1.b21 | B1.j37 |
| W041 | n3 | B1.i37 | B1.a35 |
| W042 | GND | B1.j11 | B1.BG2 |
| W043 | GND | B1.a8 | B1.TG2 |
| W044 | GND | B1.a6 | B1.TG3 |
| W045 | GND | B1.j25 | B1.BG3 |
| W046 | GND | B1.j39 | B1.BG4 |
| W047 | GND | B1.j53 | B1.BG5 |
| W048 | GND | B2.j11 | B2.BG2 |
| W049 | GND | B2.j25 | B2.BG3 |
| W050 | GND | B2.j37 | B2.BG4 |
| W051 | GND | B2.j39 | B2.BG5 |
| W052 | GND | B2.a39 | B2.TG2 |
| W053 | GND | B2.a38 | B2.TG3 |
| W054 | GND | B2.a35 | B2.TG4 |
| W055 | GND | B2.a34 | B2.TG5 |
| W056 | GND | B2.j54 | B2.BG6 |
| W057 | GND | B2.a52 | B2.TG6 |
| W058 | GND | B2.a50 | B2.TG7 |
| W059 | GND | B2.a49 | B2.TG8 |
| W060 | GND | S1.GND | B1.BG6 |
| W061 | GND | S2.GND | B2.BG7 |
| W062 | GND | CLK.GND | B1.BG7 |
| W063 | GND | PWR.GND | B1.BG8 |
| W064 | GND | L1.K | B1.BG9 |
| W065 | n26 | B1.a11 | B2.j47 |
| W066 | rst | B1.a10 | S1.OUT |
| W067 | +5V | B1.a5 | B1.TP2 |
| W068 | +5V | B1.a19 | B1.TP3 |
| W069 | +5V | B1.a33 | B1.TP4 |
| W070 | +5V | B1.a47 | B1.TP5 |
| W071 | +5V | B2.a5 | B2.TP2 |
| W072 | +5V | B2.a19 | B2.TP3 |
| W073 | +5V | B2.a33 | B2.TP4 |
| W074 | +5V | B2.a47 | B2.TP5 |
| W075 | +5V | S1.VCC | B1.BP2 |
| W076 | +5V | S2.VCC | B2.BP2 |
| W077 | +5V | CLK.VCC | B1.BP3 |
| W078 | +5V | PWR.+5V | B1.BP4 |
| W079 | n4 | B1.j21 | B1.j24 |
| W080 | n6 | B1.a23 | B1.a20 |
| W081 | n7 | B1.a22 | B2.a20 |
| W082 | n8 | B1.j35 | B1.j38 |
| W083 | n10 | B1.a37 | B1.a34 |
| W084 | n11 | B1.a36 | B2.a21 |
| W085 | n12 | B1.j49 | B1.j52 |
| W086 | n13 | B1.j50 | B2.j19 |
| W087 | n14 | B1.a51 | B1.a48 |
| W088 | n15 | B1.a50 | B2.j20 |
| W089 | n16 | B2.j7 | B2.j10 |
| W090 | n17 | B2.j8 | B2.j23 |
| W091 | n17 | B2.i23 | B2.j34 |
| W092 | n18 | B2.a9 | B2.a6 |
| W093 | n19 | B2.a8 | B2.a24 |
| W094 | n19 | B2.b24 | B2.j38 |
| W095 | n20 | B2.j21 | B2.j24 |
| W096 | n21 | B2.j22 | B2.a25 |
| W097 | n22 | B2.a23 | B2.j49 |
| W098 | n23 | B2.a22 | B2.j33 |
| W099 | n24 | B2.j35 | B2.j50 |
| W100 | n25 | B2.j36 | B2.j52 |
| W101 | match | B2.j53 | L1.A |
| W102 | clk | B2.a54 | CLK.OUT |
8. Generic synthesizable SystemVerilog
rtl/custom_sequence.sv
// Synthesizable generic design.
module custom_sequence
(
input clk,
input rst,
input x,
output logic match
);
logic [1:0] state;
logic [1:0] next_state;
logic next_match;
always_comb
begin
next_state = '0;
next_match = 1'b0;
case ({ x, state })
3'd0:
begin
next_state = 2'd0;
next_match = 1'b0;
end
3'd1:
begin
next_state = 2'd2;
next_match = 1'b0;
end
3'd2:
begin
next_state = 2'd0;
next_match = 1'b0;
end
3'd3:
begin
next_state = 2'd2;
next_match = 1'b0;
end
3'd4:
begin
next_state = 2'd1;
next_match = 1'b0;
end
3'd5:
begin
next_state = 2'd1;
next_match = 1'b0;
end
3'd6:
begin
next_state = 2'd3;
next_match = 1'b0;
end
3'd7:
begin
next_state = 2'd1;
next_match = 1'b1;
end
endcase
end
always_ff @ (posedge clk or posedge rst)
if (rst)
begin
state <= '0;
match <= 1'b0;
end
else
begin
state <= next_state;
match <= next_match;
end
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/cd40174b.sv
// Synthesizable ideal digital model; power and propagation delays omitted.
module cd40174b
(
input p1_clear_n,
input p3_d0,
input p4_d1,
input p6_d2,
input p9_clk,
input p11_d3,
input p13_d4,
input p14_d5,
output p2_q0,
output p5_q1,
output p7_q2,
output p10_q3,
output p12_q4,
output p15_q5
);
logic [5:0] state;
always_ff @ (posedge p9_clk or negedge p1_clear_n)
if (~ p1_clear_n)
state <= '0;
else
state <= { p14_d5, p13_d4, p11_d3, p6_d2, p4_d1, p3_d0 };
assign { p15_q5, p12_q4, p10_q3, p7_q2, p5_q1, p2_q0 } = state;
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
models/cd4071b.sv
// Synthesizable ideal digital model; power and propagation delays 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 digital model; power and propagation delays 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/custom_sequence_chips.sv
// Pin connections are generated from the same netlist as the diagrams.
module custom_sequence_chips
(
input clk,
input rst,
input x,
output match
);
logic n1;
logic n10;
logic n11;
logic n12;
logic n13;
logic n14;
logic n15;
logic n16;
logic n17;
logic n18;
logic n19;
logic n2;
logic n20;
logic n21;
logic n22;
logic n23;
logic n24;
logic n25;
logic n26;
logic n3;
logic n4;
logic n5;
logic n6;
logic n7;
logic n8;
logic n9;
logic [1:0] state;
cd4069ub u1
(
.p1_a1 (state [0]),
.p2_y1 (n1),
.p3_a2 (state [1]),
.p4_y2 (n2),
.p5_a3 (x),
.p6_y3 (n3),
.p8_y4 (n26),
.p9_a4 (rst),
.p10_y5 (),
.p11_a5 (1'b0),
.p12_y6 (),
.p13_a6 (1'b0)
);
cd4081b u2
(
.p1_a1 (n1),
.p2_b1 (n2),
.p3_y1 (n4),
.p4_y2 (n5),
.p5_b2 (n3),
.p6_a2 (n4),
.p8_a3 (state [0]),
.p9_b3 (n2),
.p10_y3 (n6),
.p11_y4 (n7),
.p12_b4 (n3),
.p13_a4 (n6)
);
cd4081b u3
(
.p1_a1 (n1),
.p2_b1 (state [1]),
.p3_y1 (n8),
.p4_y2 (n9),
.p5_b2 (n3),
.p6_a2 (n8),
.p8_a3 (state [0]),
.p9_b3 (state [1]),
.p10_y3 (n10),
.p11_y4 (n11),
.p12_b4 (n3),
.p13_a4 (n10)
);
cd4081b u4
(
.p1_a1 (n1),
.p2_b1 (n2),
.p3_y1 (n12),
.p4_y2 (n13),
.p5_b2 (x),
.p6_a2 (n12),
.p8_a3 (state [0]),
.p9_b3 (n2),
.p10_y3 (n14),
.p11_y4 (n15),
.p12_b4 (x),
.p13_a4 (n14)
);
cd4081b u5
(
.p1_a1 (n1),
.p2_b1 (state [1]),
.p3_y1 (n16),
.p4_y2 (n17),
.p5_b2 (x),
.p6_a2 (n16),
.p8_a3 (state [0]),
.p9_b3 (state [1]),
.p10_y3 (n18),
.p11_y4 (n19),
.p12_b4 (x),
.p13_a4 (n18)
);
cd4071b u6
(
.p1_a1 (n13),
.p2_b1 (n15),
.p3_y1 (n20),
.p4_y2 (n21),
.p5_b2 (n17),
.p6_a2 (n20),
.p8_a3 (n21),
.p9_b3 (n19),
.p10_y3 (n22),
.p11_y4 (n23),
.p12_b4 (n11),
.p13_a4 (n7)
);
cd4071b u7
(
.p1_a1 (n23),
.p2_b1 (n17),
.p3_y1 (n24),
.p4_y2 (n25),
.p5_b2 (1'b0),
.p6_a2 (n19),
.p8_a3 (1'b0),
.p9_b3 (1'b0),
.p10_y3 (),
.p11_y4 (),
.p12_b4 (1'b0),
.p13_a4 (1'b0)
);
cd40174b u8
(
.p1_clear_n (n26),
.p2_q0 (state [0]),
.p3_d0 (n22),
.p4_d1 (n24),
.p5_q1 (state [1]),
.p6_d2 (n25),
.p7_q2 (match),
.p9_clk (clk),
.p10_q3 (),
.p11_d3 (1'b0),
.p12_q4 (),
.p13_d4 (1'b0),
.p14_d5 (1'b0),
.p15_q5 ()
);
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 = 500;
logic [3:0] vectors [0:vector_count-1];
logic [0:0] expected, check_mask;
logic clk = 1'b0;
always # (period / 2) clk = ~ clk;
logic rst = '0;
logic x = '0;
logic match_rtl;
logic match_chips;
custom_sequence dut_rtl
(
.clk (clk),
.rst (rst),
.x (x),
.match (match_rtl)
);
custom_sequence_chips dut_chips
(
.clk (clk),
.rst (rst),
.x (x),
.match (match_chips)
);
initial
begin
$readmemh ("vectors.hex", vectors);
@ (posedge clk);
# 1;
for (int i = 0; i < vector_count; i ++)
begin
rst = vectors [i] [0 +: 1];
x = vectors [i] [1 +: 1];
expected = vectors [i] [2 +: 1];
check_mask = vectors [i] [3 +: 1];
@ (posedge clk);
# 1; // Allow nonblocking state and combinational outputs to settle.
if (({ match_rtl } & check_mask) !== (expected & check_mask))
$fatal (1, "custom_sequence_rtl vector %0d got=%h expected=%h mask=%h", i, { match_rtl }, expected, check_mask);
if (({ match_chips } & check_mask) !== (expected & check_mask))
$fatal (1, "custom_sequence_chips vector %0d got=%h expected=%h mask=%h", i, { match_chips }, expected, check_mask);
end
$display ("PASS custom_sequence: 500 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;
wire i_x = data [0 +: 1];
logic o_match;
custom_sequence reference_core
(
.clk (clk),
.rst (rst),
.x (i_x),
.match (o_match)
);
assign reference_result = { 31'b0, o_match };
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_custom_sequence # (.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_custom_sequence # (.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/.
500 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 |
|---|---|
| x | data[0:0] |
| match | result[0:0] |
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
);
wire io_x = data [0 +: 1];
logic io_match;
generate
if (CHIP_MODEL == 0)
begin : generic_design
custom_sequence dut
(
.clk (clk),
.rst (rst),
.x (io_x),
.match (io_match)
);
end
else
begin : physical_design
custom_sequence_chips dut
(
.clk (clk),
.rst (rst),
.x (io_x),
.match (io_match)
);
end
endgenerate
assign result = { 31'b0, { io_match } };
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_custom_sequence. 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_custom_sequence
# (
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
Trace 10111011 and a stream of all zeros/all ones. Draw the prefix-state graph before wiring. Explain where the machine goes after a match.
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.
Teacher generator: python3 ../tools/custom_sequence.py 0101. It produces another complete bilingual lesson and vectors, then runs Icarus. The reviewed default is 1011.
July 31 curriculum · Habr curriculum · LSSK inventory · Coverage of all 61 source entries