[SOLVED] Stopping a countdown timer from 9-0.

Status
Not open for further replies.

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

 

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.
 
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:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…