1. Purpose and prerequisites
Patch addresses and use data/write controls to store and read four independent words.
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
The layout assumes a 24-pin DIP with 0.6-inch (15.24 mm) row spacing: upper pins in row c, lower pins in row g. Check the mechanical drawing of the actual stocked package before insertion. The 14/16-pin chips use rows e/f.
CD40108 provides one synchronous write port and two independent asynchronous read ports. OEA/OEB are tied high. It has no reset: all four words must be written before expecting defined values. This rare part is an optional procurement dependency.
| Port | Direction | Bits |
|---|---|---|
| clk | input | 1 |
| we | input | 1 |
| wa | input | 2 |
| ra | input | 2 |
| rb | input | 2 |
| data | input | 4 |
| qa | output | 4 |
| qb | output | 4 |

3. Parts you need
| Part | Quantity | LSSK row |
|---|---|---|
| CD40108B · DIP | 1 | 42 |
| 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) | 11 | 66 |
| Assembled 555 clock module | 1 | 54 |
| 5 V current-limited LED | 8 | 46 |
| M–M jumper | 10 | 70 |
| External-module lead (M–F assumed) | 54 | 71 |
CSV · Jumper schedule · Pin/net data
Counts describe this exact layout, without spare jumpers. The button quantity counts independent channels: buy 3 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
CD40108B
4 × 4, one write / two reads · Manufacturer datasheet
| Pin | Signal | Type |
|---|---|---|
| 1 | qb3 | output |
| 2 | qb2 | output |
| 3 | oea | input |
| 4 | qa0 | output |
| 5 | qa1 | output |
| 6 | qa2 | output |
| 7 | qa3 | output |
| 8 | wa0 | input |
| 9 | wa1 | input |
| 10 | rb1 | input |
| 11 | rb0 | input |
| 12 | vss | supply |
| 13 | ra0 | input |
| 14 | ra1 | input |
| 15 | we | input |
| 16 | clk | input |
| 17 | d3 | input |
| 18 | d2 | input |
| 19 | d1 | input |
| 20 | d0 | input |
| 21 | oeb | input |
| 22 | qb0 | output |
| 23 | qb1 | output |
| 24 | 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.
Manufacturer example of the 24-pin, 0.6-inch DIP outline; the layout explicitly assumes this row spacing.
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 | qb3 | qb[3] |
| U1 | 2 | qb2 | qb[2] |
| U1 | 3 | oea | +5V |
| U1 | 4 | qa0 | qa[0] |
| U1 | 5 | qa1 | qa[1] |
| U1 | 6 | qa2 | qa[2] |
| U1 | 7 | qa3 | qa[3] |
| U1 | 8 | wa0 | wa[0] |
| U1 | 9 | wa1 | wa[1] |
| U1 | 10 | rb1 | rb[1] |
| U1 | 11 | rb0 | rb[0] |
| U1 | 12 | vss | GND |
| U1 | 13 | ra0 | ra[0] |
| U1 | 14 | ra1 | ra[1] |
| U1 | 15 | we | we |
| U1 | 16 | clk | clk |
| U1 | 17 | d3 | data[3] |
| U1 | 18 | d2 | data[2] |
| U1 | 19 | d1 | data[1] |
| U1 | 20 | d0 | data[0] |
| U1 | 21 | oeb | +5V |
| U1 | 22 | qb0 | qb[0] |
| U1 | 23 | qb1 | qb[1] |
| U1 | 24 | 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.
- Write 1,2,4,8 to addresses 0,1,2,3. Set WE=0 and sweep RA/RB independently. Write F while reading the same address; the read output changes after the write edge.
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 | qb[3] | B1.j5 | L8.A |
| W008 | qb[2] | B1.j6 | L7.A |
| W009 | +5V | B1.j7 | B1.BP2 |
| W010 | +5V | B1.a8 | B1.TP2 |
| W011 | +5V | B1.a5 | B1.TP3 |
| W012 | +5V | S1.VCC | B1.BP3 |
| W013 | +5V | S2.VCC | B1.BP4 |
| W014 | +5V | S3.VCC | B1.BP5 |
| W015 | +5V | S4.VCC | B1.BP6 |
| W016 | +5V | S5.VCC | B1.BP7 |
| W017 | +5V | S6.VCC | B1.BP8 |
| W018 | +5V | S7.VCC | B1.BP9 |
| W019 | +5V | S8.VCC | B1.BP10 |
| W020 | +5V | S9.VCC | B1.BP11 |
| W021 | +5V | S10.VCC | B1.BP12 |
| W022 | +5V | S11.VCC | B1.BP13 |
| W023 | +5V | CLK.VCC | B1.BP14 |
| W024 | +5V | PWR.+5V | B1.BP15 |
| W025 | qa[0] | B1.j8 | L1.A |
| W026 | qa[1] | B1.j9 | L2.A |
| W027 | qa[2] | B1.j10 | L3.A |
| W028 | qa[3] | B1.j11 | L4.A |
| W029 | wa[0] | B1.j12 | S2.OUT |
| W030 | wa[1] | B1.j13 | S3.OUT |
| W031 | rb[1] | B1.j14 | S7.OUT |
| W032 | rb[0] | B1.j15 | S6.OUT |
| W033 | GND | B1.j16 | B1.BG2 |
| W034 | GND | S1.GND | B1.BG3 |
| W035 | GND | S2.GND | B1.BG4 |
| W036 | GND | S3.GND | B1.BG5 |
| W037 | GND | S4.GND | B1.BG6 |
| W038 | GND | S5.GND | B1.BG7 |
| W039 | GND | S6.GND | B1.BG8 |
| W040 | GND | S7.GND | B1.BG9 |
| W041 | GND | S8.GND | B1.BG10 |
| W042 | GND | S9.GND | B1.BG11 |
| W043 | GND | S10.GND | B1.BG12 |
| W044 | GND | S11.GND | B1.BG13 |
| W045 | GND | CLK.GND | B1.BG14 |
| W046 | GND | PWR.GND | B1.BG15 |
| W047 | GND | L1.K | B1.BG16 |
| W048 | GND | L2.K | B1.BG17 |
| W049 | GND | L3.K | B1.BG18 |
| W050 | GND | L4.K | B1.BG19 |
| W051 | GND | L5.K | B1.BG20 |
| W052 | GND | L6.K | B1.BG21 |
| W053 | GND | L7.K | B1.BG22 |
| W054 | GND | L8.K | B1.BG23 |
| W055 | ra[0] | B1.a16 | S4.OUT |
| W056 | ra[1] | B1.a15 | S5.OUT |
| W057 | we | B1.a14 | S1.OUT |
| W058 | clk | B1.a13 | CLK.OUT |
| W059 | data[3] | B1.a12 | S11.OUT |
| W060 | data[2] | B1.a11 | S10.OUT |
| W061 | data[1] | B1.a10 | S9.OUT |
| W062 | data[0] | B1.a9 | S8.OUT |
| W063 | qb[0] | B1.a7 | L5.A |
| W064 | qb[1] | B1.a6 | L6.A |
8. Generic synthesizable SystemVerilog
rtl/register_file.sv
// Synthesizable generic design.
module register_file
(
input clk,
input we,
input [1:0] wa,
input [1:0] ra,
input [1:0] rb,
input [3:0] data,
output [3:0] qa,
output [3:0] qb
);
logic [3:0] memory [0:3];
always_ff @ (posedge clk)
if (we)
memory [wa] <= data;
assign qa = memory [ra];
assign qb = memory [rb];
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/cd40108b.sv
// Synthesizable ideal digital model; power and propagation delays omitted.
// Lesson subset: OEA=OEB=1. Memory has no reset; initialize all four words.
module cd40108b
(
input p3_oea,
input p8_wa0,
input p9_wa1,
input p10_rb1,
input p11_rb0,
input p13_ra0,
input p14_ra1,
input p15_we,
input p16_clk,
input p17_d3,
input p18_d2,
input p19_d1,
input p20_d0,
input p21_oeb,
output p1_qb3,
output p2_qb2,
output p4_qa0,
output p5_qa1,
output p6_qa2,
output p7_qa3,
output p22_qb0,
output p23_qb1
);
logic [3:0] memory [0:3];
always_ff @ (posedge p16_clk)
if (p15_we)
memory [{ p9_wa1, p8_wa0 }] <= { p17_d3, p18_d2, p19_d1, p20_d0 };
assign { p7_qa3, p6_qa2, p5_qa1, p4_qa0 } = memory [{ p14_ra1, p13_ra0 }];
assign { p1_qb3, p2_qb2, p23_qb1, p22_qb0 } = memory [{ p10_rb1, p11_rb0 }];
endmodule
10. Pin-connected SystemVerilog
rtl/register_file_chips.sv
// Pin connections are generated from the same netlist as the diagrams.
module register_file_chips
(
input clk,
input we,
input [1:0] wa,
input [1:0] ra,
input [1:0] rb,
input [3:0] data,
output [3:0] qa,
output [3:0] qb
);
cd40108b u1
(
.p1_qb3 (qb [3]),
.p2_qb2 (qb [2]),
.p3_oea (1'b1),
.p4_qa0 (qa [0]),
.p5_qa1 (qa [1]),
.p6_qa2 (qa [2]),
.p7_qa3 (qa [3]),
.p8_wa0 (wa [0]),
.p9_wa1 (wa [1]),
.p10_rb1 (rb [1]),
.p11_rb0 (rb [0]),
.p13_ra0 (ra [0]),
.p14_ra1 (ra [1]),
.p15_we (we),
.p16_clk (clk),
.p17_d3 (data [3]),
.p18_d2 (data [2]),
.p19_d1 (data [1]),
.p20_d0 (data [0]),
.p21_oeb (1'b1),
.p22_qb0 (qb [0]),
.p23_qb1 (qb [1])
);
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 = 300;
logic [26:0] vectors [0:vector_count-1];
logic [7:0] expected, check_mask;
logic clk = 1'b0;
always # (period / 2) clk = ~ clk;
logic we = '0;
logic [1:0] wa = '0;
logic [1:0] ra = '0;
logic [1:0] rb = '0;
logic [3:0] data = '0;
logic [3:0] qa_rtl;
logic [3:0] qa_chips;
logic [3:0] qb_rtl;
logic [3:0] qb_chips;
register_file dut_rtl
(
.clk (clk),
.we (we),
.wa (wa),
.ra (ra),
.rb (rb),
.data (data),
.qa (qa_rtl),
.qb (qb_rtl)
);
register_file_chips dut_chips
(
.clk (clk),
.we (we),
.wa (wa),
.ra (ra),
.rb (rb),
.data (data),
.qa (qa_chips),
.qb (qb_chips)
);
initial
begin
$readmemh ("vectors.hex", vectors);
@ (posedge clk);
# 1;
for (int i = 0; i < vector_count; i ++)
begin
we = vectors [i] [0 +: 1];
wa = vectors [i] [1 +: 2];
ra = vectors [i] [3 +: 2];
rb = vectors [i] [5 +: 2];
data = vectors [i] [7 +: 4];
expected = vectors [i] [11 +: 8];
check_mask = vectors [i] [19 +: 8];
@ (posedge clk);
# 1; // Allow nonblocking state and combinational outputs to settle.
if (({ qb_rtl, qa_rtl } & check_mask) !== (expected & check_mask))
$fatal (1, "register_file_rtl vector %0d got=%h expected=%h mask=%h", i, { qb_rtl, qa_rtl }, expected, check_mask);
if (({ qb_chips, qa_chips } & check_mask) !== (expected & check_mask))
$fatal (1, "register_file_chips vector %0d got=%h expected=%h mask=%h", i, { qb_chips, qa_chips }, expected, check_mask);
end
$display ("PASS register_file: 300 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_we = data [0 +: 1];
wire [1:0] i_wa = data [1 +: 2];
wire [1:0] i_ra = data [3 +: 2];
wire [1:0] i_rb = data [5 +: 2];
wire [3:0] i_data = data [7 +: 4];
logic [3:0] o_qa;
logic [3:0] o_qb;
register_file reference_core
(
.clk (clk),
.we (i_we),
.wa (i_wa),
.ra (i_ra),
.rb (i_rb),
.data (i_data),
.qa (o_qa),
.qb (o_qb)
);
assign reference_result = { 24'b0, o_qb, o_qa };
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_register_file # (.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_register_file # (.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/.
300 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 |
|---|---|
| we | data[0:0] |
| wa | data[2:1] |
| ra | data[4:3] |
| rb | data[6:5] |
| data | data[10:7] |
| qa | result[3:0] |
| qb | result[7:4] |
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_we = data [0 +: 1];
wire [1:0] io_wa = data [1 +: 2];
wire [1:0] io_ra = data [3 +: 2];
wire [1:0] io_rb = data [5 +: 2];
wire [3:0] io_data = data [7 +: 4];
logic [3:0] io_qa;
logic [3:0] io_qb;
generate
if (CHIP_MODEL == 0)
begin : generic_design
register_file dut
(
.clk (clk),
.we (io_we),
.wa (io_wa),
.ra (io_ra),
.rb (io_rb),
.data (io_data),
.qa (io_qa),
.qb (io_qb)
);
end
else
begin : physical_design
register_file_chips dut
(
.clk (clk),
.we (io_we),
.wa (io_wa),
.ra (io_ra),
.rb (io_rb),
.data (io_data),
.qa (io_qa),
.qb (io_qb)
);
end
endgenerate
assign result = { 24'b0, { io_qb, io_qa } };
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_register_file. 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_register_file
# (
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
Write 1,2,4,8 to addresses 0,1,2,3. Set WE=0 and sweep RA/RB independently. Write F while reading the same address; the read output changes after the write edge.
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