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

Serial adder with discrete carry register

1. Purpose and prerequisites

Replace the 4032 of P01 with the A02 full adder and one 4013 for carry; preserve the serializer, output register and displays.

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

Hold LOAD=1 over a falling edge and the following rising edge; this loads the CD4014s and initializes carry. Release LOAD just after that rising edge, then apply exactly eight shift edges. Each argument is a 4-bit value padded with four zero bits; wiring P8…P5 to bits 0…3 makes the stream LSB first.

Only after eight shifts is RESULT the complete five-bit sum. Keep A/B fixed during the run. The three 4511 displays show A, B and the low result nibble; codes 10…15 are blank. They do not form a multi-digit decimal sum. Probe result[4] for overflow; it also drives the second shift-register section.

PortDirectionBits
clkinput1
loadinput1
ainput4
binput4
resultoutput5
seg_aoutput7
seg_boutput7
seg_sumoutput7
Serial adder with discrete carry register · timing
SVG · PNG

3. Parts you need

PartQuantityLSSK row
CD4014B · DIP227
CD4070B · DIP12
CD4081B · DIP110
CD4071B · DIP120
CD4013B · DIP13
CD4015B · DIP15
CD4511B · DIP37
830-contact breadboard645
5 V regulated power module156
USB-to-9 V cable to regulator input157
Qualified button channels (sets of five)966
Assembled 555 clock module154
Common-cathode seven-segment display349
560 Ω resistor, 1/2 W2151
M–M jumper15870
External-module lead (M–F assumed)5971

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

CD4013B

CD4013B · Manufacturer datasheet

PinSignalType
1q1output
2qn1output
3clk1input
4rst1input
5d1input
6set1input
7vsssupply
8set2input
9d2input
10rst2input
11clk2input
12qn2output
13q2output
14vddsupply

CD4014B

8-stage parallel load / shift · Manufacturer datasheet

PinSignalType
1d7input
2q5output
3q7output
4d3input
5d2input
6d1input
7d0input
8vsssupply
9loadinput
10clkinput
11serialinput
12q6output
13d4input
14d5input
15d6input
16vddsupply

CD4015B

Two 4-stage shift registers · Manufacturer datasheet

PinSignalType
1clk_binput
2q4_boutput
3q3_aoutput
4q2_aoutput
5q1_aoutput
6rst_ainput
7d_ainput
8vsssupply
9clk_ainput
10q4_aoutput
11q3_boutput
12q2_boutput
13q1_boutput
14rst_binput
15d_binput
16vddsupply

CD4070B

CD4070B · Manufacturer datasheet

PinSignalType
1a1input
2b1input
3y1output
4y2output
5b2input
6a2input
7vsssupply
8a3input
9b3input
10y3output
11y4output
12b4input
13a4input
14vddsupply

CD4071B

CD4071B · Manufacturer datasheet

PinSignalType
1a1input
2b1input
3y1output
4y2output
5b2input
6a2input
7vsssupply
8a3input
9b3input
10y3output
11y4output
12b4input
13a4input
14vddsupply

CD4081B

CD4081B · Manufacturer datasheet

PinSignalType
1a1input
2b1input
3y1output
4y2output
5b2input
6a2input
7vsssupply
8a3input
9b3input
10y3output
11y4output
12b4input
13a4input
14vddsupply

CD4511B

BCD → seven segments · Manufacturer datasheet

PinSignalType
1binput
2cinput
3lt_ninput
4bi_ninput
5leinput
6dinput
7ainput
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

Serial adder with discrete carry register · 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

Serial adder with discrete carry register · connections
SVG · PNG
DevicePinSignalNet
U11d7a[0]
U12q5NC
U13q7a_serial
U14d3GND
U15d2GND
U16d1GND
U17d0GND
U18vssGND
U19loadload
U110clkclk
U111serialGND
U112q6NC
U113d4a[3]
U114d5a[2]
U115d6a[1]
U116vdd+5V
U21d7b[0]
U22q5NC
U23q7b_serial
U24d3GND
U25d2GND
U26d1GND
U27d0GND
U28vssGND
U29loadload
U210clkclk
U211serialGND
U212q6NC
U213d4b[3]
U214d5b[2]
U215d6b[1]
U216vdd+5V
U31a1a_serial
U32b1b_serial
U33y1n1
U34y2serial_sum
U35b2carry
U36a2n1
U37vssGND
U38a3GND
U39b3GND
U310y3NC
U311y4NC
U312b4GND
U313a4GND
U314vdd+5V
U41a1a_serial
U42b1b_serial
U43y1n2
U44y2n3
U45b2carry
U46a2n1
U47vssGND
U48a3GND
U49b3GND
U410y3NC
U411y4NC
U412b4GND
U413a4GND
U414vdd+5V
U51a1n2
U52b1n3
U53y1n4
U54y2NC
U55b2GND
U56a2GND
U57vssGND
U58a3GND
U59b3GND
U510y3NC
U511y4NC
U512b4GND
U513a4GND
U514vdd+5V
U61q1carry
U62qn1NC
U63clk1clk
U64rst1load
U65d1n4
U66set1GND
U67vssGND
U68set2GND
U69d2GND
U610rst2GND
U611clk2GND
U612qn2NC
U613q2NC
U614vdd+5V
U71clk_bclk
U72q4_bresult[0]
U73q3_aNC
U74q2_aNC
U75q1_aNC
U76rst_aload
U77d_aserial_sum
U78vssGND
U79clk_aclk
U710q4_aresult[4]
U711q3_bresult[1]
U712q2_bresult[2]
U713q1_bresult[3]
U714rst_bload
U715d_bresult[4]
U716vdd+5V
U81ba[1]
U82ca[2]
U83lt_n+5V
U84bi_n+5V
U85leGND
U86da[3]
U87aa[0]
U88vssGND
U89seg_eseg_a[4]
U810seg_dseg_a[3]
U811seg_cseg_a[2]
U812seg_bseg_a[1]
U813seg_aseg_a[0]
U814seg_gseg_a[6]
U815seg_fseg_a[5]
U816vdd+5V
U91bb[1]
U92cb[2]
U93lt_n+5V
U94bi_n+5V
U95leGND
U96db[3]
U97ab[0]
U98vssGND
U99seg_eseg_b[4]
U910seg_dseg_b[3]
U911seg_cseg_b[2]
U912seg_bseg_b[1]
U913seg_aseg_b[0]
U914seg_gseg_b[6]
U915seg_fseg_b[5]
U916vdd+5V
U101bresult[1]
U102cresult[2]
U103lt_n+5V
U104bi_n+5V
U105leGND
U106dresult[3]
U107aresult[0]
U108vssGND
U109seg_eseg_sum[4]
U1010seg_dseg_sum[3]
U1011seg_cseg_sum[2]
U1012seg_bseg_sum[1]
U1013seg_aseg_sum[0]
U1014seg_gseg_sum[6]
U1015seg_fseg_sum[5]
U1016vdd+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

Serial adder with discrete carry register · 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. Run 3+4, 9+1, 15+1 and 15+15. Record each serial SUM bit before its sampling edge and reconstruct the result. Reassert LOAD before every new word.

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+5VB5.TP25B5.TP26
W026GNDB5.TG25B5.TG26
W027+5VB5.BP25B5.BP26
W028GNDB5.BG25B5.BG26
W029+5VB5.TP1B5.BP1
W030GNDB5.TG1B5.BG1
W031+5VB6.TP25B6.TP26
W032GNDB6.TG25B6.TG26
W033+5VB6.BP25B6.BP26
W034GNDB6.BG25B6.BG26
W035+5VB6.TP1B6.BP1
W036GNDB6.TG1B6.BG1
W037+5VB1.BP50B2.TP50
W038GNDB1.BG50B2.TG50
W039+5VB2.BP50B3.TP50
W040GNDB2.BG50B3.TG50
W041+5VB3.BP50B4.TP50
W042GNDB3.BG50B4.TG50
W043+5VB4.BP50B5.TP50
W044GNDB4.BG50B5.TG50
W045+5VB5.BP50B6.TP50
W046GNDB5.BG50B6.TG50
W047a[0]B1.j5B2.j53
W048a[0]B2.i53S2.OUT
W049a_serialB1.j7B1.j33
W050a_serialB1.i33B1.j47
W051GNDB1.j8B1.BG2
W052GNDB1.j9B1.BG3
W053GNDB1.j10B1.BG4
W054GNDB1.j11B1.BG5
W055GNDB1.j12B1.BG6
W056GNDB1.a10B1.TG2
W057GNDB1.j22B1.BG7
W058GNDB1.j23B1.BG8
W059GNDB1.j24B1.BG9
W060GNDB1.j25B1.BG10
W061GNDB1.j26B1.BG11
W062GNDB1.a24B1.TG3
W063GNDB1.j39B1.BG12
W064GNDB1.a39B1.TG4
W065GNDB1.a38B1.TG5
W066GNDB1.a35B1.TG6
W067GNDB1.a34B1.TG7
W068GNDB1.j53B1.BG13
W069GNDB1.a53B1.TG8
W070GNDB1.a52B1.TG9
W071GNDB1.a49B1.TG10
W072GNDB1.a48B1.TG11
W073GNDB2.j9B2.BG2
W074GNDB2.j10B2.BG3
W075GNDB2.j11B2.BG4
W076GNDB2.a11B2.TG2
W077GNDB2.a10B2.TG3
W078GNDB2.a7B2.TG4
W079GNDB2.a6B2.TG5
W080GNDB2.j24B2.BG5
W081GNDB2.j25B2.BG6
W082GNDB2.a25B2.TG6
W083GNDB2.a24B2.TG7
W084GNDB2.a23B2.TG8
W085GNDB2.a22B2.TG9
W086GNDB2.j40B2.BG7
W087GNDB2.j51B2.BG8
W088GNDB2.j54B2.BG9
W089GNDB3.j9B3.BG2
W090GNDB3.j12B3.BG3
W091GNDB3.j23B3.BG4
W092GNDB3.j26B3.BG5
W093GNDS1.GNDB1.BG14
W094GNDS2.GNDB2.BG10
W095GNDS3.GNDB3.BG6
W096GNDS4.GNDB4.BG2
W097GNDS5.GNDB5.BG2
W098GNDS6.GNDB6.BG2
W099GNDS7.GNDB1.BG15
W100GNDS8.GNDB2.BG11
W101GNDS9.GNDB3.BG7
W102GNDCLK.GNDB1.BG16
W103GNDPWR.GNDB1.BG17
W104GNDDS1.COM1B4.BG3
W105GNDDS1.COM2B4.BG4
W106GNDDS2.COM1B5.BG3
W107GNDDS2.COM2B5.BG4
W108GNDDS3.COM1B6.BG3
W109GNDDS3.COM2B6.BG4
W110loadB1.a12B1.a26
W111loadB1.b26B2.j22
W112loadB2.i22B2.j38
W113loadB2.i38B2.a35
W114loadB2.b35S1.OUT
W115clkB1.a11B1.a25
W116clkB1.b25B2.j21
W117clkB2.i21B2.j33
W118clkB2.i33B2.a40
W119clkB2.b40CLK.OUT
W120a[3]B1.a8B2.j52
W121a[3]B2.i52S5.OUT
W122a[2]B1.a7B2.j48
W123a[2]B2.i48S4.OUT
W124a[1]B1.a6B2.j47
W125a[1]B2.i47S3.OUT
W126+5VB1.a5B1.TP2
W127+5VB1.a19B1.TP3
W128+5VB1.a33B1.TP4
W129+5VB1.a47B1.TP5
W130+5VB2.a5B2.TP2
W131+5VB2.a19B2.TP3
W132+5VB2.a33B2.TP4
W133+5VB2.j49B2.BP2
W134+5VB2.j50B2.BP3
W135+5VB2.a47B2.TP5
W136+5VB3.j7B3.BP2
W137+5VB3.j8B3.BP3
W138+5VB3.a5B3.TP2
W139+5VB3.j21B3.BP4
W140+5VB3.j22B3.BP5
W141+5VB3.a19B3.TP3
W142+5VS1.VCCB1.BP2
W143+5VS2.VCCB2.BP4
W144+5VS3.VCCB3.BP6
W145+5VS4.VCCB4.BP2
W146+5VS5.VCCB5.BP2
W147+5VS6.VCCB6.BP2
W148+5VS7.VCCB1.BP3
W149+5VS8.VCCB2.BP5
W150+5VS9.VCCB3.BP7
W151+5VCLK.VCCB1.BP4
W152+5VPWR.+5VB1.BP5
W153b[0]B1.j19B3.j11
W154b[0]B3.i11S6.OUT
W155b_serialB1.j21B1.j34
W156b_serialB1.i34B1.j48
W157b[3]B1.a22B3.j10
W158b[3]B3.i10S9.OUT
W159b[2]B1.a21B3.j6
W160b[2]B3.i6S8.OUT
W161b[1]B1.a20B3.j5
W162b[1]B3.i5S7.OUT
W163n1B1.j35B1.j38
W164n1B1.i38B1.j52
W165serial_sumB1.j36B2.j39
W166carryB1.j37B1.j51
W167carryB1.i51B2.j19
W168n2B1.j49B2.j5
W169n3B1.j50B2.j6
W170n4B2.j7B2.j23
W171result[0]B2.j34B3.j25
W172result[4]B2.a39B2.a34
W173result[1]B2.a38B3.j19
W174result[2]B2.a37B3.j20
W175result[3]B2.a36B3.j24
W176seg_a[4]B2.a54B4.a24
W177seg_a[3]B2.a53B4.a23
W178seg_a[2]B2.a52B4.a22
W179seg_a[1]B2.a51B4.a21
W180seg_a[0]B2.a50B4.a20
W181seg_a[6]B2.a49B4.a26
W182seg_a[5]B2.a48B4.a25
W183seg_b[4]B3.a12B5.a24
W184seg_b[3]B3.a11B5.a23
W185seg_b[2]B3.a10B5.a22
W186seg_b[1]B3.a9B5.a21
W187seg_b[0]B3.a8B5.a20
W188seg_b[6]B3.a7B5.a26
W189seg_b[5]B3.a6B5.a25
W190seg_sum[4]B3.a26B6.a24
W191seg_sum[3]B3.a25B6.a23
W192seg_sum[2]B3.a24B6.a22
W193seg_sum[1]B3.a23B6.a21
W194seg_sum[0]B3.a22B6.a20
W195seg_sum[6]B3.a21B6.a26
W196seg_sum[5]B3.a20B6.a25
W197DS1.aB4.j20DS1.a
W198DS1.bB4.j21DS1.b
W199DS1.cB4.j22DS1.c
W200DS1.dB4.j23DS1.d
W201DS1.eB4.j24DS1.e
W202DS1.fB4.j25DS1.f
W203DS1.gB4.j26DS1.g
W204DS2.aB5.j20DS2.a
W205DS2.bB5.j21DS2.b
W206DS2.cB5.j22DS2.c
W207DS2.dB5.j23DS2.d
W208DS2.eB5.j24DS2.e
W209DS2.fB5.j25DS2.f
W210DS2.gB5.j26DS2.g
W211DS3.aB6.j20DS3.a
W212DS3.bB6.j21DS3.b
W213DS3.cB6.j22DS3.c
W214DS3.dB6.j23DS3.d
W215DS3.eB6.j24DS3.e
W216DS3.fB6.j25DS3.f
W217DS3.gB6.j26DS3.g

8. Generic synthesizable SystemVerilog

rtl/serial_adder_gates.sv

Download

// Synthesizable generic design.

module serial_adder_gates
(
    input              clk,
    input              load,
    input        [3:0] a,
    input        [3:0] b,
    output       [4:0] result,
    output logic [6:0] seg_a,
    output logic [6:0] seg_b,
    output logic [6:0] seg_sum
);

    logic [7:0] a_shift, b_shift, collected;
    logic carry;
    wire serial_sum = a_shift [7] ^ b_shift [7] ^ carry;
    always_ff @ (posedge clk)
        if (load)
        begin
            a_shift <= { a [0], a [1], a [2], a [3], 4'b0 };
            b_shift <= { b [0], b [1], b [2], b [3], 4'b0 };
            carry   <= 1'b0;
        end
        else
        begin
            a_shift <= { a_shift [6:0], 1'b0 };
            b_shift <= { b_shift [6:0], 1'b0 };
            carry   <= (a_shift [7] & b_shift [7])
                        | ((a_shift [7] ^ b_shift [7]) & carry);
        end
    always_ff @ (posedge clk or posedge load)
        if (load)
            collected <= '0;
        else
            collected <= { collected [6:0], serial_sum };
    assign result = { collected [3], collected [4], collected [5],
                        collected [6], collected [7] };
    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'h7c;
            7: seg_a       = 7'h07;
            8: seg_a       = 7'h7f;
            9: seg_a       = 7'h67;
            10: seg_a      = 7'h00;
            11: seg_a      = 7'h00;
            12: seg_a      = 7'h00;
            13: seg_a      = 7'h00;
            14: seg_a      = 7'h00;
            15: seg_a      = 7'h00;
            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'h7c;
            7: seg_b       = 7'h07;
            8: seg_b       = 7'h7f;
            9: seg_b       = 7'h67;
            10: seg_b      = 7'h00;
            11: seg_b      = 7'h00;
            12: seg_b      = 7'h00;
            13: seg_b      = 7'h00;
            14: seg_b      = 7'h00;
            15: seg_b      = 7'h00;
            default: seg_b = '0;
        endcase
    always_comb
        case (result [3:0])
            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'h7c;
            7: seg_sum       = 7'h07;
            8: seg_sum       = 7'h7f;
            9: seg_sum       = 7'h67;
            10: seg_sum      = 7'h00;
            11: seg_sum      = 7'h00;
            12: seg_sum      = 7'h00;
            13: seg_sum      = 7'h00;
            14: seg_sum      = 7'h00;
            15: seg_sum      = 7'h00;
            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/cd4013b.sv

Download

// Ideal functional model. SET_TIED_LOW=1 is synthesizable with the
// supplied toolchain. General SET/RESET branch is a simulation model.
// SET and RESET simultaneously high is forbidden in this lesson.
// The model shows both outputs high then; release behavior is unspecified.

module cd4013b
# (
    parameter SET_TIED_LOW = 0
)
(
    input        p3_clk1,
    input        p4_rst1,
    input        p5_d1,
    input        p6_set1,
    input        p8_set2,
    input        p9_d2,
    input        p10_rst2,
    input        p11_clk2,
    output logic p1_q1,
    output       p2_qn1,
    output       p12_qn2,
    output logic p13_q2
);

    generate
        if (SET_TIED_LOW != 0)
        begin : reset_only
            always_ff @ (posedge p3_clk1 or posedge p4_rst1)
                if (p4_rst1)
                    p1_q1 <= 1'b0;
                else
                    p1_q1 <= p5_d1;

            assign p2_qn1 = ~ p1_q1;

            always_ff @ (posedge p11_clk2 or posedge p10_rst2)
                if (p10_rst2)
                    p13_q2 <= 1'b0;
                else
                    p13_q2 <= p9_d2;

            assign p12_qn2 = ~ p13_q2;

        end
        else
        begin : set_reset_model
            always_ff @ (posedge p3_clk1 or posedge p4_rst1 or posedge p6_set1)
                if (p6_set1)
                    p1_q1 <= 1'b1;
                else if (p4_rst1)
                    p1_q1 <= 1'b0;
                else
                    p1_q1 <= p5_d1;

            assign p2_qn1 = (p6_set1 & p4_rst1) | ~ p1_q1;

            always_ff @ (posedge p11_clk2 or posedge p10_rst2 or posedge p8_set2)
                if (p8_set2)
                    p13_q2 <= 1'b1;
                else if (p10_rst2)
                    p13_q2 <= 1'b0;
                else
                    p13_q2 <= p9_d2;

            assign p12_qn2 = (p8_set2 & p10_rst2) | ~ p13_q2;

        end
    endgenerate

endmodule
models/cd4014b.sv

Download

// Synthesizable ideal digital model; power and propagation delays omitted.

module cd4014b
(
    input  p1_d7,
    input  p4_d3,
    input  p5_d2,
    input  p6_d1,
    input  p7_d0,
    input  p9_load,
    input  p10_clk,
    input  p11_serial,
    input  p13_d4,
    input  p14_d5,
    input  p15_d6,
    output p2_q5,
    output p3_q7,
    output p12_q6
);

    logic [7:0] state;
    always_ff @ (posedge p10_clk)
        state <= p9_load ? { p1_d7, p15_d6, p14_d5, p13_d4, p4_d3, p5_d2, p6_d1, p7_d0 } : { state [6:0], p11_serial };
    assign p2_q5  = state [5];
    assign p12_q6 = state [6];
    assign p3_q7  = state [7];

endmodule
models/cd4015b.sv

Download

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

module cd4015b
(
    input  p1_clk_b,
    input  p6_rst_a,
    input  p7_d_a,
    input  p9_clk_a,
    input  p14_rst_b,
    input  p15_d_b,
    output p2_q4_b,
    output p3_q3_a,
    output p4_q2_a,
    output p5_q1_a,
    output p10_q4_a,
    output p11_q3_b,
    output p12_q2_b,
    output p13_q1_b
);

    logic [3:0] a, b;

    always_ff @ (posedge p9_clk_a or posedge p6_rst_a)
        if (p6_rst_a)
            a <= '0;
        else
            a <= { a [2:0], p7_d_a };

    always_ff @ (posedge p1_clk_b or posedge p14_rst_b)
        if (p14_rst_b)
            b <= '0;
        else
            b <= { b [2:0], p15_d_b };

    assign { p10_q4_a, p3_q3_a, p4_q2_a, p5_q1_a }   = a;
    assign { p2_q4_b, p11_q3_b, p12_q2_b, p13_q1_b } = b;

endmodule
models/cd4070b.sv

Download

// Synthesizable ideal digital model; power and propagation delays omitted.

module cd4070b
(
    input  p1_a1,
    input  p2_b1,
    input  p5_b2,
    input  p6_a2,
    input  p8_a3,
    input  p9_b3,
    input  p12_b4,
    input  p13_a4,
    output p3_y1,
    output p4_y2,
    output p10_y3,
    output p11_y4
);

    assign p3_y1  = p1_a1 ^ p2_b1;
    assign p4_y2  = p6_a2 ^ p5_b2;
    assign p10_y3 = p8_a3 ^ p9_b3;
    assign p11_y4 = p13_a4 ^ p12_b4;

endmodule
models/cd4071b.sv

Download

// Synthesizable ideal digital model; power and propagation delays omitted.

module cd4071b
(
    input  p1_a1,
    input  p2_b1,
    input  p5_b2,
    input  p6_a2,
    input  p8_a3,
    input  p9_b3,
    input  p12_b4,
    input  p13_a4,
    output p3_y1,
    output p4_y2,
    output p10_y3,
    output p11_y4
);

    assign p3_y1  = p1_a1 | p2_b1;
    assign p4_y2  = p6_a2 | p5_b2;
    assign p10_y3 = p8_a3 | p9_b3;
    assign p11_y4 = p13_a4 | p12_b4;

endmodule
models/cd4081b.sv

Download

// Synthesizable ideal digital model; power and propagation delays omitted.

module cd4081b
(
    input  p1_a1,
    input  p2_b1,
    input  p5_b2,
    input  p6_a2,
    input  p8_a3,
    input  p9_b3,
    input  p12_b4,
    input  p13_a4,
    output p3_y1,
    output p4_y2,
    output p10_y3,
    output p11_y4
);

    assign p3_y1  = p1_a1 & p2_b1;
    assign p4_y2  = p6_a2 & p5_b2;
    assign p10_y3 = p8_a3 & p9_b3;
    assign p11_y4 = p13_a4 & p12_b4;

endmodule
models/cd4511b.sv

Download

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

Download

// Pin connections are generated from the same netlist as the diagrams.
module serial_adder_gates_chips
(
    input              clk,
    input              load,
    input        [3:0] a,
    input        [3:0] b,
    output       [4:0] result,
    output       [6:0] seg_a,
    output       [6:0] seg_b,
    output       [6:0] seg_sum
);

    logic a_serial;
    logic b_serial;
    logic carry;
    logic n1;
    logic n2;
    logic n3;
    logic n4;
    logic serial_sum;

    cd4014b u1
    (
        .p1_d7        (a [0]),
        .p2_q5        (),
        .p3_q7        (a_serial),
        .p4_d3        (1'b0),
        .p5_d2        (1'b0),
        .p6_d1        (1'b0),
        .p7_d0        (1'b0),
        .p9_load      (load),
        .p10_clk      (clk),
        .p11_serial   (1'b0),
        .p12_q6       (),
        .p13_d4       (a [3]),
        .p14_d5       (a [2]),
        .p15_d6       (a [1])
    );

    cd4014b u2
    (
        .p1_d7        (b [0]),
        .p2_q5        (),
        .p3_q7        (b_serial),
        .p4_d3        (1'b0),
        .p5_d2        (1'b0),
        .p6_d1        (1'b0),
        .p7_d0        (1'b0),
        .p9_load      (load),
        .p10_clk      (clk),
        .p11_serial   (1'b0),
        .p12_q6       (),
        .p13_d4       (b [3]),
        .p14_d5       (b [2]),
        .p15_d6       (b [1])
    );

    cd4070b u3
    (
        .p1_a1        (a_serial),
        .p2_b1        (b_serial),
        .p3_y1        (n1),
        .p4_y2        (serial_sum),
        .p5_b2        (carry),
        .p6_a2        (n1),
        .p8_a3        (1'b0),
        .p9_b3        (1'b0),
        .p10_y3       (),
        .p11_y4       (),
        .p12_b4       (1'b0),
        .p13_a4       (1'b0)
    );

    cd4081b u4
    (
        .p1_a1        (a_serial),
        .p2_b1        (b_serial),
        .p3_y1        (n2),
        .p4_y2        (n3),
        .p5_b2        (carry),
        .p6_a2        (n1),
        .p8_a3        (1'b0),
        .p9_b3        (1'b0),
        .p10_y3       (),
        .p11_y4       (),
        .p12_b4       (1'b0),
        .p13_a4       (1'b0)
    );

    cd4071b u5
    (
        .p1_a1        (n2),
        .p2_b1        (n3),
        .p3_y1        (n4),
        .p4_y2        (),
        .p5_b2        (1'b0),
        .p6_a2        (1'b0),
        .p8_a3        (1'b0),
        .p9_b3        (1'b0),
        .p10_y3       (),
        .p11_y4       (),
        .p12_b4       (1'b0),
        .p13_a4       (1'b0)
    );

    cd4013b # (.SET_TIED_LOW (1)) u6
    (
        .p1_q1        (carry),
        .p2_qn1       (),
        .p3_clk1      (clk),
        .p4_rst1      (load),
        .p5_d1        (n4),
        .p6_set1      (1'b0),
        .p8_set2      (1'b0),
        .p9_d2        (1'b0),
        .p10_rst2     (1'b0),
        .p11_clk2     (1'b0),
        .p12_qn2      (),
        .p13_q2       ()
    );

    cd4015b u7
    (
        .p1_clk_b     (clk),
        .p2_q4_b      (result [0]),
        .p3_q3_a      (),
        .p4_q2_a      (),
        .p5_q1_a      (),
        .p6_rst_a     (load),
        .p7_d_a       (serial_sum),
        .p9_clk_a     (clk),
        .p10_q4_a     (result [4]),
        .p11_q3_b     (result [1]),
        .p12_q2_b     (result [2]),
        .p13_q1_b     (result [3]),
        .p14_rst_b    (load),
        .p15_d_b      (result [4])
    );

    cd4511b # (.TRANSPARENT (1)) u8
    (
        .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)) u9
    (
        .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)) u10
    (
        .p1_b         (result [1]),
        .p2_c         (result [2]),
        .p3_lt_n      (1'b1),
        .p4_bi_n      (1'b1),
        .p5_le        (1'b0),
        .p6_d         (result [3]),
        .p7_a         (result [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 = 2304;
    logic [60:0] vectors [0:vector_count-1];
    logic [25:0] expected, check_mask;
    logic clk = 1'b0;

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

    logic load    = '0;
    logic [3:0] a = '0;
    logic [3:0] b = '0;
    logic [4:0] result_rtl;
    logic [4:0] result_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;

    serial_adder_gates dut_rtl
    (
        .clk          (clk),
        .load         (load),
        .a            (a),
        .b            (b),
        .result       (result_rtl),
        .seg_a        (seg_a_rtl),
        .seg_b        (seg_b_rtl),
        .seg_sum      (seg_sum_rtl)
    );

    serial_adder_gates_chips dut_chips
    (
        .clk          (clk),
        .load         (load),
        .a            (a),
        .b            (b),
        .result       (result_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
            load       = vectors [i] [0 +: 1];
            a          = vectors [i] [1 +: 4];
            b          = vectors [i] [5 +: 4];
            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, result_rtl } & check_mask) !== (expected & check_mask))
                $fatal (1, "serial_adder_gates_rtl vector %0d got=%h expected=%h mask=%h", i, { seg_sum_rtl, seg_b_rtl, seg_a_rtl, result_rtl }, expected, check_mask);
            if (({ seg_sum_chips, seg_b_chips, seg_a_chips, result_chips } & check_mask) !== (expected & check_mask))
                $fatal (1, "serial_adder_gates_chips vector %0d got=%h expected=%h mask=%h", i, { seg_sum_chips, seg_b_chips, seg_a_chips, result_chips }, expected, check_mask);
        end
        $display ("PASS serial_adder_gates: 2304 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 i_load    = data [0 +: 1];
    wire [3:0] i_a = data [1 +: 4];
    wire [3:0] i_b = data [5 +: 4];
    logic [4:0] o_result;
    logic [6:0] o_seg_a;
    logic [6:0] o_seg_b;
    logic [6:0] o_seg_sum;
    serial_adder_gates reference_core
    (
        .clk          (clk),
        .load         (i_load),
        .a            (i_a),
        .b            (i_b),
        .result       (o_result),
        .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_result };
    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_serial_adder_gates # (.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_serial_adder_gates # (.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/.

2304 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
loaddata[0:0]
adata[4:1]
bdata[8:5]
resultresult[4:0]
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 io_load    = data [0 +: 1];
    wire [3:0] io_a = data [1 +: 4];
    wire [3:0] io_b = data [5 +: 4];
    logic [4:0] io_result;
    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
            serial_adder_gates dut
            (
                .clk          (clk),
                .load         (io_load),
                .a            (io_a),
                .b            (io_b),
                .result       (io_result),
                .seg_a        (io_seg_a),
                .seg_b        (io_seg_b),
                .seg_sum      (io_seg_sum)
            );
        end
        else
        begin : physical_design
            serial_adder_gates_chips dut
            (
                .clk          (clk),
                .load         (io_load),
                .a            (io_a),
                .b            (io_b),
                .result       (io_result),
                .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_result } };
    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_serial_adder_gates. 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_serial_adder_gates
# (
    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

Run 3+4, 9+1, 15+1 and 15+15. Record each serial SUM bit before its sampling edge and reconstruct the result. Reassert LOAD before every new word.

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