`timescale 1ns/1ps // ECE 287 - Exercise 2 testbench: draw every digit the decoder makes. // Paste this into the LEFT pane (testbench.sv) on EDA Playground. // // The log draws each output as a little seven-segment picture. // Questions to answer from the log: // 1. A segment is drawn when its bit is 0, not 1. Why would the board // be wired that way? (Look up "active low".) // 2. Do all 16 pictures look like the digit they should be? // 3. Our random number is 8 bits. How many of these decoders will you // need to show it in decimal, and what values will each one see? // // In EPWave (it opens empty): Get Signals -> scope tb -> select i and o -> // Append Selected. There is no clock here. When does o change compared with i? module tb; reg [3:0] i; wire [6:0] o; integer k; // one row of a seven-segment digit as 3 characters of ASCII art. // The segments are active low: a 0 bit draws, a 1 bit is blank. // row 0: _ segment 0 // row 1: |_| segments 5, 6, 1 // row 2: |_| segments 4, 3, 2 function [23:0] seg_row(input [6:0] s, input [1:0] row); case (row) 2'd0: seg_row = {" ", (s[0] ? " " : "_"), " "}; 2'd1: seg_row = {(s[5] ? " " : "|"), (s[6] ? " " : "_"), (s[1] ? " " : "|")}; 2'd2: seg_row = {(s[4] ? " " : "|"), (s[3] ? " " : "_"), (s[2] ? " " : "|")}; default: seg_row = " "; endcase endfunction seven_segment dut(.i(i), .o(o)); // From Exercise 1, not instantiated here. design.sv still has the lfsr // module; the instance stays commented out until the challenge. // lfsr dut_lfsr(.clk(clk), .rst(rst), .seed(seed), .en_seed(en_seed), .number(number)); initial begin $dumpfile("dump.vcd"); $dumpvars(0, tb); for (k = 0; k < 16; k = k + 1) begin i = k; #10; $display("input %h -> o = %b (segments 6543210)", i, o); $display(" %s", seg_row(o, 2'd0)); $display(" %s", seg_row(o, 2'd1)); $display(" %s", seg_row(o, 2'd2)); $display(""); end $finish; end endmodule