Feb 25, 2020 #1 chandlerbing65nm Member level 5 Joined Apr 5, 2018 Messages 80 Helped 0 Reputation 0 Reaction score 1 Trophy points 8 Activity points 709 Stopping a countdown timer from 9-0 displayed in 7-segment Hi folks, I can't stop the countdown timer displayed in 7-segment. It is supposed to stop or latch when it reached "0" in 7-segment display. I don't know what code can I write to make it stop/latch. The countdown timer starts from "9" down to "0". It remains in-loop there, 9-0. Here is code. Code Verilog - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 module countdowntimer(SEG,reset,clk); reg [32:0] counter; input reset; input clk; output [6:0] SEG; reg [6:0] oSEG; //initial begin //end always @(posedge clk, posedge reset) begin if(reset) begin counter <= 500000000; oSEG <= 7'b1000000; end else begin if (counter == 0) begin counter <= 500000000; end else begin counter <= counter-1'b1; //oSEG <= 7'b0; case(counter) 450000000: oSEG <= 7'b0011000;//9 400000000: oSEG <= 7'b0000000;//8 350000000: oSEG <= 7'b1111000;//7 300000000: oSEG <= 7'b0000010;//6 250000000: oSEG <= 7'b0010010;//5 200000000: oSEG <= 7'b0011001;//4 150000000: oSEG <= 7'b0110000;//3 100000000: oSEG <= 7'b0100100;//2 50000000: oSEG <= 7'b1111001; //1 1000: oSEG <= 7'b1000000; //0 endcase end end end assign SEG = oSEG; endmodule
Stopping a countdown timer from 9-0 displayed in 7-segment Hi folks, I can't stop the countdown timer displayed in 7-segment. It is supposed to stop or latch when it reached "0" in 7-segment display. I don't know what code can I write to make it stop/latch. The countdown timer starts from "9" down to "0". It remains in-loop there, 9-0. Here is code. Code Verilog - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 module countdowntimer(SEG,reset,clk); reg [32:0] counter; input reset; input clk; output [6:0] SEG; reg [6:0] oSEG; //initial begin //end always @(posedge clk, posedge reset) begin if(reset) begin counter <= 500000000; oSEG <= 7'b1000000; end else begin if (counter == 0) begin counter <= 500000000; end else begin counter <= counter-1'b1; //oSEG <= 7'b0; case(counter) 450000000: oSEG <= 7'b0011000;//9 400000000: oSEG <= 7'b0000000;//8 350000000: oSEG <= 7'b1111000;//7 300000000: oSEG <= 7'b0000010;//6 250000000: oSEG <= 7'b0010010;//5 200000000: oSEG <= 7'b0011001;//4 150000000: oSEG <= 7'b0110000;//3 100000000: oSEG <= 7'b0100100;//2 50000000: oSEG <= 7'b1111001; //1 1000: oSEG <= 7'b1000000; //0 endcase end end end assign SEG = oSEG; endmodule
Feb 25, 2020 #2 A asdf44 Advanced Member level 4 Joined Feb 15, 2014 Messages 1,000 Helped 355 Reputation 710 Reaction score 344 Trophy points 1,363 Activity points 9,716 Code: if (counter == 0) begin counter <= 500000000; That resets the counter every time it reaches zero. Remove that and it should count once after being reset.
Code: if (counter == 0) begin counter <= 500000000; That resets the counter every time it reaches zero. Remove that and it should count once after being reset.
Feb 27, 2020 #3 B BlackHelicopter Full Member level 2 Joined Jun 3, 2010 Messages 137 Helped 13 Reputation 26 Reaction score 16 Trophy points 1,298 Activity points 2,207 Also change to this Code: if (counter > 0) begin counter <= counter-1'b1; //oSEG <= 7'b0; case(counter) The counter will then stop at 0 after counting down. Last edited: Feb 27, 2020
Also change to this Code: if (counter > 0) begin counter <= counter-1'b1; //oSEG <= 7'b0; case(counter) The counter will then stop at 0 after counting down.