Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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

 

asdf44

Advanced Member level 3
Joined
Feb 15, 2014
Messages
999
Helped
355
Reputation
710
Reaction score
343
Trophy points
1,363
Activity points
9,697
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.
 

BlackHelicopter

Full Member level 2
Joined
Jun 3, 2010
Messages
128
Helped
13
Reputation
26
Reaction score
13
Trophy points
1,298
Activity points
2,159
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.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top