From 11a0ed5a6e8af2e224caf1cb782829dfd8737b5e Mon Sep 17 00:00:00 2001 From: Michael Abed Date: Thu, 22 Mar 2012 16:14:11 -0400 Subject: updates --- Countdown.v | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'Countdown.v') 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 -- cgit v1.2.3