From 5ebded9372f7d9ac6b295084df8baa31b5403654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Fri, 25 Oct 2024 15:34:10 +0300 Subject: [PATCH] feat: :sparkles: counter with enable --- 02-counter_with_enable/counter_with_enable.v | 14 +++++++++++ .../counter_with_enable_tb.v | 23 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 02-counter_with_enable/counter_with_enable.v create mode 100644 02-counter_with_enable/counter_with_enable_tb.v diff --git a/02-counter_with_enable/counter_with_enable.v b/02-counter_with_enable/counter_with_enable.v new file mode 100644 index 0000000..d7a65f2 --- /dev/null +++ b/02-counter_with_enable/counter_with_enable.v @@ -0,0 +1,14 @@ +module counter_with_enable(out, enable, clk, reset); + parameter WIDTH = 8; + input enable, clk, reset; + output[WIDTH-1:0] out; + reg[WIDTH-1:0] out; + + always @(posedge clk)begin + if (reset) begin + out <= 8'b0; + end else if(enable) begin + out <= out + 1; + end + end +endmodule \ No newline at end of file diff --git a/02-counter_with_enable/counter_with_enable_tb.v b/02-counter_with_enable/counter_with_enable_tb.v new file mode 100644 index 0000000..404a9bf --- /dev/null +++ b/02-counter_with_enable/counter_with_enable_tb.v @@ -0,0 +1,23 @@ +module counter_with_enable_tb; + parameter WIDTH = 8; + reg reset = 0; + reg enable = 0; + initial begin + #17 reset = 1; + #11 enable = 1; + #17 reset = 0; + #11 enable = 1; + #17 reset = 1; + #17 $stop; + end + + reg clk = 0; + always begin + #1 clk = 0; + #1 clk = 1; + end + wire[WIDTH-1:0] output_wire; + counter_with_enable c1(output_wire, enable, clk, reset); + initial + $monitor("Time = %t, Value = %h (%0d)", $time, output_wire, output_wire); +endmodule \ No newline at end of file