2003-04-24 19:24:37 +00:00
|
|
|
module inc(count, enable, clock, reset);
|
|
|
|
|
|
|
|
parameter n = 8;
|
|
|
|
input enable;
|
|
|
|
input clock;
|
|
|
|
input reset;
|
|
|
|
output [15:0] count;
|
|
|
|
reg [15:0] count;
|
|
|
|
|
2003-05-07 16:52:57 +00:00
|
|
|
initial
|
|
|
|
count = 0;
|
|
|
|
|
|
|
|
|
2003-04-24 19:24:37 +00:00
|
|
|
always @(posedge clock or negedge reset) begin
|
2003-05-07 16:52:57 +00:00
|
|
|
$display("Always triggered: count %d", count);
|
2003-04-24 19:24:37 +00:00
|
|
|
if (reset == 0) begin
|
|
|
|
count <= 0;
|
|
|
|
end
|
|
|
|
else begin
|
|
|
|
if (enable) begin
|
|
|
|
count <= (count + 1) % n;
|
|
|
|
end
|
|
|
|
// $display("count %d", count);
|
|
|
|
end
|
2003-05-07 16:52:57 +00:00
|
|
|
end // always @ (posedge clock or negedge reset)
|
|
|
|
|
|
|
|
always @ (count) begin
|
|
|
|
$display("%d count %d", $time, count);
|
2003-04-24 19:24:37 +00:00
|
|
|
end
|
2003-05-07 16:52:57 +00:00
|
|
|
|
|
|
|
|
2003-04-24 19:24:37 +00:00
|
|
|
|
|
|
|
endmodule // inc
|