//------------------------------------------------------------------------ // Title : count8.v // Description : This module implements a loadable counter that simply // counts up until it reaches 0. //--------------------------------------------------------------------------- `timescale 1ns / 1ns module count8 (clk, reset, datain, load, tc); input clk, reset; input [7:0] datain; // Value to be loaded into the counter input load; // Load initializes the counter to datain output tc; // "Terminal Count", i.e. highest count value reg tc; // Declaration needed for always block reg [7:0] count, nxt_count; // This block implements a simple register always @(posedge clk) begin if (reset) count <= 0; else count <= nxt_count; end // This block implements the logic for the next count value and // for the tc output always @(count or datain or load) begin nxt_count = count; // Default is to do nothing if (load) nxt_count = datain; else if (count != 0) nxt_count = count + 1; tc = (count == 255); end endmodule // count8