1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-02-07 06:44:09 +08:00
oh/common/hdl/oh_counter.v

66 lines
1.4 KiB
Coq
Raw Normal View History

2015-12-17 13:50:59 -05:00
module oh_counter (/*AUTOARG*/
// Outputs
count, zero,
// Inputs
2016-01-17 21:15:28 -05:00
clk, nreset, in, en, load, wdata
2015-12-17 13:50:59 -05:00
);
//###############################################################
//# Interface
//###############################################################
parameter DW = 64;
parameter TYPE = "BINARY"; //BINARY, GRAY, LFSR
//clock interface
input clk;
input nreset;
//counter control
2016-01-17 21:15:28 -05:00
input in; //input to count
2015-12-17 13:50:59 -05:00
input en; //counter enabled
input load; //loads new start value
input [DW-1:0] wdata; //write data
//outputs
output [DW-1:0] count; //current count value
output zero; //counter is zero
//###############################################################
//# Interface
//###############################################################
reg [DW-1:0] count;
2016-01-17 21:15:28 -05:00
always @(posedge clk)
if(load)
2015-12-17 13:50:59 -05:00
count[DW-1:0] = wdata[DW-1:0];
else if (en)
count[DW-1:0] = count_in[DW-1:0];
generate
if(TYPE=="BINARY")
begin
2016-01-17 21:15:28 -05:00
assign count_in[DW-1:0] = count[DW-1:0] + in;
2015-12-17 13:50:59 -05:00
end
else if (TYPE=="GRAY")
begin
initial
$display ("NOT IMPLEMENTED");
end
else if (TYPE=="LFSR")
begin
initial
$display ("NOT IMPLEMENTED");
end
endgenerate
endmodule // oh_counter