+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Member level 2
    Points: 683, Level: 5

    Join Date
    Apr 2018
    Posts
    50
    Helped
    0 / 0
    Points
    683
    Level
    5

    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

    •   AltAdvertisement

        
       

  2. #2
    Advanced Member level 3
    Points: 7,012, Level: 19

    Join Date
    Feb 2014
    Posts
    998
    Helped
    349 / 349
    Points
    7,012
    Level
    19

    Re: Stopping a countdown timer from 9-0.

    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.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #3
    Full Member level 2
    Points: 2,304, Level: 11
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    128
    Helped
    13 / 13
    Points
    2,304
    Level
    11

    Re: Stopping a countdown timer from 9-0.

    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 by BlackHelicopter; 27th February 2020 at 03:48.



--[[ ]]--