summaryrefslogtreecommitdiff
path: root/Countdown.v
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-03-22 16:14:11 -0400
committerMichael Abed <michaelabed@gmail.com>2012-03-22 16:14:11 -0400
commit11a0ed5a6e8af2e224caf1cb782829dfd8737b5e (patch)
tree5c7aa13704d69357887328db7c4926be76858c72 /Countdown.v
parentbab97470acd4dd09ef19b669ff6c6f933aece0f8 (diff)
downloadec311-lab4-11a0ed5a6e8af2e224caf1cb782829dfd8737b5e.tar.gz
ec311-lab4-11a0ed5a6e8af2e224caf1cb782829dfd8737b5e.tar.bz2
ec311-lab4-11a0ed5a6e8af2e224caf1cb782829dfd8737b5e.zip
updates
Diffstat (limited to 'Countdown.v')
-rw-r--r--Countdown.v52
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