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

Decoded decade counter

1. Purpose and prerequisites

Follow the single active output through Q0–Q9; reset to Q0.

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

RESET selects Q0. COUT is high in states 0…4 and low in 5…9; it is a divide-by-ten waveform, not a one-cycle overflow pulse. Change INHIBIT only while CLK is low.

PortDirectionBits
clkinput1
rstinput1
inhibitinput1
qoutput10
carryoutput1
Decoded decade counter · states
SVG · PNG
Decoded decade counter · timing
SVG · PNG

3. Parts you need

PartQuantityLSSK row
CD4017B · DIP137
830-contact breadboard145
5 V regulated power module156
USB-to-9 V cable to regulator input157
Qualified button channels (sets of five)266
Assembled 555 clock module154
5 V current-limited LED1146
M–M jumper870
External-module lead (M–F assumed)3371

CSV · Jumper schedule · Pin/net data

Counts describe this exact layout, without spare jumpers. The button quantity counts independent channels: buy 1 sets of five if using that source listing. Qualify the module’s 0/5 V output and built-in bias first; a bare switch is not equivalent. External connector genders and shared module power terminals must be adapted to the actual part.

4. Chip functions, pins and polarity

CD4017B

Modulo-10 decoded counter · Manufacturer datasheet

PinSignalType
1q5output
2q1output
3q0output
4q2output
5q6output
6q7output
7q3output
8vsssupply
9q8output
10q4output
11q9output
12carryoutput
13inhibitinput
14clockinput
15resetinput
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

Decoded decade counter · 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

Decoded decade counter · connections
SVG · PNG
DevicePinSignalNet
U11q5q[5]
U12q1q[1]
U13q0q[0]
U14q2q[2]
U15q6q[6]
U16q7q[7]
U17q3q[3]
U18vssGND
U19q8q[8]
U110q4q[4]
U111q9q[9]
U112carrycarry
U113inhibitinhibit
U114clockclk
U115resetrst
U116vdd+5V

7. Schematic 3 · Breadboard and assembly

Decoded decade counter · 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. Reset, count twelve edges, then inhibit for two edges and resume. Check Q9→Q0 and both COUT transitions.

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
W007q[5]B1.j5L6.A
W008q[1]B1.j6L2.A
W009q[0]B1.j7L1.A
W010q[2]B1.j8L3.A
W011q[6]B1.j9L7.A
W012q[7]B1.j10L8.A
W013q[3]B1.j11L4.A
W014GNDB1.j12B1.BG2
W015GNDS1.GNDB1.BG3
W016GNDS2.GNDB1.BG4
W017GNDCLK.GNDB1.BG5
W018GNDPWR.GNDB1.BG6
W019GNDL1.KB1.BG7
W020GNDL2.KB1.BG8
W021GNDL3.KB1.BG9
W022GNDL4.KB1.BG10
W023GNDL5.KB1.BG11
W024GNDL6.KB1.BG12
W025GNDL7.KB1.BG13
W026GNDL8.KB1.BG14
W027GNDL9.KB1.BG15
W028GNDL10.KB1.BG16
W029GNDL11.KB1.BG17
W030q[8]B1.a12L9.A
W031q[4]B1.a11L5.A
W032q[9]B1.a10L10.A
W033carryB1.a9L11.A
W034inhibitB1.a8S2.OUT
W035clkB1.a7CLK.OUT
W036rstB1.a6S1.OUT
W037+5VB1.a5B1.TP2
W038+5VS1.VCCB1.BP2
W039+5VS2.VCCB1.BP3
W040+5VCLK.VCCB1.BP4
W041+5VPWR.+5VB1.BP5

8. Generic synthesizable SystemVerilog

rtl/decade_counter.sv

Download

// Synthesizable generic design.

module decade_counter
(
    input              clk,
    input              rst,
    input              inhibit,
    output       [9:0] q,
    output             carry
);

    logic [3:0] state;
    always_ff @ (posedge clk or posedge rst)
        if (rst)
            state <= '0;
        else if (~ inhibit)
            state <= state == 4'd9 ? 4'd0 : state + 1'b1;
    assign q     = 10'b1 << state;
    assign carry = state < 4'd5;

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

Download

// Synthesizable ideal digital model; power and propagation delays omitted.
// INHIBIT is a stable enable; clocking through its falling edge is outside this model.

module cd4017b
(
    input  p13_inhibit,
    input  p14_clock,
    input  p15_reset,
    output p1_q5,
    output p2_q1,
    output p3_q0,
    output p4_q2,
    output p5_q6,
    output p6_q7,
    output p7_q3,
    output p9_q8,
    output p10_q4,
    output p11_q9,
    output p12_carry
);

    logic [3:0] state;
    always_ff @ (posedge p14_clock or posedge p15_reset)
        if (p15_reset)
            state <= '0;
        else if (~ p13_inhibit)
            state <= state == 4'd9 ? 4'd0 : state + 1'b1;
    assign p3_q0     = state == 4'd0;
    assign p2_q1     = state == 4'd1;
    assign p4_q2     = state == 4'd2;
    assign p7_q3     = state == 4'd3;
    assign p10_q4    = state == 4'd4;
    assign p1_q5     = state == 4'd5;
    assign p5_q6     = state == 4'd6;
    assign p6_q7     = state == 4'd7;
    assign p9_q8     = state == 4'd8;
    assign p11_q9    = state == 4'd9;
    assign p12_carry = state < 4'd5;

endmodule

10. Pin-connected SystemVerilog

rtl/decade_counter_chips.sv

Download

// Pin connections are generated from the same netlist as the diagrams.
module decade_counter_chips
(
    input              clk,
    input              rst,
    input              inhibit,
    output       [9:0] q,
    output             carry
);


    cd4017b u1
    (
        .p1_q5        (q [5]),
        .p2_q1        (q [1]),
        .p3_q0        (q [0]),
        .p4_q2        (q [2]),
        .p5_q6        (q [6]),
        .p6_q7        (q [7]),
        .p7_q3        (q [3]),
        .p9_q8        (q [8]),
        .p10_q4       (q [4]),
        .p11_q9       (q [9]),
        .p12_carry    (carry),
        .p13_inhibit  (inhibit),
        .p14_clock    (clk),
        .p15_reset    (rst)
    );

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 = 200;
    logic [23:0] vectors [0:vector_count-1];
    logic [10:0] expected, check_mask;
    logic clk = 1'b0;

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

    logic rst     = '0;
    logic inhibit = '0;
    logic [9:0] q_rtl;
    logic [9:0] q_chips;
    logic carry_rtl;
    logic carry_chips;

    decade_counter dut_rtl
    (
        .clk          (clk),
        .rst          (rst),
        .inhibit      (inhibit),
        .q            (q_rtl),
        .carry        (carry_rtl)
    );

    decade_counter_chips dut_chips
    (
        .clk          (clk),
        .rst          (rst),
        .inhibit      (inhibit),
        .q            (q_chips),
        .carry        (carry_chips)
    );

    initial
    begin
        $readmemh ("vectors.hex", vectors);
        @ (posedge clk);
        # 1;
        for (int i = 0; i < vector_count; i ++)
        begin
            rst        = vectors [i] [0 +: 1];
            inhibit    = vectors [i] [1 +: 1];
            expected   = vectors [i] [2 +: 11];
            check_mask = vectors [i] [13 +: 11];
            @ (posedge clk);
            # 1;  // Allow nonblocking state and combinational outputs to settle.
            if (({ carry_rtl, q_rtl } & check_mask) !== (expected & check_mask))
                $fatal (1, "decade_counter_rtl vector %0d got=%h expected=%h mask=%h", i, { carry_rtl, q_rtl }, expected, check_mask);
            if (({ carry_chips, q_chips } & check_mask) !== (expected & check_mask))
                $fatal (1, "decade_counter_chips vector %0d got=%h expected=%h mask=%h", i, { carry_chips, q_chips }, expected, check_mask);
        end
        $display ("PASS decade_counter: 200 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_inhibit = data [0 +: 1];
    logic [9:0] o_q;
    logic o_carry;
    decade_counter reference_core
    (
        .clk          (clk),
        .rst          (rst),
        .inhibit      (i_inhibit),
        .q            (o_q),
        .carry        (o_carry)
    );
    assign reference_result = { 21'b0, o_carry, o_q };
    always_comb
        case (reference_result [3:0])
            0: hex_digit       = 7'h3f;
            1: hex_digit       = 7'h06;
            2: hex_digit       = 7'h5b;
            3: hex_digit       = 7'h4f;
            4: hex_digit       = 7'h66;
            5: hex_digit       = 7'h6d;
            6: hex_digit       = 7'h7d;
            7: hex_digit       = 7'h07;
            8: hex_digit       = 7'h7f;
            9: hex_digit       = 7'h67;
            10: hex_digit      = 7'h77;
            11: hex_digit      = 7'h7c;
            12: hex_digit      = 7'h39;
            13: hex_digit      = 7'h5e;
            14: hex_digit      = 7'h79;
            15: hex_digit      = 7'h71;
            default: hex_digit = '0;
        endcase
    assign reference_segments = { 14'b0, hex_digit };
    lab_top # (.SCAN_BITS (4)) lab
    (
        .clk          (clk),
        .slow_clk     (clk),
        .rst          (rst),
        .key          (4'b0),
        .sw           (data [7:0]),
        .led          (lab_led),
        .abcdefgh     (lab_seg),
        .digit        (lab_digit),
        .x            (10'b0),
        .y            (9'b0),
        .red          (),
        .green        (),
        .blue         (),
        .mic          (24'b0),
        .sound        (),
        .uart_rx      (1'b1),
        .uart_tx      (),
        .gpio         (lab_gpio)
    );
    hackathon_top # (.SCAN_BITS (4), .UPPER_INPUTS (4'ha)) hack
    (
        .clock        (clk),
        .slow_clock   (clk),
        .reset        (rst),
        .key          (data [7:0]),
        .led          (hack_led),
        .abcdefgh     (hack_seg),
        .digit        (hack_digit),
        .x            (10'b0),
        .y            (9'b0),
        .red          (),
        .green        (),
        .blue         (),
        .gpio         (hack_gpio)
    );
    for (genvar v = 0; v < 4; v ++)
    begin : views
        tt_um_decade_counter # (.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_decade_counter # (.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/.

200 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
inhibitdata[0:0]
qresult[9:0]
carryresult[10:10]
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_inhibit = data [0 +: 1];
    logic [9:0] io_q;
    logic io_carry;
    generate
        if (CHIP_MODEL == 0)
        begin : generic_design
            decade_counter dut
            (
                .clk          (clk),
                .rst          (rst),
                .inhibit      (io_inhibit),
                .q            (io_q),
                .carry        (io_carry)
            );
        end
        else
        begin : physical_design
            decade_counter_chips dut
            (
                .clk          (clk),
                .rst          (rst),
                .inhibit      (io_inhibit),
                .q            (io_q),
                .carry        (io_carry)
            );
        end
    endgenerate
    assign result = { 21'b0, { io_carry, io_q } };
    logic [6:0] digit_zero;
    always_comb
        case (result [3:0])
            0: digit_zero       = 7'h3f;
            1: digit_zero       = 7'h06;
            2: digit_zero       = 7'h5b;
            3: digit_zero       = 7'h4f;
            4: digit_zero       = 7'h66;
            5: digit_zero       = 7'h6d;
            6: digit_zero       = 7'h7d;
            7: digit_zero       = 7'h07;
            8: digit_zero       = 7'h7f;
            9: digit_zero       = 7'h67;
            10: digit_zero      = 7'h77;
            11: digit_zero      = 7'h7c;
            12: digit_zero      = 7'h39;
            13: digit_zero      = 7'h5e;
            14: digit_zero      = 7'h79;
            15: digit_zero      = 7'h71;
            default: digit_zero = '0;
        endcase
    assign segments = { 14'b0, digit_zero };
endmodule
integration/lab_top.sv

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_decade_counter. 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_decade_counter
# (
    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

Reset, count twelve edges, then inhibit for two edges and resume. Check Q9→Q0 and both COUT transitions.

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