diff options
Diffstat (limited to 'Countdown.v')
-rw-r--r-- | Countdown.v | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/Countdown.v b/Countdown.v index 78e4162..a8c7506 100644 --- a/Countdown.v +++ b/Countdown.v @@ -23,35 +23,43 @@ module Countdown( input rst, input start, input [7:0] init, - output [7:0] t + output [7:0] t,
+ output running ); reg [7:0] t; -reg running = 0; +reg running = 0;
+reg [7:0] count;
+
+always @(posedge clk_1hz or posedge rst) begin
+ if (rst)
+ count <= 0;
+ else if (running)
+ count <= count + 1;
+ else
+ count <= 0;
+end
-always @(init) begin - if (!running) begin - t = init; - end else begin - t = t; - end -end - -always @(posedge clk_1hz) begin - if (running) begin - t <= t - 1; - end else begin - t <= init; - end -end +always @(posedge clk_1hz or posedge rst) begin
+
+ if (rst)
+ t <= 0;
+ else //if (running)
+ t <= init - count;
-always @(posedge start) begin - running = 1; end -always @(rst) begin - running = 0; - t = 0; +always @(posedge start or posedge rst) begin
+
+ if (rst)
+ running <= 0;
+ else if (count == init) begin
+ running <= 0;
+ end else if (start)
+ running <= 1;
+ else
+ running <= running;
+ end endmodule |