piratecoug
Newbie level 3
Hi,
I'm making a stopwatch on a Nexys4 and I'm having trouble with one part. I can start, stop, and reset the stopwatch, but I cannot figure out how to get it to increment by 1 bit. So if the stopwatch is stopped at 1:021, when I hit the increment button the output would be 1:022. Currently, when I hit the increment button, it will increment a random amount, and I assume this is because it is being pushed over multiple clock edges. How do I just do 1 bit increment no matter how long I hold the button for?
Here is a snippet of my code for my counter:
Cen is coming from the state machine, where Cen = 2'b01 means start counting. Inc is also coming from the state machine.
I'm making a stopwatch on a Nexys4 and I'm having trouble with one part. I can start, stop, and reset the stopwatch, but I cannot figure out how to get it to increment by 1 bit. So if the stopwatch is stopped at 1:021, when I hit the increment button the output would be 1:022. Currently, when I hit the increment button, it will increment a random amount, and I assume this is because it is being pushed over multiple clock edges. How do I just do 1 bit increment no matter how long I hold the button for?
Here is a snippet of my code for my counter:
Cen is coming from the state machine, where Cen = 2'b01 means start counting. Inc is also coming from the state machine.
Code:
always @ (posedge (clk), posedge(rst))//, posedge(inc))
begin
if (rst == 1'b1)begin
Dig0 <= 4'b0000;
Dig1 <= 4'b0000;
Dig2 <= 4'b0000;
Dig3 <= 4'b0000;
end
//increment if inc
else if(inc == 1'b1)// && Dig3 < 4'b1001)begin
begin
if (enable == 1'b1)
begin
Dig0 <= Dig0 + 4'b0001;
enable = 1'b0;
end
end
//only continue if Cen is 01 & not inc
else if(Cen == 2'b01)begin
//add 1 to first digit up till 9
Dig0 <= Dig0 + 1'b1;
//reset if == 10
if(Dig0 > 4'b1001)begin
Dig0 <= 4'b0000;
//add 1 to second digit (when first resets) up till 9
Dig1 <= Dig1 + 1'b1;
end
//reset if == 10
if(Dig1 == 4'b1010)begin
Dig1 <= 4'b0000;
//add 1 to third digit (when second reset) up till 9
Dig2 <= Dig2 + 1'b1;
end
//reset if == 10
if(Dig2 == 4'b1010)begin
Dig2 <= 4'b0000;
//add 1 to fourth digit (when third reset) up till 9
Dig3 <= Dig3 + 1'b1;
end
//reset if == 10
if(Dig3 > 4'b1001)begin
Dig3 <= 4'b0000;
end
end