Dr. Peter Andrew Jamieson — Academic in an information evolution

← Back to A Random Number Every Second

design.sv

· Download design.sv · Download both files (.zip)

`timescale 1ns/1ps
// ECE 287 - Simple Sequential Design
// Exercise 2: the seven-segment decoder from the slides (unchanged).
// Paste this into the RIGHT pane (design.sv) on EDA Playground.
//
// This file builds up the big design one piece at a time. Modules from
// earlier exercises are kept here, complete, but nothing instantiates them
// yet (their instantiations are commented out in testbench.sv). In the
// challenge, your top level instantiates all of them.


// ---------------------------------------------------------------------------
// From Exercise 1: LFSR (not instantiated in this exercise)
// ---------------------------------------------------------------------------
module lfsr(	input clk,
		input rst,
		input [7:0]seed,
		input en_seed,
		output reg [7:0]number);

always @(posedge clk or negedge rst)
begin
	if (rst == 1'b0)
	begin
		number <= 8'd0;
	end
	else
	begin
		if (en_seed == 1'b1)
		   number <= seed;
		else
		   number <= {number[6], number[5]^number[4], number[4], number[3], number[2], number[1], number[0], number[7]^number[2]};
	end
end

endmodule


// ---------------------------------------------------------------------------
// NEW in Exercise 2: seven-segment decoder
// ---------------------------------------------------------------------------
module seven_segment(
	input wire[3:0]i,
	output reg[6:0]o
);

// HEX out - rewire DE1
//  ---0---
// |       |
// 5       1
// |       |
//  ---6---
// |       |
// 4       2
// |       |
//  ---3---

always @(*)
begin
	case (i)	    // 6543210
		4'h0: o = 7'b1000000;
		4'h1: o = 7'b1111001;
		4'h2: o = 7'b0100100;
		4'h3: o = 7'b0110000;
		4'h4: o = 7'b0011001;
		4'h5: o = 7'b0010010;
		4'h6: o = 7'b0000010;
		4'h7: o = 7'b1111000;
		4'h8: o = 7'b0000000;
		4'h9: o = 7'b0010000;
		4'ha: o = 7'b0001000;
		4'hb: o = 7'b0000011;
		4'hc: o = 7'b1000110;
		4'hd: o = 7'b0100001;
		4'he: o = 7'b0000110;
		4'hf: o = 7'b0001110;
	endcase
end

endmodule