如何将按钮计数器与倒数秒表(完成的按钮计数器)结合使用

时间:2019-05-30 16:11:56

标签: verilog

我不知道如何结合计数器和秒表。

我尝试下面的代码,但是当我启动秒表时它变为0。 我希望它每秒显示一次减少。

always @(posedge  clk)begin

    if ( n_reset == 0)begin
        counter <= 0;//unit digit
        counter2 <= 0;//ten digit
    end
    else if (level_out == 1)
        if (counter  < 9)
            counter <= counter +1;
        else begin
            counter <= 0;
            counter2 <= counter2 + 1;
        end
    else if(D_count==1)begin//stop watch can not work in expected
        if (counter >0)
            counter <= counter - 1;
        else if(counter == 0 && counter2 > 0)begin
            counter <= 9;
            counter2 <= counter2 - 1;
        end 
        else if(counter==0 && counter2 == 0)begin
            counter <= 0;
            counter2 <= 0;
        end
    end   
end

0 个答案:

没有答案