Hello all!
So I just started learning Verilog this semester, and I have coded a 4 bit counter to run on LEDs. The counter works great. The only problem is that the reset button does not work as anticipated. When I flip the reset switch, the counter simply stops on whichever number it is currently on. It is meant to set the count to 0 and reset the timer.
Does anyone know what I did wrong? Thank you!
Code below:
# This is my slow clock module. Not rly sure why I need the reset in here, but I am just following examples that I found online.
`timescale 1ns / 1ps
module slowClock(clk, reset, clk_1Hz);
input clk, reset;
output clk_1Hz;
reg clk_1Hz = 1'b0;
reg [27:0] counter;
always@(posedge reset or posedge clk)
begin
if (reset == 1'b1)
begin
clk_1Hz <= 0;
counter <= 0;
end
else
begin
counter <= counter + 1;
if ( counter == 25_000_000)
begin
counter <= 0;
clk_1Hz <= ~clk_1Hz;
end
end
end
endmodule
# This is my counter module
`timescale 1ns / 1ps
module fourbitcounter(Q, clk, reset);
input clk, reset; // Declare the inputs as the clock and reset
output [3:0] Q; // Declare the outputs as 4 bit Q
reg [3:0] Q; // Declare Q as a variable
wire clk_1Hz; // Declare the slow clock as a wire
slowClock clock_generator(clk, reset, clk_1Hz); //Instatiate the slow clock
always@(posedge clk_1Hz) // Check for the rising edge of the slow clock
begin
if (reset == 1) // If the reset is high, set the output to 0
Q <= 4'b0000; // Not sure why it isn't setting the value to 0 when timer is high
else // Otherwise, increment the 4 bit Q by 1
Q <= Q + 4'b1;
end
endmodule