← All exercisesРусский
LSSK · O01

Hexadecimal display with DM9368

1. Purpose and prerequisites

Wire the source’s DM9368 alternative to display hexadecimal operands and result.

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.

For this higher-current optional display build, use inventory power option 2: regulated 5 V through the barrel adapter, with at least 1 A available. Do not use the 9 V cable with this direct-input adapter.

2. Behavior, symbols and observations

Optional legacy DM9368N: it decodes 0…F and includes segment current sources. Use a common-cathode display rated for its roughly 20 mA/segment output at the specified forward voltage; check the actual display rating and regulator budget. Do not transplant the 4511 resistor wiring blindly. LE=0, RBI=1; RBO is left open.

This is a separately qualified optional build, not a drop-in 4511 replacement: control pin assignments differ. The supplied model covers transparent decoding only. Source stock and authenticity of this obsolete device are not established.

PortDirectionBits
ainput4
binput4
cininput1
sumoutput4
coutoutput1
seg_aoutput7
seg_boutput7
seg_sumoutput7
abcinsumcoutseg_aseg_bseg_sum
00000636363
100106636
20020916391
30030796379
4004010263102
5005010963109
6006012563125
700707637
0011063636
15151151113113113

The table is a sample; the testbench checks all 512 combinations in vectors.hex. Values in the table are unsigned decimal.

3. Parts you need

PartQuantityLSSK row
CD4008B · DIP16
DM9368 · DIP38
830-contact breadboard445
Qualified button channels (sets of five)966
5 V barrel adapter (direct regulated input)158
USB-to-5 V cable; supply rated at least 1 A159
5 V current-limited LED146
Common-cathode seven-segment display349
M–M jumper5670
External-module lead (M–F assumed)5871

CSV · Jumper schedule · Pin/net data

Counts describe this exact layout, without spare jumpers. The button quantity counts independent channels: buy 2 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

CD4008B

4-bit adder · Manufacturer datasheet

PinSignalType
1a4input
2b3input
3a3input
4b2input
5a2input
6b1input
7a1input
8vsssupply
9ciinput
10s1output
11s2output
12s3output
13s4output
14cooutput
15b4input
16vddsupply

DM9368

Hex → seven segments · Manufacturer datasheet

PinSignalType
1a1input
2a2input
3leinput
4rbooutput
5rbiinput
6a3input
7a0input
8vsssupply
9seg_eoutput
10seg_doutput
11seg_coutput
12seg_boutput
13seg_aoutput
14seg_goutput
15seg_foutput
16vddsupply

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

Hexadecimal display with DM9368 · logic
SVG · PNG

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

Hexadecimal display with DM9368 · connections
SVG · PNG
DevicePinSignalNet
U11a4a[3]
U12b3b[2]
U13a3a[2]
U14b2b[1]
U15a2a[1]
U16b1b[0]
U17a1a[0]
U18vssGND
U19cicin
U110s1sum[0]
U111s2sum[1]
U112s3sum[2]
U113s4sum[3]
U114cocout
U115b4b[3]
U116vdd+5V
U21a1a[1]
U22a2a[2]
U23leGND
U24rboNC
U25rbi+5V
U26a3a[3]
U27a0a[0]
U28vssGND
U29seg_eseg_a[4]
U210seg_dseg_a[3]
U211seg_cseg_a[2]
U212seg_bseg_a[1]
U213seg_aseg_a[0]
U214seg_gseg_a[6]
U215seg_fseg_a[5]
U216vdd+5V
U31a1b[1]
U32a2b[2]
U33leGND
U34rboNC
U35rbi+5V
U36a3b[3]
U37a0b[0]
U38vssGND
U39seg_eseg_b[4]
U310seg_dseg_b[3]
U311seg_cseg_b[2]
U312seg_bseg_b[1]
U313seg_aseg_b[0]
U314seg_gseg_b[6]
U315seg_fseg_b[5]
U316vdd+5V
U41a1sum[1]
U42a2sum[2]
U43leGND
U44rboNC
U45rbi+5V
U46a3sum[3]
U47a0sum[0]
U48vssGND
U49seg_eseg_sum[4]
U410seg_dseg_sum[3]
U411seg_cseg_sum[2]
U412seg_bseg_sum[1]
U413seg_aseg_sum[0]
U414seg_gseg_sum[6]
U415seg_fseg_sum[5]
U416vdd+5V
DisplaySegments a…gCommon pins
DS1seg_a[0]…seg_a[6]Both cathodes → GND; dp open
DS2seg_b[0]…seg_b[6]Both cathodes → GND; dp open
DS3seg_sum[0]…seg_sum[6]Both cathodes → GND; dp open

The source inventory does not establish a universal display pinout. Identify a…g, both common cathodes and dp from your exact display datasheet before wiring. The diagram uses functional terminal names.

7. Schematic 3 · Breadboard and assembly

Hexadecimal display with DM9368 · breadboard
SVG · PNG
  1. Disconnect power. Bridge each split power rail as shown; verify that +5 V and GND are separate.
  2. 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.
  3. Wire supplies, fixed controls and unused inputs first. Follow jumpers.csv from W001 onward; matching wire labels across boards denote one wire.
  4. Connect data/control modules, then the indicators and clock. Do not leave CMOS inputs floating. Start/reset/load as specified in section 2.
  5. Compare 9+1, A+5 and F+1 with the 4511 version. The sum nibble wraps at F and COUT indicates the fifth bit.

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
IDNetFromTo
W001+5VB1.TP25B1.TP26
W002GNDB1.TG25B1.TG26
W003+5VB1.BP25B1.BP26
W004GNDB1.BG25B1.BG26
W005+5VB1.TP1B1.BP1
W006GNDB1.TG1B1.BG1
W007+5VB2.TP25B2.TP26
W008GNDB2.TG25B2.TG26
W009+5VB2.BP25B2.BP26
W010GNDB2.BG25B2.BG26
W011+5VB2.TP1B2.BP1
W012GNDB2.TG1B2.BG1
W013+5VB3.TP25B3.TP26
W014GNDB3.TG25B3.TG26
W015+5VB3.BP25B3.BP26
W016GNDB3.BG25B3.BG26
W017+5VB3.TP1B3.BP1
W018GNDB3.TG1B3.BG1
W019+5VB4.TP25B4.TP26
W020GNDB4.TG25B4.TG26
W021+5VB4.BP25B4.BP26
W022GNDB4.BG25B4.BG26
W023+5VB4.TP1B4.BP1
W024GNDB4.TG1B4.BG1
W025+5VB1.BP50B2.TP50
W026GNDB1.BG50B2.TG50
W027+5VB2.BP50B3.TP50
W028GNDB2.BG50B3.TG50
W029+5VB3.BP50B4.TP50
W030GNDB3.BG50B4.TG50
W031a[3]B1.j5B1.j24
W032a[3]B1.i24S4.OUT
W033b[2]B1.j6B1.j34
W034b[2]B1.i34S7.OUT
W035a[2]B1.j7B1.j20
W036a[2]B1.i20S3.OUT
W037b[1]B1.j8B1.j33
W038b[1]B1.i33S6.OUT
W039a[1]B1.j9B1.j19
W040a[1]B1.i19S2.OUT
W041b[0]B1.j10B1.j39
W042b[0]B1.i39S5.OUT
W043a[0]B1.j11B1.j25
W044a[0]B1.i25S1.OUT
W045GNDB1.j12B1.BG2
W046GNDB1.j21B1.BG3
W047GNDB1.j26B1.BG4
W048GNDB1.j35B1.BG5
W049GNDB1.j40B1.BG6
W050GNDB1.j49B1.BG7
W051GNDB1.j54B1.BG8
W052GNDS1.GNDB1.BG9
W053GNDS2.GNDB2.BG2
W054GNDS3.GNDB3.BG2
W055GNDS4.GNDB4.BG2
W056GNDS5.GNDB1.BG10
W057GNDS6.GNDB2.BG3
W058GNDS7.GNDB3.BG3
W059GNDS8.GNDB4.BG3
W060GNDS9.GNDB1.BG11
W061GNDPWR.GNDB1.BG12
W062GNDL1.KB1.BG13
W063GNDDS1.COM1B2.BG4
W064GNDDS1.COM2B2.BG5
W065GNDDS2.COM1B3.BG4
W066GNDDS2.COM2B3.BG5
W067GNDDS3.COM1B4.BG4
W068GNDDS3.COM2B4.BG5
W069cinB1.a12S9.OUT
W070sum[0]B1.a11B1.j53
W071sum[1]B1.a10B1.j47
W072sum[2]B1.a9B1.j48
W073sum[3]B1.a8B1.j52
W074coutB1.a7L1.A
W075b[3]B1.a6B1.j38
W076b[3]B1.i38S8.OUT
W077+5VB1.a5B1.TP2
W078+5VB1.j23B1.BP2
W079+5VB1.a19B1.TP3
W080+5VB1.j37B1.BP3
W081+5VB1.a33B1.TP4
W082+5VB1.j51B1.BP4
W083+5VB1.a47B1.TP5
W084+5VS1.VCCB1.BP5
W085+5VS2.VCCB2.BP2
W086+5VS3.VCCB3.BP2
W087+5VS4.VCCB4.BP2
W088+5VS5.VCCB1.BP6
W089+5VS6.VCCB2.BP3
W090+5VS7.VCCB3.BP3
W091+5VS8.VCCB4.BP3
W092+5VS9.VCCB1.BP7
W093+5VPWR.+5VB1.BP8
W094seg_a[4]B1.a26DS1.e
W095seg_a[3]B1.a25DS1.d
W096seg_a[2]B1.a24DS1.c
W097seg_a[1]B1.a23DS1.b
W098seg_a[0]B1.a22DS1.a
W099seg_a[6]B1.a21DS1.g
W100seg_a[5]B1.a20DS1.f
W101seg_b[4]B1.a40DS2.e
W102seg_b[3]B1.a39DS2.d
W103seg_b[2]B1.a38DS2.c
W104seg_b[1]B1.a37DS2.b
W105seg_b[0]B1.a36DS2.a
W106seg_b[6]B1.a35DS2.g
W107seg_b[5]B1.a34DS2.f
W108seg_sum[4]B1.a54DS3.e
W109seg_sum[3]B1.a53DS3.d
W110seg_sum[2]B1.a52DS3.c
W111seg_sum[1]B1.a51DS3.b
W112seg_sum[0]B1.a50DS3.a
W113seg_sum[6]B1.a49DS3.g
W114seg_sum[5]B1.a48DS3.f

8. Generic synthesizable SystemVerilog

rtl/hexadecimal_adder.sv

Download

// Synthesizable generic design.

module hexadecimal_adder
(
    input        [3:0] a,
    input        [3:0] b,
    input              cin,
    output       [3:0] sum,
    output             cout,
    output logic [6:0] seg_a,
    output logic [6:0] seg_b,
    output logic [6:0] seg_sum
);

    assign { cout, sum } = { 1'b0, a } + { 1'b0, b } + { 4'b0, cin };
    always_comb
        case (a)
            0: seg_a       = 7'h3f;
            1: seg_a       = 7'h06;
            2: seg_a       = 7'h5b;
            3: seg_a       = 7'h4f;
            4: seg_a       = 7'h66;
            5: seg_a       = 7'h6d;
            6: seg_a       = 7'h7d;
            7: seg_a       = 7'h07;
            8: seg_a       = 7'h7f;
            9: seg_a       = 7'h67;
            10: seg_a      = 7'h77;
            11: seg_a      = 7'h7c;
            12: seg_a      = 7'h39;
            13: seg_a      = 7'h5e;
            14: seg_a      = 7'h79;
            15: seg_a      = 7'h71;
            default: seg_a = '0;
        endcase
    always_comb
        case (b)
            0: seg_b       = 7'h3f;
            1: seg_b       = 7'h06;
            2: seg_b       = 7'h5b;
            3: seg_b       = 7'h4f;
            4: seg_b       = 7'h66;
            5: seg_b       = 7'h6d;
            6: seg_b       = 7'h7d;
            7: seg_b       = 7'h07;
            8: seg_b       = 7'h7f;
            9: seg_b       = 7'h67;
            10: seg_b      = 7'h77;
            11: seg_b      = 7'h7c;
            12: seg_b      = 7'h39;
            13: seg_b      = 7'h5e;
            14: seg_b      = 7'h79;
            15: seg_b      = 7'h71;
            default: seg_b = '0;
        endcase
    always_comb
        case (sum)
            0: seg_sum       = 7'h3f;
            1: seg_sum       = 7'h06;
            2: seg_sum       = 7'h5b;
            3: seg_sum       = 7'h4f;
            4: seg_sum       = 7'h66;
            5: seg_sum       = 7'h6d;
            6: seg_sum       = 7'h7d;
            7: seg_sum       = 7'h07;
            8: seg_sum       = 7'h7f;
            9: seg_sum       = 7'h67;
            10: seg_sum      = 7'h77;
            11: seg_sum      = 7'h7c;
            12: seg_sum      = 7'h39;
            13: seg_sum      = 7'h5e;
            14: seg_sum      = 7'h79;
            15: seg_sum      = 7'h71;
            default: seg_sum = '0;
        endcase

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/cd4008b.sv

Download

// Synthesizable ideal functional model; physical power pins omitted.

module cd4008b
(
    input  p1_a4,
    input  p2_b3,
    input  p3_a3,
    input  p4_b2,
    input  p5_a2,
    input  p6_b1,
    input  p7_a1,
    input  p9_ci,
    input  p15_b4,
    output p10_s1,
    output p11_s2,
    output p12_s3,
    output p13_s4,
    output p14_co
);

    logic [4:0] carry;
    logic [3:0] a, b, sum;

    assign a         = { p1_a4, p3_a3, p5_a2, p7_a1 };
    assign b         = { p15_b4, p2_b3, p4_b2, p6_b1 };
    assign carry [0] = p9_ci;

    for (genvar i = 0; i < 4; i ++)
    begin : full_adder
        assign sum [i]       = a [i] ^ b [i] ^ carry [i];
        assign carry [i + 1] = (a [i] & b [i])
                                | ((a [i] ^ b [i]) & carry [i]);
    end

    assign { p13_s4, p12_s3, p11_s2, p10_s1 } = sum;
    assign p14_co                             = carry [4];

endmodule
models/dm9368.sv

Download

// Synthesizable ideal digital model; power and propagation delays omitted.
// Transparent decoder subset: LE=0, RBI=1, RBO unconnected.

module dm9368
(
    input  p1_a1,
    input  p2_a2,
    input  p3_le,
    input  p5_rbi,
    input  p6_a3,
    input  p7_a0,
    output p4_rbo,
    output p9_seg_e,
    output p10_seg_d,
    output p11_seg_c,
    output p12_seg_b,
    output p13_seg_a,
    output p14_seg_g,
    output p15_seg_f
);

    logic [6:0] segments;
    always_comb
        case ({ p6_a3, p2_a2, p1_a1, p7_a0 })
            4'd0: segments    = 7'h3f;
            4'd1: segments    = 7'h06;
            4'd2: segments    = 7'h5b;
            4'd3: segments    = 7'h4f;
            4'd4: segments    = 7'h66;
            4'd5: segments    = 7'h6d;
            4'd6: segments    = 7'h7d;
            4'd7: segments    = 7'h07;
            4'd8: segments    = 7'h7f;
            4'd9: segments    = 7'h67;
            4'd10: segments   = 7'h77;
            4'd11: segments   = 7'h7c;
            4'd12: segments   = 7'h39;
            4'd13: segments   = 7'h5e;
            4'd14: segments   = 7'h79;
            4'd15: segments   = 7'h71;
            default: segments = '0;
        endcase
    assign p13_seg_a = segments [0];
    assign p12_seg_b = segments [1];
    assign p11_seg_c = segments [2];
    assign p10_seg_d = segments [3];
    assign p9_seg_e  = segments [4];
    assign p15_seg_f = segments [5];
    assign p14_seg_g = segments [6];
    assign p4_rbo    = 1'b1;

endmodule

10. Pin-connected SystemVerilog

rtl/hexadecimal_adder_chips.sv

Download

// Pin connections are generated from the same netlist as the diagrams.
module hexadecimal_adder_chips
(
    input        [3:0] a,
    input        [3:0] b,
    input              cin,
    output       [3:0] sum,
    output             cout,
    output       [6:0] seg_a,
    output       [6:0] seg_b,
    output       [6:0] seg_sum
);


    cd4008b u1
    (
        .p1_a4        (a [3]),
        .p2_b3        (b [2]),
        .p3_a3        (a [2]),
        .p4_b2        (b [1]),
        .p5_a2        (a [1]),
        .p6_b1        (b [0]),
        .p7_a1        (a [0]),
        .p9_ci        (cin),
        .p10_s1       (sum [0]),
        .p11_s2       (sum [1]),
        .p12_s3       (sum [2]),
        .p13_s4       (sum [3]),
        .p14_co       (cout),
        .p15_b4       (b [3])
    );

    dm9368 u2
    (
        .p1_a1        (a [1]),
        .p2_a2        (a [2]),
        .p3_le        (1'b0),
        .p4_rbo       (),
        .p5_rbi       (1'b1),
        .p6_a3        (a [3]),
        .p7_a0        (a [0]),
        .p9_seg_e     (seg_a [4]),
        .p10_seg_d    (seg_a [3]),
        .p11_seg_c    (seg_a [2]),
        .p12_seg_b    (seg_a [1]),
        .p13_seg_a    (seg_a [0]),
        .p14_seg_g    (seg_a [6]),
        .p15_seg_f    (seg_a [5])
    );

    dm9368 u3
    (
        .p1_a1        (b [1]),
        .p2_a2        (b [2]),
        .p3_le        (1'b0),
        .p4_rbo       (),
        .p5_rbi       (1'b1),
        .p6_a3        (b [3]),
        .p7_a0        (b [0]),
        .p9_seg_e     (seg_b [4]),
        .p10_seg_d    (seg_b [3]),
        .p11_seg_c    (seg_b [2]),
        .p12_seg_b    (seg_b [1]),
        .p13_seg_a    (seg_b [0]),
        .p14_seg_g    (seg_b [6]),
        .p15_seg_f    (seg_b [5])
    );

    dm9368 u4
    (
        .p1_a1        (sum [1]),
        .p2_a2        (sum [2]),
        .p3_le        (1'b0),
        .p4_rbo       (),
        .p5_rbi       (1'b1),
        .p6_a3        (sum [3]),
        .p7_a0        (sum [0]),
        .p9_seg_e     (seg_sum [4]),
        .p10_seg_d    (seg_sum [3]),
        .p11_seg_c    (seg_sum [2]),
        .p12_seg_b    (seg_sum [1]),
        .p13_seg_a    (seg_sum [0]),
        .p14_seg_g    (seg_sum [6]),
        .p15_seg_f    (seg_sum [5])
    );

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

Download

`timescale 1ns / 1ps

module tb;

    localparam period       = 20;
    localparam vector_count = 512;
    logic [60:0] vectors [0:vector_count-1];
    logic [25:0] expected, check_mask;
    logic clk = 1'b0;

    always # (period / 2) clk = ~ clk;

    logic [3:0] a = '0;
    logic [3:0] b = '0;
    logic cin     = '0;
    logic [3:0] sum_rtl;
    logic [3:0] sum_chips;
    logic cout_rtl;
    logic cout_chips;
    logic [6:0] seg_a_rtl;
    logic [6:0] seg_a_chips;
    logic [6:0] seg_b_rtl;
    logic [6:0] seg_b_chips;
    logic [6:0] seg_sum_rtl;
    logic [6:0] seg_sum_chips;

    hexadecimal_adder dut_rtl
    (
        .a            (a),
        .b            (b),
        .cin          (cin),
        .sum          (sum_rtl),
        .cout         (cout_rtl),
        .seg_a        (seg_a_rtl),
        .seg_b        (seg_b_rtl),
        .seg_sum      (seg_sum_rtl)
    );

    hexadecimal_adder_chips dut_chips
    (
        .a            (a),
        .b            (b),
        .cin          (cin),
        .sum          (sum_chips),
        .cout         (cout_chips),
        .seg_a        (seg_a_chips),
        .seg_b        (seg_b_chips),
        .seg_sum      (seg_sum_chips)
    );

    initial
    begin
        $readmemh ("vectors.hex", vectors);
        @ (posedge clk);
        # 1;
        for (int i = 0; i < vector_count; i ++)
        begin
            a          = vectors [i] [0 +: 4];
            b          = vectors [i] [4 +: 4];
            cin        = vectors [i] [8 +: 1];
            expected   = vectors [i] [9 +: 26];
            check_mask = vectors [i] [35 +: 26];
            @ (posedge clk);
            # 1;  // Allow nonblocking state and combinational outputs to settle.
            if (({ seg_sum_rtl, seg_b_rtl, seg_a_rtl, cout_rtl, sum_rtl } & check_mask) !== (expected & check_mask))
                $fatal (1, "hexadecimal_adder_rtl vector %0d got=%h expected=%h mask=%h", i, { seg_sum_rtl, seg_b_rtl, seg_a_rtl, cout_rtl, sum_rtl }, expected, check_mask);
            if (({ seg_sum_chips, seg_b_chips, seg_a_chips, cout_chips, sum_chips } & check_mask) !== (expected & check_mask))
                $fatal (1, "hexadecimal_adder_chips vector %0d got=%h expected=%h mask=%h", i, { seg_sum_chips, seg_b_chips, seg_a_chips, cout_chips, sum_chips }, expected, check_mask);
        end
        $display ("PASS hexadecimal_adder: 512 oracle vectors");
        $finish;
    end

    initial
    begin
        repeat (vector_count * 3 + 20) @ (posedge clk);
        $fatal (1, "Cycle watchdog");
    end

endmodule
tb/tb_integrations.sv

Download

`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 [3:0] i_a = data [0 +: 4];
    wire [3:0] i_b = data [4 +: 4];
    wire i_cin     = data [8 +: 1];
    logic [3:0] o_sum;
    logic o_cout;
    logic [6:0] o_seg_a;
    logic [6:0] o_seg_b;
    logic [6:0] o_seg_sum;
    hexadecimal_adder reference_core
    (
        .a            (i_a),
        .b            (i_b),
        .cin          (i_cin),
        .sum          (o_sum),
        .cout         (o_cout),
        .seg_a        (o_seg_a),
        .seg_b        (o_seg_b),
        .seg_sum      (o_seg_sum)
    );
    assign reference_result = { 6'b0, o_seg_sum, o_seg_b, o_seg_a, o_cout, o_sum };
    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 = { o_seg_sum, o_seg_b, o_seg_a };
    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_hexadecimal_adder # (.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_hexadecimal_adder # (.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.sh

The 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/.

512 vectors. Test manifest · Source list

CheckResult
iverilog12PASS
iverilog14PASS
verilatorPASS
integrationsPASS
questa_compilePASS
questa_integrations_compilePASS
yosys_genericPASS
yosys_chipsPASS
yosys_tinytapeoutPASS
wrappersPASS

Tool results

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.

Questa runtime log

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.

RTLPacked bus
adata[3:0]
bdata[7:4]
cindata[8:8]
sumresult[3:0]
coutresult[4:4]
seg_aresult[11:5]
seg_bresult[18:12]
seg_sumresult[25:19]
integration/exercise_adapter.sv

Download

module exercise_adapter
# (
    parameter CHIP_MODEL = 0
)
(
    input               clk,
    input               rst,
    input        [15:0] data,
    output       [31:0] result,
    output       [20:0] segments
);

    wire [3:0] io_a = data [0 +: 4];
    wire [3:0] io_b = data [4 +: 4];
    wire io_cin     = data [8 +: 1];
    logic [3:0] io_sum;
    logic io_cout;
    logic [6:0] io_seg_a;
    logic [6:0] io_seg_b;
    logic [6:0] io_seg_sum;
    generate
        if (CHIP_MODEL == 0)
        begin : generic_design
            hexadecimal_adder dut
            (
                .a            (io_a),
                .b            (io_b),
                .cin          (io_cin),
                .sum          (io_sum),
                .cout         (io_cout),
                .seg_a        (io_seg_a),
                .seg_b        (io_seg_b),
                .seg_sum      (io_seg_sum)
            );
        end
        else
        begin : physical_design
            hexadecimal_adder_chips dut
            (
                .a            (io_a),
                .b            (io_b),
                .cin          (io_cin),
                .sum          (io_sum),
                .cout         (io_cout),
                .seg_a        (io_seg_a),
                .seg_b        (io_seg_b),
                .seg_sum      (io_seg_sum)
            );
        end
    endgenerate
    assign result   = { 6'b0, { io_seg_sum, io_seg_b, io_seg_a, io_cout, io_sum } };
    assign segments = { io_seg_sum, io_seg_b, io_seg_a };
endmodule
integration/lab_top.sv

Download

// 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

Download

// 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

Download

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_hexadecimal_adder. 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

Download

module tt_um_hexadecimal_adder
# (
    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

Compare 9+1, A+5 and F+1 with the 4511 version. The sum nibble wraps at F and COUT indicates the fifth bit.

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