← Breadboard exercisesРусский
BB-BAS-06 · CMOS → RTL → FPGA → ASIC

4008 adder with three decimal displays

Wire it, predict it, simulate both descriptions, then move the same behavior into programmable logic.

1. Purpose and prerequisites

The 4008 performs a four-bit binary addition without a clock. Carry propagates through combinational logic; no state or sequence is required. Three 4511 chips decode operand A, operand B and the low result nibble. This connects the full-adder equations to the arithmetic datapath used inside a processor.

Before starting: know how the breadboard’s five-hole strips and split power rails work. Use regulated 5 V, qualified button modules with built-in pull-downs and the specified 5 V indicators. The bare seven-segment displays use the source inventory’s segment resistors. No observation buffer or added clock-conditioning circuit is used.

Current starting guide · SystemVerilog style rules

2. Behavior, symbols and observations

The five-bit result is {cout,sum}=A+B+cin, from 0 to 31. The three displays show A, B and sum[3:0] only when the corresponding nibble is 0…9; 10…15 is blank. cout lights a separate 5 V indicator. For an ordinary decimal equation on the three digits, choose A,B in 0…9 and A+B+cin≤9. This circuit performs no binary-to-BCD conversion and has no tens digit.

4008 adder with three decimal displays · behavior
SVG · PNG · Open SVG to inspect at full size.
ABcinBinary resultA / B / SUM displayscout
23052 / 3 / 50
44194 / 4 / 90
910109 / 1 / blank0
880168 / 8 / 01
1515131blank / blank / blank1

3. Parts you need

PartQuantityLSSK rowPurpose
CD4008B · DIP16Logic IC
CD4511B · DIP37Logic IC
830-contact breadboard245Main board(s)
5 V regulated power module156Regulated output to logic rails
USB-to-9 V cable157Input to compatible regulator module
Active-high button module965One per data/control bit; built-in pull-down
5 V current-limited LED146Direct logic indication
Common-cathode seven-segment display349Row 49 green or row 50 red; map actual pins
560 Ω resistor, 1/2 W2151One per segment a…g
M–M jumper6470Board and inter-board wiring
M–F lead5871External modules/display terminals; adapt connector ends to actual parts

CSV · Quantities cover this build, not supplier packs. All 122 leads are listed in the wiring schedule; no reserve is included.

The 560 Ω resistors are the original LSSK row 51 parts, seven per bare display. They are not the rejected 2.2 kΩ observation resistors. Do not substitute one shared cathode resistor for seven segment resistors.

4. Chip functions, pins and polarity

4008 adder with three decimal displays · pinouts
SVG · PNG · Open SVG to inspect at full size.

Pin diagrams are top views with the notch UP. In the horizontal breadboard drawing the notch turns LEFT, so pin 1 is below the trench. Signal names ending in _n and labels with / are active low. Q1/A1 on a chip corresponds to bit [0] in RTL. Power pins are physical connections and are omitted from ideal HDL models.

U1 · CD4008B · all pins

Manufacturer pin/function reference

PinFunctionDirectionNetHole
1A4Inputa[3]B1.f8
2B3Inputb[2]B1.f9
3A3Inputa[2]B1.f10
4B2Inputb[1]B1.f11
5A2Inputa[1]B1.f12
6B1Inputb[0]B1.f13
7A1Inputa[0]B1.f14
8VSSPowerGNDB1.f15
9CIInputcinB1.e15
10S1Outputsum[0]B1.e14
11S2Outputsum[1]B1.e13
12S3Outputsum[2]B1.e12
13S4Outputsum[3]B1.e11
14COOutputcoutB1.e10
15B4Inputb[3]B1.e9
16VDDPower+5VB1.e8
U2 · CD4511B · all pins

Manufacturer pin/function reference

PinFunctionDirectionNetHole
1BInputa[1]B1.f31
2CInputa[2]B1.f32
3LT_NInput+5VB1.f33
4BI_NInput+5VB1.f34
5LEInputGNDB1.f35
6DInputa[3]B1.f36
7AInputa[0]B1.f37
8VSSPowerGNDB1.f38
9SEG_EOutputseg_a[4]B1.e38
10SEG_DOutputseg_a[3]B1.e37
11SEG_COutputseg_a[2]B1.e36
12SEG_BOutputseg_a[1]B1.e35
13SEG_AOutputseg_a[0]B1.e34
14SEG_GOutputseg_a[6]B1.e33
15SEG_FOutputseg_a[5]B1.e32
16VDDPower+5VB1.e31
U3 · CD4511B · all pins

Manufacturer pin/function reference

PinFunctionDirectionNetHole
1BInputb[1]B2.f8
2CInputb[2]B2.f9
3LT_NInput+5VB2.f10
4BI_NInput+5VB2.f11
5LEInputGNDB2.f12
6DInputb[3]B2.f13
7AInputb[0]B2.f14
8VSSPowerGNDB2.f15
9SEG_EOutputseg_b[4]B2.e15
10SEG_DOutputseg_b[3]B2.e14
11SEG_COutputseg_b[2]B2.e13
12SEG_BOutputseg_b[1]B2.e12
13SEG_AOutputseg_b[0]B2.e11
14SEG_GOutputseg_b[6]B2.e10
15SEG_FOutputseg_b[5]B2.e9
16VDDPower+5VB2.e8
U4 · CD4511B · all pins

Manufacturer pin/function reference

PinFunctionDirectionNetHole
1BInputsum[1]B2.f34
2CInputsum[2]B2.f35
3LT_NInput+5VB2.f36
4BI_NInput+5VB2.f37
5LEInputGNDB2.f38
6DInputsum[3]B2.f39
7AInputsum[0]B2.f40
8VSSPowerGNDB2.f41
9SEG_EOutputseg_sum[4]B2.e41
10SEG_DOutputseg_sum[3]B2.e40
11SEG_COutputseg_sum[2]B2.e39
12SEG_BOutputseg_sum[1]B2.e38
13SEG_AOutputseg_sum[0]B2.e37
14SEG_GOutputseg_sum[6]B2.e36
15SEG_FOutputseg_sum[5]B2.e35
16VDDPower+5VB2.e34

5. Schematic 1 · Generic logic

4008 adder with three decimal displays · logic
SVG · PNG · Open SVG to inspect at full size.

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

6. Schematic 2 · Chip connections

4008 adder with three decimal displays · connections
SVG · PNG · Open SVG to inspect at full size.

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

Full pin/net database

7. Schematic 3 · Breadboard and assembly

4008 adder with three decimal displays · breadboard
SVG · PNG · Open SVG to inspect at full size.

B1/B2 identify boards. Each a–e strip at one column is connected internally; f–j is a separate strip. TP/BP are positive rails, TG/BG are ground. Bridge each illustrated rail at 25–26 and join top/bottom rails. Follow the actual board’s continuity if its rails differ. Matching inter-board W labels denote the two ends of one wire.

The boxes outside the main board show button, clock and display terminals by function, not connector pin order or an assumed display package. Support these parts beside the board and use the named leads; map the actual display pins first. The two regulator output leads are included; the upstream USB-to-9 V cable feeds only the compatible regulator input. Logic rails receive 5 V.

  1. Build and check one 4511/display channel using lesson 5 before assembling all three. Map each display’s segment terminals separately.
  2. Install U1=4008 and U2=4511 for A on B1. Put U3=4511 for B and U4=4511 for SUM on B2. Join the two boards’ +5 V and GND rails.
  3. Connect four A modules to 4008 A1…A4 and to the A display decoder; connect four B modules similarly. Connect the ninth module to carry-in pin 9. A1/B1 are bit 0, not bit 1 in RTL indexing.
  4. Connect S1…S4 pins 10,11,12,13 to U4 A,B,C,D. All 4511 LE pins 5 go to GND; /LT pins 3 and /BI pins 4 go to +5 V. Connect 21 separate 560 Ω segment resistors.
  5. Start with 2+3+0=5, then 4+4+1=9. Use the examples below to distinguish a blank result from binary carry. Keep all inputs defined while changing values.
Exact jumper schedule

CSV

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+5VB1.BP50B2.TP50
W014GNDB1.BG50B2.TG50
W015a[3]B1.j8B1.j36
W016a[3]B1.i36S4.OUT
W017b[2]B1.j9B2.j9
W018b[2]B2.i9S7.OUT
W019a[2]B1.j10B1.j32
W020a[2]B1.i32S3.OUT
W021b[1]B1.j11B2.j8
W022b[1]B2.i8S6.OUT
W023a[1]B1.j12B1.j31
W024a[1]B1.i31S2.OUT
W025b[0]B1.j13B2.j14
W026b[0]B2.i14S5.OUT
W027a[0]B1.j14B1.j37
W028a[0]B1.i37S1.OUT
W029GNDB1.j15B1.BG2
W030GNDB1.j35B1.BG3
W031GNDB1.j38B1.BG4
W032GNDB2.j12B2.BG2
W033GNDB2.j15B2.BG3
W034GNDB2.j38B2.BG4
W035GNDB2.j41B2.BG5
W036GNDS1.GNDB1.BG5
W037GNDS2.GNDB1.BG6
W038GNDS3.GNDB1.BG7
W039GNDS4.GNDB1.BG8
W040GNDS5.GNDB1.BG9
W041GNDS6.GNDB1.BG10
W042GNDS7.GNDB1.BG11
W043GNDS8.GNDB1.BG12
W044GNDS9.GNDB1.BG13
W045GNDPWR.GNDB1.BG14
W046GNDL1.KB1.BG15
W047GNDDS1.COM1B1.BG16
W048GNDDS1.COM2B1.BG17
W049GNDDS2.COM1B2.BG6
W050GNDDS2.COM2B2.BG7
W051GNDDS3.COM1B2.BG8
W052GNDDS3.COM2B2.BG9
W053cinB1.a15S9.OUT
W054sum[0]B1.a14B2.j40
W055sum[1]B1.a13B2.j34
W056sum[2]B1.a12B2.j35
W057sum[3]B1.a11B2.j39
W058coutB1.a10L1.A
W059b[3]B1.a9B2.j13
W060b[3]B2.i13S8.OUT
W061+5VB1.a8B1.TP2
W062+5VB1.j33B1.BP2
W063+5VB1.j34B1.BP3
W064+5VB1.a31B1.TP3
W065+5VB2.j10B2.BP2
W066+5VB2.j11B2.BP3
W067+5VB2.a8B2.TP2
W068+5VB2.j36B2.BP4
W069+5VB2.j37B2.BP5
W070+5VB2.a34B2.TP3
W071+5VS1.VCCB1.BP4
W072+5VS2.VCCB1.BP5
W073+5VS3.VCCB1.BP6
W074+5VS4.VCCB1.BP7
W075+5VS5.VCCB1.BP8
W076+5VS6.VCCB1.BP9
W077+5VS7.VCCB1.BP10
W078+5VS8.VCCB1.BP11
W079+5VS9.VCCB1.BP12
W080+5VPWR.+5VB1.BP13
W081seg_a[4]B1.a38B1.a53
W082seg_a[3]B1.a37B1.a52
W083seg_a[2]B1.a36B1.a51
W084seg_a[1]B1.a35B1.a50
W085seg_a[0]B1.a34B1.a49
W086seg_a[6]B1.a33B1.a55
W087seg_a[5]B1.a32B1.a54
W088seg_b[4]B2.a15B2.a26
W089seg_b[3]B2.a14B2.a25
W090seg_b[2]B2.a13B2.a24
W091seg_b[1]B2.a12B2.a23
W092seg_b[0]B2.a11B2.a22
W093seg_b[6]B2.a10B2.a28
W094seg_b[5]B2.a9B2.a27
W095seg_sum[4]B2.a41B2.a53
W096seg_sum[3]B2.a40B2.a52
W097seg_sum[2]B2.a39B2.a51
W098seg_sum[1]B2.a38B2.a50
W099seg_sum[0]B2.a37B2.a49
W100seg_sum[6]B2.a36B2.a55
W101seg_sum[5]B2.a35B2.a54
W102DS1.aB1.j49DS1.a
W103DS1.bB1.j50DS1.b
W104DS1.cB1.j51DS1.c
W105DS1.dB1.j52DS1.d
W106DS1.eB1.j53DS1.e
W107DS1.fB1.j54DS1.f
W108DS1.gB1.j55DS1.g
W109DS2.aB2.j22DS2.a
W110DS2.bB2.j23DS2.b
W111DS2.cB2.j24DS2.c
W112DS2.dB2.j25DS2.d
W113DS2.eB2.j26DS2.e
W114DS2.fB2.j27DS2.f
W115DS2.gB2.j28DS2.g
W116DS3.aB2.j49DS3.a
W117DS3.bB2.j50DS3.b
W118DS3.cB2.j51DS3.c
W119DS3.dB2.j52DS3.d
W120DS3.eB2.j53DS3.e
W121DS3.fB2.j54DS3.f
W122DS3.gB2.j55DS3.g
Resistor lead positions
PartValueEnd 1End 2
R1a560 ΩB1.b49B1.h49
R1b560 ΩB1.b50B1.h50
R1c560 ΩB1.b51B1.h51
R1d560 ΩB1.b52B1.h52
R1e560 ΩB1.b53B1.h53
R1f560 ΩB1.b54B1.h54
R1g560 ΩB1.b55B1.h55
R2a560 ΩB2.b22B2.h22
R2b560 ΩB2.b23B2.h23
R2c560 ΩB2.b24B2.h24
R2d560 ΩB2.b25B2.h25
R2e560 ΩB2.b26B2.h26
R2f560 ΩB2.b27B2.h27
R2g560 ΩB2.b28B2.h28
R3a560 ΩB2.b49B2.h49
R3b560 ΩB2.b50B2.h50
R3c560 ΩB2.b51B2.h51
R3d560 ΩB2.b52B2.h52
R3e560 ΩB2.b53B2.h53
R3f560 ΩB2.b54B2.h54
R3g560 ΩB2.b55B2.h55

8. Generic synthesizable SystemVerilog

rtl/basic_adder.sv

Download source

// Synthesizable, zero-delay generic circuit. Segment order: { g, f, e, d, c, b, a }.

module basic_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 };

    // Each display decodes one nibble. Values 10..15 are blank.
    always_comb
    begin
        case (a)
        4'd0:     seg_a = 7'h3f;
        4'd1:     seg_a = 7'h06;
        4'd2:     seg_a = 7'h5b;
        4'd3:     seg_a = 7'h4f;
        4'd4:     seg_a = 7'h66;
        4'd5:     seg_a = 7'h6d;
        4'd6:     seg_a = 7'h7c;
        4'd7:     seg_a = 7'h07;
        4'd8:     seg_a = 7'h7f;
        4'd9:     seg_a = 7'h67;
        default:  seg_a = '0;
        endcase

        case (b)
        4'd0:     seg_b = 7'h3f;
        4'd1:     seg_b = 7'h06;
        4'd2:     seg_b = 7'h5b;
        4'd3:     seg_b = 7'h4f;
        4'd4:     seg_b = 7'h66;
        4'd5:     seg_b = 7'h6d;
        4'd6:     seg_b = 7'h7c;
        4'd7:     seg_b = 7'h07;
        4'd8:     seg_b = 7'h7f;
        4'd9:     seg_b = 7'h67;
        default:  seg_b = '0;
        endcase

        case (sum)
        4'd0:     seg_sum = 7'h3f;
        4'd1:     seg_sum = 7'h06;
        4'd2:     seg_sum = 7'h5b;
        4'd3:     seg_sum = 7'h4f;
        4'd4:     seg_sum = 7'h66;
        4'd5:     seg_sum = 7'h6d;
        4'd6:     seg_sum = 7'h7c;
        4'd7:     seg_sum = 7'h07;
        4'd8:     seg_sum = 7'h7f;
        4'd9:     seg_sum = 7'h67;
        default:  seg_sum = '0;
        endcase
    end

endmodule

The style guide requires four-space indentation and plain input/output net ports. RTL, chip models and wrappers contain no timeunit, timeprecision or `timescale; each testbench file uses `timescale 1ns / 1ps before its module. always_ff describes edge-triggered state; assign/always_comb describe combinational logic. The display lesson deliberately uses always_latch because LE controls a transparent latch.

9. CMOS chip models

Models describe ideal powered logic with no propagation delays, loading, bounce or metastability. The 4511 model uses TI’s digit shapes. The 4029 model covers the wired JAM=0000 configuration. CD4013 SET_TIED_LOW=1 selects the synthesizable configuration used here; its general SET/RESET branch is for simulation. CD4511 TRANSPARENT=1 specializes the adder’s fixed LE=0 connection.

models/cd4008b.sv

Download source

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

Download source

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

module cd4511b
# (
    parameter TRANSPARENT = 0
)
(
    input              p1_b,
    input              p2_c,
    input              p3_lt_n,
    input              p4_bi_n,
    input              p5_le,
    input              p6_d,
    input              p7_a,
    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 [3:0] held;
    logic [6:0] segments;

    generate
        if (TRANSPARENT != 0)
        begin : fixed_transparent
            // Physical LE is tied low in the adder lesson.
            assign held = { p6_d, p2_c, p1_b, p7_a };
        end
        else
        begin : controlled_latch
            always_latch
                if (~ p5_le)
                    held = { p6_d, p2_c, p1_b, p7_a };
        end
    endgenerate

    always_comb
    begin
        if (~ p3_lt_n)
            segments = 7'h7f;
        else if (~ p4_bi_n)
            segments = '0;
        else
        begin
            case (held)
            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'h7c;
            4'd7:     segments = 7'h07;
            4'd8:     segments = 7'h7f;
            4'd9:     segments = 7'h67;
            default:  segments = '0;
            endcase
        end
    end

    assign { p14_seg_g, p15_seg_f, p9_seg_e, p10_seg_d,
             p11_seg_c, p12_seg_b, p13_seg_a } = segments;

endmodule

10. Pin-connected SystemVerilog

rtl/basic_adder_chips.sv

Download source

// Synthesizable pin-connected circuit, generated from netlist data.
// Supply pins and passive display components are physical only.

module basic_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])
    );

    cd4511b # (.TRANSPARENT (1)) u2
    (
        .p1_b         (a [1]),
        .p2_c         (a [2]),
        .p3_lt_n      (1'b1),
        .p4_bi_n      (1'b1),
        .p5_le        (1'b0),
        .p6_d         (a [3]),
        .p7_a         (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])
    );

    cd4511b # (.TRANSPARENT (1)) u3
    (
        .p1_b         (b [1]),
        .p2_c         (b [2]),
        .p3_lt_n      (1'b1),
        .p4_bi_n      (1'b1),
        .p5_le        (1'b0),
        .p6_d         (b [3]),
        .p7_a         (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])
    );

    cd4511b # (.TRANSPARENT (1)) u4
    (
        .p1_b         (sum [1]),
        .p2_c         (sum [2]),
        .p3_lt_n      (1'b1),
        .p4_bi_n      (1'b1),
        .p5_le        (1'b0),
        .p6_d         (sum [3]),
        .p7_a         (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 implementation is generated from the same physical pin/net database as the schematic tables. Open unused outputs with empty named port connections; physical unused inputs remain tied to their listed levels.

11. Testbenches and simulator scripts

The core bench compares both implementations against independent expected values. The integration bench checks both variants through the full BGM wrappers and Tiny Tapeout wrapper, including segment order, scan selection and output enable. Inputs change after a sampling/settling step; clocks have independent generators. Necessary # 1 delays allow combinational/NBA settling or observe asynchronous reset before another edge. Watchdogs count cycles.

cd breadboard/basics_adder
./scripts/run_icarus.sh
./scripts/run_questa.sh
./scripts/run_verilator.sh
python3 scripts/check_synthesis.py
ToolRecorded result
icarus14PASS
verilatorPASS
synthesisPASS
questaRUNTIME BLOCKED
icarus12PASS
questa_compile_allPASS

Compatibility target: Icarus 13, Questa and current Verilator. Available binaries here: Icarus 12 and 14 development, Verilator 5.053 development, Questa 2025.2. Icarus 13 itself is not installed. Questa compilation is checked separately from execution: this sandbox reports an invalid license host when loading simulation. No Questa runtime pass is claimed. Synthesis uses the built-in Yosys read_verilog -sv reader; Slang is optional with --frontend slang. The simulation runners provide a 1ns/1ps default for RTL without time declarations in Questa and Verilator.

Tool results · Wiring checks

tb/tb_basic_adder.sv

Download source

`timescale 1ns / 1ps

module tb_basic_adder;

    localparam period         = 20;
    localparam timeout_cycles = 3000;

    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_g;
    logic [3:0] sum_c;
    logic cout_g;
    logic cout_c;
    logic [6:0] seg_a_g;
    logic [6:0] seg_a_c;
    logic [6:0] seg_b_g;
    logic [6:0] seg_b_c;
    logic [6:0] seg_sum_g;
    logic [6:0] seg_sum_c;
    int checks = 0;

    basic_adder dut_g
    (
        .a            (a),
        .b            (b),
        .cin          (cin),
        .sum          (sum_g),
        .cout         (cout_g),
        .seg_a        (seg_a_g),
        .seg_b        (seg_b_g),
        .seg_sum      (seg_sum_g)
    );

    basic_adder_chips dut_c
    (
        .a            (a),
        .b            (b),
        .cin          (cin),
        .sum          (sum_c),
        .cout         (cout_c),
        .seg_a        (seg_a_c),
        .seg_b        (seg_b_c),
        .seg_sum      (seg_sum_c)
    );

    task check (input logic [3:0] expected_sum, input logic expected_cout, input logic [6:0] expected_seg_a, input logic [6:0] expected_seg_b, input logic [6:0] expected_seg_sum);
        if (sum_g !== expected_sum || sum_c !== expected_sum)
            $fatal (1, "sum: generic=%h chips=%h expected=%h", sum_g, sum_c, expected_sum);
        if (cout_g !== expected_cout || cout_c !== expected_cout)
            $fatal (1, "cout: generic=%h chips=%h expected=%h", cout_g, cout_c, expected_cout);
        if (seg_a_g !== expected_seg_a || seg_a_c !== expected_seg_a)
            $fatal (1, "seg_a: generic=%h chips=%h expected=%h", seg_a_g, seg_a_c, expected_seg_a);
        if (seg_b_g !== expected_seg_b || seg_b_c !== expected_seg_b)
            $fatal (1, "seg_b: generic=%h chips=%h expected=%h", seg_b_g, seg_b_c, expected_seg_b);
        if (seg_sum_g !== expected_seg_sum || seg_sum_c !== expected_seg_sum)
            $fatal (1, "seg_sum: generic=%h chips=%h expected=%h", seg_sum_g, seg_sum_c, expected_seg_sum);
        checks = checks + 1;
    endtask

    function automatic logic [6:0] glyph (input int value);
        case (value)
        0:       glyph = 7'b0111111;
        1:       glyph = 7'b0000110;
        2:       glyph = 7'b1011011;
        3:       glyph = 7'b1001111;
        4:       glyph = 7'b1100110;
        5:       glyph = 7'b1101101;
        6:       glyph = 7'b1111100;
        7:       glyph = 7'b0000111;
        8:       glyph = 7'b1111111;
        9:       glyph = 7'b1100111;
        default: glyph = '0;
        endcase
    endfunction

    initial
    begin
        $dumpfile ("trace.vcd");
        $dumpvars (0, tb_basic_adder);

        for (int ia = 0; ia < 16; ia ++)
            for (int ib = 0; ib < 16; ib ++)
                for (int ic = 0; ic < 2; ic ++)
                begin
                    int total;
                    @ (posedge clk);
                    a     = 4' (ia);
                    b     = 4' (ib);
                    cin   = 1' (ic);
                    total = ia + ib + ic;
                    # 1;  // Adder carry chain and all three decoders settle.
                    check (4' (total % 16), total >= 16,
                        glyph (ia), glyph (ib), glyph (total % 16));
                end

        $display ("PASS basic_adder: %0d independent checks", checks);
        $finish;
    end

    initial
    begin
        repeat (timeout_cycles) @ (posedge clk);
        $fatal (1, "Timeout in clock cycles");
    end

endmodule
tb/tb_integrations.sv

Download source

`timescale 1ns / 1ps

module tb_integrations;

    localparam period = 20;
    logic clk = 1'b0;
    logic rst = 1'b0;
    logic ena = 1'b1;
    logic [7:0] data = '0;
    logic [3:0] aux  = '0;
    logic [7:0] expected_led;
    logic [20:0] expected_segments;
    logic [7:0] lab_led [2], hack_led [2], tt_out [2];
    logic [7:0] lab_seg [2], hack_seg [2], lab_digit [2], hack_digit [2];
    logic [7:0] tt_uio [2], tt_oe [2];

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

    exercise_bridge expected
    (
        .clk          (clk),
        .rst          (rst),
        .data         (data),
        .aux          (aux),
        .led          (expected_led),
        .segments     (expected_segments)
    );

    for (genvar v = 0; v < 2; v ++)
    begin : versions
        wire [99:0] lab_gpio = { 96'b0, aux };
        wire [3:0] hack_gpio = aux;

        lab_top # (.CHIP_MODEL (v), .SCAN_BITS (4)) lab
        (
            .clk          (clk),
            .slow_clk     (clk),
            .rst          (rst),
            .key          (4'b0),
            .sw           (data),
            .led          (lab_led [v]),
            .abcdefgh     (lab_seg [v]),
            .digit        (lab_digit [v]),
            .x            (10'b0),
            .y            (9'b0),
            .red          (),
            .green        (),
            .blue         (),
            .mic          (24'b0),
            .sound        (),
            .uart_rx      (1'b1),
            .uart_tx      (),
            .gpio         (lab_gpio)
        );
        hackathon_top # (.CHIP_MODEL (v), .SCAN_BITS (4)) hack
        (
            .clock        (clk),
            .slow_clock   (clk),
            .reset        (rst),
            .key          (data),
            .led          (hack_led [v]),
            .abcdefgh     (hack_seg [v]),
            .digit        (hack_digit [v]),
            .x            (10'b0),
            .y            (9'b0),
            .red          (),
            .green        (),
            .blue         (),
            .gpio         (hack_gpio)
        );
        tt_um_basic_adder # (.CHIP_MODEL (v)) tt
        (
            .ui_in        (data),
            .uo_out       (tt_out [v]),
            .uio_in       ({ 4'b0, aux }),
            .uio_out      (tt_uio [v]),
            .uio_oe       (tt_oe [v]),
            .ena          (ena),
            .clk          (clk),
            .rst_n        (~ rst)
        );
    end

    initial
    begin
        @ (posedge clk);
        # 1;
        rst = 1'b1;
        # 1;  // Let asynchronous reset propagate through wrappers.
        rst = 1'b0;
        for (int i = 0; i < 80; i ++)
        begin
            logic [6:0] scan_seg;
            logic [7:0] scan_digits;
            logic [7:0] tt_expected;
            int phase;

            @ (posedge clk);
            # 1;  // NBA updates, scan mux and wrapper outputs settle.
            phase       = ((i + 1) % 16) / 4;
            scan_digits = phase < 3 ? (8'b1 << phase) : 8'b0;
            scan_seg    = phase < 3 ? 7' (expected_segments >> (phase * 7)) : 7'b0;
            case (aux [2:1])
            2'd0: tt_expected = { expected_led [4], expected_segments [6:0] };
            2'd1: tt_expected = { expected_led [4], expected_segments [20:14] };
            2'd2: tt_expected = { expected_led [4], expected_segments [13:7] };
            default: tt_expected = { expected_led [4], 7'b0 };
            endcase
            for (int v = 0; v < 2; v ++)
            begin
                if (lab_led [v] !== expected_led || hack_led [v] !== expected_led)
                    $fatal (1, "Platform data mapping, variant %0d", v);
                if (lab_digit [v] !== scan_digits || hack_digit [v] !== scan_digits)
                    $fatal (1, "Digit selection/polarity");
                if (lab_seg [v] !== { scan_seg [0], scan_seg [1], scan_seg [2],
                    scan_seg [3], scan_seg [4], scan_seg [5], scan_seg [6], 1'b0 }
                    || hack_seg [v] !== lab_seg [v])
                    $fatal (1, "BGM segment bit order");
                if (tt_out [v] !== (ena ? tt_expected : 8'b0)
                    || tt_oe [v] !== (ena ? 8'hf0 : 8'b0)
                    || tt_uio [v] !== (ena ? { expected_led [3:0], 4'b0 } : 8'b0))
                    $fatal (1, "Tiny Tapeout polarity, selector or output enable");
            end
            data = 8' (i * 17);
            aux  = 4' (i);
            ena  = (i % 5 != 0);
        end
        $display ("PASS integrations: 80 steps, both variants, BGM scan and Tiny Tapeout mapping/enable");
        $finish;
    end

    initial
    begin
        repeat (100) @ (posedge clk);
        $fatal (1, "Integration timeout in cycles");
    end
endmodule
scripts/run_icarus.sh

Download source

#!/usr/bin/env bash
set -euo pipefail
exec "$(dirname -- "${BASH_SOURCE[0]}")/run.sh" icarus
scripts/run_questa.sh

Download source

#!/usr/bin/env bash
set -euo pipefail

# Preserve explicit tool choices; otherwise find a local Quartus installation.
questa_bin=${QUESTA_BIN:-}
if [[ -z "$questa_bin" ]]; then
    if command -v "${VSIM:-vsim}" > /dev/null 2>&1; then
        questa_bin=$(dirname -- "$(command -v "${VSIM:-vsim}")")
    else
        for candidate in "$HOME"/altera_lite/*/questa_fse/bin \
                         "$HOME"/intelFPGA_lite/*/questa_fse/bin \
                         /opt/altera_lite/*/questa_fse/bin \
                         /opt/intelFPGA_lite/*/questa_fse/bin; do
            if [[ -x "$candidate/vsim" ]]; then
                questa_bin=$candidate
                break
            fi
        done
    fi
fi
if [[ -n "$questa_bin" ]]; then
    export VLIB=${VLIB:-$questa_bin/vlib}
    export VMAP=${VMAP:-$questa_bin/vmap}
    export VLOG=${VLOG:-$questa_bin/vlog}
    export VSIM=${VSIM:-$questa_bin/vsim}
fi

# Read the user's existing license; never copy it into the project or archive.
if [[ -z "${SALT_LICENSE_SERVER:-}" && -f "$HOME/flexlm/license.dat" ]]; then
    export SALT_LICENSE_SERVER="$HOME/flexlm/license.dat"
fi

exec "$(dirname -- "${BASH_SOURCE[0]}")/run.sh" questa
scripts/run_verilator.sh

Download source

#!/usr/bin/env bash
set -euo pipefail
exec "$(dirname -- "${BASH_SOURCE[0]}")/run.sh" verilator
scripts/run.sh

Download source

#!/usr/bin/env bash
set -euo pipefail
exercise_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)
simulator=${1:-icarus}
build_dir="$exercise_dir/build/$simulator"
mkdir -p "$build_dir"
cd "$build_dir"
sources=("$exercise_dir"/rtl/*.sv "$exercise_dir"/models/*.sv "$exercise_dir"/integration/*.sv "$exercise_dir"/integration/bgm_lab/*.sv "$exercise_dir"/integration/bgm_hackathon/*.sv "$exercise_dir"/integration/tinytapeout/project.v)
for bench in "$exercise_dir"/tb/*.sv; do
    top=$(basename "$bench" .sv)
    case "$simulator" in
        icarus)
            "${IVERILOG:-iverilog}" -g2012 -Wall -s "$top" -o "$top.vvp" "${sources[@]}" "$bench" > "$top.compile.log" 2>&1 || { cat "$top.compile.log"; exit 1; }
            "${VVP:-vvp}" "$top.vvp" | tee "$top.log"
            ;;
        questa)
            [[ -f modelsim.ini ]] || "${VMAP:-vmap}" -c > /dev/null
            [[ -d work ]] || "${VLIB:-vlib}" work
            "${VLOG:-vlog}" -sv -timescale 1ns/1ps -work work "${sources[@]}" "$bench" > "$top.compile.log" 2>&1 || { cat "$top.compile.log"; exit 1; }
            "${VSIM:-vsim}" -batch -onfinish exit "work.$top" -do "onerror {quit -code 1}; onbreak {quit -code 1}; run -all; quit -code 0" 2>&1 | tee "$top.log"
            ;;
        verilator)
            "${VERILATOR:-verilator}" --binary --timing --trace --timescale 1ns/1ps --top-module "$top" --Mdir "obj_$top" -Wno-PINCONNECTEMPTY -Wno-DECLFILENAME -j 2 "${sources[@]}" "$bench" > "$top.compile.log" 2>&1 || { cat "$top.compile.log"; exit 1; }
            "./obj_$top/V$top" | tee "$top.log"
            ;;
        *) echo "Usage: $0 {icarus|questa|verilator}" >&2; exit 2 ;;
    esac
    grep -q 'PASS ' "$top.log" || { echo "Missing PASS: $top" >&2; exit 1; }
done
scripts/check_synthesis.py

Download source

#!/usr/bin/env python3
"""Check both cores using the built-in Yosys reader, or optionally Slang."""
import argparse
import os
from pathlib import Path
import subprocess


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--frontend', choices=['verilog', 'slang'], default='verilog')
    args = parser.parse_args()
    exercise = Path(__file__).resolve().parents[1]
    build = exercise / 'build/synthesis'
    build.mkdir(parents=True, exist_ok=True)
    sources = sorted((exercise / 'rtl').glob('*.sv'))
    sources += sorted((exercise / 'models').glob('*.sv'))
    # Fixed relative source names also work when the exercise directory has spaces.
    filenames = ' '.join(p.relative_to(exercise).as_posix() for p in sources)
    yosys = os.environ.get('YOSYS', 'yosys')

    for top in ['basic_adder', 'basic_adder_chips']:
        read = (f'read_slang --top {top}' if args.frontend == 'slang'
                else 'read_verilog -sv')
        commands = (f'{read} {filenames}; '
                    f'synth -top {top} -flatten; check -assert; stat')
        log = build / f'{top}.log'
        with log.open('w') as output:
            plugin = ['-m', 'slang'] if args.frontend == 'slang' else []
            result = subprocess.run([yosys, '-Q'] + plugin + ['-p', commands],
                                    cwd=exercise, stdout=output, stderr=subprocess.STDOUT)
        if result.returncode:
            print(log.read_text())
            raise SystemExit(result.returncode)
        print(f'PASS synthesis: {top} (Yosys, {args.frontend} frontend); {log}')


if __name__ == '__main__':
    main()

12. BGM lab_top integration

data[3:0]=A; data[7:4]=B; aux[0]=cin. led[3:0]=sum; led[4]=cout. segments[20:14]=A, [13:7]=B, [6:0]=SUM, each in g…a order.

The full lab_top interface is supplied: sw[7:0] provides data, GPIO[3:0] provides aux, slow_clk clocks sequential lessons, and rst resets them. LEDs show the mapped logical outputs. Use at least eight switches for the adder and at least three digit positions for its scanned display. Unused sound/video outputs have defined values.

CHIP_MODEL=0 selects generic RTL; 1 selects chip-connected RTL. The adapter converts internal segment order {g,f,e,d,c,b,a} to BGM {a,b,c,d,e,f,g,dp}, active high. The scan module cycles SUM, B, A and a blank slot using the fast clock; it is platform display logic, not an extra breadboard clock phase. For the other lessons, only the first display slot has data or the display is blank.

python3 scripts/stage_integration.py bgm_lab /tmp/basics_adder_bgm_lab

Stage into an empty directory, then copy the selected wrapper and all staged RTL/models into a new BGM lab/problem. Add the listed files in sources.f to the board project; replace its existing top, do not compile two copies. The wrapper alone is not a board pin-constraint file. Board-specific polarity and constraints remain the BGM infrastructure’s responsibility.

integration/bgm_lab/lab_top.sv

Download source

// Full BGM interface. Requires w_sw >= 8 and w_gpio >= 4.
// The adder uses three display positions; the 4511 lesson uses one.

module lab_top
# (
    parameter SCAN_BITS     = 16,
    parameter CHIP_MODEL    = 0,
    parameter clk_mhz       = 50,
    parameter w_key         = 4,
    parameter w_sw          = 8,
    parameter w_led         = 8,
    parameter w_digit       = 8,
    parameter w_gpio        = 100,

    parameter screen_width  = 640,
    parameter screen_height = 480,

    parameter w_red         = 4,
    parameter w_green       = 4,
    parameter w_blue        = 4,

    parameter w_x           = $clog2 (screen_width),
    parameter w_y           = $clog2 (screen_height)
)
(
    input                  clk,
    input                  slow_clk,
    input                  rst,

    // Keys, switches, LEDs

    input  [w_key   - 1:0] key,
    input  [w_sw    - 1:0] sw,
    output [w_led   - 1:0] led,

    // A dynamic seven-segment display

    output [          7:0] abcdefgh,
    output [w_digit - 1:0] digit,

    // Graphics

    input  [w_x     - 1:0] x,
    input  [w_y     - 1:0] y,

    output [w_red   - 1:0] red,
    output [w_green - 1:0] green,
    output [w_blue  - 1:0] blue,

    // Microphone, sound output and UART

    input  [         23:0] mic,
    output [         15:0] sound,

    input                  uart_rx,
    output                 uart_tx,

    // General-purpose Input/Output

    inout  [w_gpio  - 1:0] gpio
);

    logic [7:0] exercise_led;
    logic [20:0] segments;
    logic [7:0] scan_digit;

    exercise_bridge # (.CHIP_MODEL (CHIP_MODEL)) exercise
    (
        .clk          (slow_clk),
        .rst          (rst),
        .data         (8' (sw)),
        .aux          (4' (gpio)),
        .led          (exercise_led),
        .segments     (segments)
    );

    exercise_scan # (.SCAN_BITS (SCAN_BITS)) scan
    (
        .clk          (clk),
        .rst          (rst),
        .segments     (segments),
        .abcdefgh     (abcdefgh),
        .digit        (scan_digit)
    );

    assign led      = w_led' (exercise_led);
    assign digit    = w_digit' (scan_digit);
    assign sound    = '0;
    assign uart_tx  = 1'b1;
    assign red      = '0;
    assign green    = '0;
    assign blue     = '0;
    assign gpio     = 'z;

endmodule
integration/exercise_bridge.sv

Download source

// Synthesizable platform adapter. Not part of the breadboard circuit.

module exercise_bridge
# (
    parameter CHIP_MODEL = 0
)
(
    input              clk,
    input              rst,
    input        [7:0] data,
    input        [3:0] aux,
    output       [7:0] led,
    output       [20:0] segments
);

    logic [3:0] sum;
    logic cout;
    logic [6:0] seg_a;
    logic [6:0] seg_b;
    logic [6:0] seg_sum;

    generate
        if (CHIP_MODEL == 0)
        begin : generic_version
            basic_adder dut
            (
                .a            (data [3:0]),
                .b            (data [7:4]),
                .cin          (aux [0]),
                .sum          (sum),
                .cout         (cout),
                .seg_a        (seg_a),
                .seg_b        (seg_b),
                .seg_sum      (seg_sum)
            );
        end
        else
        begin : chip_version
            basic_adder_chips dut
            (
                .a            (data [3:0]),
                .b            (data [7:4]),
                .cin          (aux [0]),
                .sum          (sum),
                .cout         (cout),
                .seg_a        (seg_a),
                .seg_b        (seg_b),
                .seg_sum      (seg_sum)
            );
        end
    endgenerate

    assign led      = { 3'b0, cout, sum };
    assign segments = { seg_a, seg_b, seg_sum };

endmodule
integration/exercise_scan.sv

Download source

// Synthesizable scan adapter: fast infrastructure clock, not slow exercise clock.
module exercise_scan
# (
    parameter SCAN_BITS = 16
)
(
    input               clk,
    input               rst,
    input        [20:0] segments,
    output        [7:0] abcdefgh,
    output logic  [7:0] digit
);
    logic [SCAN_BITS - 1:0] phase;
    logic [6:0] selected;

    always_ff @ (posedge clk or posedge rst)
        if (rst)
            phase <= '0;
        else
            phase <= phase + 1'b1;

    always_comb
    begin
        selected = '0;
        digit    = '0;
        case (phase [SCAN_BITS - 1 -: 2])
        2'd0: begin selected = segments [ 6: 0]; digit = 8'b0000_0001; end
        2'd1: begin selected = segments [13: 7]; digit = 8'b0000_0010; end
        2'd2: begin selected = segments [20:14]; digit = 8'b0000_0100; end
        default: begin end
        endcase
    end

    // BGM order [7:0] = { a,b,c,d,e,f,g,dp }, active high.
    assign abcdefgh = { selected [0], selected [1], selected [2],
                       selected [3], selected [4], selected [5],
                       selected [6], 1'b0 };
endmodule

13. BGM hackathon_top integration

data[3:0]=A; data[7:4]=B; aux[0]=cin. led[3:0]=sum; led[4]=cout. segments[20:14]=A, [13:7]=B, [6:0]=SUM, each in g…a order.

BGM names this module hackathon_top (with h). This wrapper matches the current 800×480 example: x[9:0], y[8:0]. key[7:0] provides data; GPIO[3:0] provides aux. slow_clock clocks the lesson; reset is active high. Keys are live levels, so hold the required combination or use the board’s input facilities. The fast clock drives display scanning only.

CHIP_MODEL=0 selects generic RTL; 1 selects chip-connected RTL. The adapter converts internal segment order {g,f,e,d,c,b,a} to BGM {a,b,c,d,e,f,g,dp}, active high. The scan module cycles SUM, B, A and a blank slot using the fast clock; it is platform display logic, not an extra breadboard clock phase. For the other lessons, only the first display slot has data or the display is blank.

python3 scripts/stage_integration.py bgm_hackathon /tmp/basics_adder_bgm_hackathon

Stage into an empty directory, then copy the selected wrapper and all staged RTL/models into a new BGM lab/problem. Add the listed files in sources.f to the board project; replace its existing top, do not compile two copies. The wrapper alone is not a board pin-constraint file. Board-specific polarity and constraints remain the BGM infrastructure’s responsibility.

integration/bgm_hackathon/hackathon_top.sv

Download source

// The BGM module is spelled hackathon_top, with "h".

module hackathon_top
# (
    parameter SCAN_BITS  = 16,
    parameter CHIP_MODEL = 0
)
(
    input        clock,
    input        slow_clock,
    input        reset,

    input  [7:0] key,
    output [7:0] led,

    // A dynamic seven-segment display

    output [7:0] abcdefgh,
    output [7:0] digit,

    // LCD screen interface

    input  [9:0] x,
    input  [8:0] y,

    output [4:0] red,
    output [5:0] green,
    output [4:0] blue,

    inout  [3:0] gpio
);

    logic [7:0] exercise_led;
    logic [20:0] segments;
    logic [7:0] scan_digit;

    exercise_bridge # (.CHIP_MODEL (CHIP_MODEL)) exercise
    (
        .clk          (slow_clock),
        .rst          (reset),
        .data         (key),
        .aux          (gpio),
        .led          (exercise_led),
        .segments     (segments)
    );

    exercise_scan # (.SCAN_BITS (SCAN_BITS)) scan
    (
        .clk          (clock),
        .rst          (reset),
        .segments     (segments),
        .abcdefgh     (abcdefgh),
        .digit        (scan_digit)
    );

    assign led      = exercise_led;
    assign digit    = scan_digit;
    assign red      = '0;
    assign green    = '0;
    assign blue     = '0;
    assign gpio     = 'z;

endmodule

14. Tiny Tapeout project.v integration

data[3:0]=A; data[7:4]=B; aux[0]=cin. led[3:0]=sum; led[4]=cout. segments[20:14]=A, [13:7]=B, [6:0]=SUM, each in g…a order.

ui_in[7:0] supplies data; uio_in[3:0] supplies aux. uio[7:4] outputs led[3:0]; uio[3:0] remains input. ena=0 disables all bidirectional output enables and drives output values low. rst_n is inverted. Supply a slow external clock for the sequential demos. Compile project.v as SystemVerilog together with the listed dependencies. Keep all time declarations out of RTL; use `timescale 1ns / 1ps only in testbenches, matching the Tiny Tapeout template test/tb.v.

Tiny Tapeout has one eight-bit display output, so select a view with uio_in[2:1]: 00=SUM nibble, 01=A, 10=B, 11=blank. uio_in[0]=cin. The decimal point shows binary carry. This wrapper cannot show three physical digits simultaneously on a single output Pmod; the breadboard still has all three displays.

These are alternative HDL implementations inside FPGA/ASIC infrastructure, not instructions to connect 5 V breadboard outputs to FPGA or Tiny Tapeout pins.

python3 scripts/stage_integration.py tinytapeout /tmp/basics_adder_tt

The staging helper writes a matching sources.f and info_fragment.yaml with flat file names. Merge that fragment into the Tiny Tapeout template and include these sources in its SystemVerilog input list.

integration/tinytapeout/project.v

Download source

// Synthesizable Tiny Tapeout top; project.v must be compiled as SystemVerilog.

module tt_um_basic_adder
# (
    parameter CHIP_MODEL = 0
)
(
    input        [7:0] ui_in,
    input        [7:0] uio_in,
    input              ena,
    input              clk,
    input              rst_n,
    output       [7:0] uo_out,
    output       [7:0] uio_out,
    output       [7:0] uio_oe
);

    logic [7:0] led;
    logic [20:0] segments;
    logic [6:0] selected;

    exercise_bridge # (.CHIP_MODEL (CHIP_MODEL)) exercise
    (
        .clk          (clk),
        .rst          (~ rst_n),
        .data         (ui_in),
        .aux          (uio_in [3:0]),
        .led          (led),
        .segments     (segments)
    );

    // aux[2:1]: 0=sum nibble, 1=A, 2=B, 3=blank. DP shows binary carry.
    always_comb
    begin
        case (uio_in [2:1])
        2'd0: selected = segments [6:0];
        2'd1: selected = segments [20:14];
        2'd2: selected = segments [13:7];
        default: selected = '0;
        endcase
    end
    assign uo_out = ena ? { led [4], selected } : '0;
    assign uio_out = ena ? { led [3:0], 4'b0 } : '0;
    assign uio_oe  = ena ? 8'hf0 : '0;

endmodule
integration/tinytapeout/info_fragment.yaml

Download source

project:
  top_module: "tt_um_basic_adder"
  source_files:
    - "rtl/basic_adder.sv"
    - "rtl/basic_adder_chips.sv"
    - "models/cd4008b.sv"
    - "models/cd4511b.sv"
    - "integration/exercise_bridge.sv"
    - "integration/tinytapeout/project.v"
# Merge into your template; keep its remaining required metadata.
scripts/stage_integration.py

Download source

#!/usr/bin/env python3
"""Stage one platform example and all dependencies into a new directory."""
from pathlib import Path
import argparse, shutil
p=argparse.ArgumentParser()
p.add_argument('platform',choices=['bgm_lab','bgm_hackathon','tinytapeout'])
p.add_argument('destination',type=Path)
a=p.parse_args()
root=Path(__file__).resolve().parents[1]
if a.destination.exists() and any(a.destination.iterdir()):
    p.error('Choose an empty directory to avoid overwriting an existing project.')
a.destination.mkdir(parents=True,exist_ok=True)
files=list((root/'rtl').glob('*.sv'))+list((root/'models').glob('*.sv'))+list((root/'integration').glob('*.sv'))
files+=list((root/'integration'/a.platform).glob('*.sv'))+list((root/'integration'/a.platform).glob('*.v'))
for f in files:shutil.copy2(f,a.destination/f.name)
(a.destination/'sources.f').write_text(''.join(f.name+'\n' for f in files))
if a.platform=='tinytapeout':
    import re
    original=(root/'integration/tinytapeout/info_fragment.yaml').read_text()
    top=re.search(r'top_module: "([^"]+)"',original).group(1)
    (a.destination/'info_fragment.yaml').write_text('project:\n  top_module: "'+top+'"\n  source_files:\n'+''.join('    - "'+f.name+'"\n' for f in files))
print('Staged',len(files),'HDL files in',a.destination)

15. Experiments, troubleshooting and sources

Try 9+1: SUM is blank, cout=0. Try 8+8: SUM shows 0, cout=1, so the binary result is 16, not zero. Try 15+15+1: both argument displays and SUM are blank, cout=1; the binary result is 31. Explain why a 4511 is not a binary-to-decimal converter. A future extension could add a tens decoder or a conversion circuit, but neither is part of this three-display build.

Display terminalActual physical pin, fill in
a________________
b________________
c________________
d________________
e________________
f________________
g________________
dp________________
COM1________________
COM2________________
ObservationCheck first
Nothing responds5 V at the IC, common GND, rail bridges, notch direction
Wrong bit or segmentBit 0 versus chip bit 1; the actual display pin map
Unexpected sequential behaviorReset, input stability at ↑clk, clock-module OUT and control polarity

Verification covers ideal RTL behavior and the static breadboard netlist. No physical assembly, LED current/brightness measurement, analog clock-level qualification or full FPGA place-and-route/ASIC signoff was performed. The source module variants still need checking on the actual hardware.

Rebuild with python3 breadboard/tools/build_basics.py --png. Drawings, source files, pin tables and translations are generated from the maintained files under breadboard/tools/. Simulator logs and validation records stay with each lesson.