summaryrefslogtreecommitdiff
path: root/Countdown.v
diff options
context:
space:
mode:
Diffstat (limited to 'Countdown.v')
-rw-r--r--Countdown.v57
1 files changed, 57 insertions, 0 deletions
diff --git a/Countdown.v b/Countdown.v
new file mode 100644
index 0000000..78e4162
--- /dev/null
+++ b/Countdown.v
@@ -0,0 +1,57 @@
+`timescale 1ns / 1ps
+//////////////////////////////////////////////////////////////////////////////////
+// Company:
+// Engineer:
+//
+// Create Date: 14:51:02 03/16/2012
+// Design Name:
+// Module Name: Countdown
+// Project Name:
+// Target Devices:
+// Tool versions:
+// Description:
+//
+// Dependencies:
+//
+// Revision:
+// Revision 0.01 - File Created
+// Additional Comments:
+//
+//////////////////////////////////////////////////////////////////////////////////
+module Countdown(
+ input clk_1hz,
+ input rst,
+ input start,
+ input [7:0] init,
+ output [7:0] t
+ );
+
+reg [7:0] t;
+reg running = 0;
+
+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 start) begin
+ running = 1;
+end
+
+always @(rst) begin
+ running = 0;
+ t = 0;
+end
+
+endmodule