From 1cfdda0d9f76d36df95677e631b8b15dd19b4dcb Mon Sep 17 00:00:00 2001 From: uvok Date: Sun, 18 Jan 2026 10:58:56 +0100 Subject: counter: Add "count_enable" pin --- nandgame/counter.sv | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'nandgame/counter.sv') diff --git a/nandgame/counter.sv b/nandgame/counter.sv index 2089194..87ecdd7 100644 --- a/nandgame/counter.sv +++ b/nandgame/counter.sv @@ -1,11 +1,12 @@ // nandgame counter +// counts on *falling* edge `timescale 1us/1us `ifndef NANDGAME_COUNTER `define NANDGAME_COUNTER -module counter #( +module counter #( parameter DATA_WIDTH = 16 ) ( // input / value to store in counter @@ -14,6 +15,9 @@ module counter #( input wire st_store_X_in, // clock input wire clk_in, + // active high, whether to count + // st_store_X_in overrides this in any case. + input wire count_enable_in, // counter value output wire [(DATA_WIDTH-1):0] counter_out @@ -45,7 +49,7 @@ end always @(negedge clk_in) begin if (st_store_X_in) counter_int <= X_in; - else + else if (count_enable_in) counter_int <= counter_int + 1; end -- cgit v1.2.3