Embedded Systems Spring 2024
Quiz 3
Mason Brady
Email: mrbrady1@fortlewis.edu

Quiz 3:

I wrote the code so that the timer would only increment when the button up was pressed and it would reset when button down was pressed. I considered using a toggle or the debounce but both just added complexity with no benefit that I saw. The button worked just fine even without the debounce. If you had worse buttons the debounce is necessary. The code is pasted below.

module SSDisp(input clk, input btnU, input btnD, output reg [6:0] g_to_a, output reg [3:0] an);
    reg state = 1'b0;
    parameter cntmax = 32'd100000000;
    reg [31:0] cnt;
    reg[3:0] digit = 4'd0;
    parameter digitMax = 4'd9;
    always @(posedge clk) begin
        an = 4'b1110;
        if(btnU) begin
            if (cnt == cntmax) begin
                if(digit < digitMax) digit = digit + 1;
                else digit = 4'd0;
                cnt = 32'd0;
            else if (cnt < cntmax) cnt = cnt + 1;
        else if (btnD) digit = 10'd0;
            0:g_to_a = 7'b1000000;
            1:g_to_a = 7'b1111001;
            2:g_to_a = 7'b0100100;
            3:g_to_a = 7'b0110000;
            4:g_to_a = 7'b0011001;
            5:g_to_a = 7'b0010010;
            6:g_to_a = 7'b0000010;
            7:g_to_a = 7'b1111000;
            8:g_to_a = 7'b0000000;
            9:g_to_a = 7'b0011000;
            default: g_to_a = 7'b0000000;

For the test bench I just used the default setup and wired btnU to btnU and btnD to btnD g_to_a went to seg and an obviously went to an

The demo is below: