2015-12-17 13:50:59 -05:00
|
|
|
module oh_counter (/*AUTOARG*/
|
|
|
|
// Outputs
|
2016-02-23 15:41:35 -05:00
|
|
|
count, carry, zero,
|
2015-12-17 13:50:59 -05:00
|
|
|
// Inputs
|
2016-02-23 15:41:35 -05:00
|
|
|
clk, in, en, load, load_data
|
2015-12-17 13:50:59 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
//###############################################################
|
|
|
|
//# Interface
|
|
|
|
//###############################################################
|
|
|
|
|
|
|
|
parameter DW = 64;
|
2016-02-23 15:41:35 -05:00
|
|
|
parameter TYPE = "INCREMENT"; //INCREMENT, DECREMENT, GRAY, LFSR
|
2015-12-17 13:50:59 -05:00
|
|
|
|
|
|
|
//clock interface
|
2016-02-23 15:41:35 -05:00
|
|
|
input clk; // clk input
|
|
|
|
|
2015-12-17 13:50:59 -05:00
|
|
|
//counter control
|
2016-02-23 15:41:35 -05:00
|
|
|
input in; // input to count
|
|
|
|
input en; // enable counter
|
|
|
|
input load; // load counter
|
|
|
|
input [DW-1:0] load_data;// load data
|
2015-12-17 13:50:59 -05:00
|
|
|
|
|
|
|
//outputs
|
2016-02-23 15:41:35 -05:00
|
|
|
output [DW-1:0] count; // current count value
|
|
|
|
output carry; // carry out from counter
|
|
|
|
output zero; // counter is zero
|
2015-12-17 13:50:59 -05:00
|
|
|
|
|
|
|
//###############################################################
|
|
|
|
//# Interface
|
|
|
|
//###############################################################
|
|
|
|
reg [DW-1:0] count;
|
2016-02-23 15:41:35 -05:00
|
|
|
reg carry;
|
|
|
|
wire [DW-1:0] count_in;
|
|
|
|
wire carry_in;
|
2015-12-17 13:50:59 -05:00
|
|
|
|
2016-01-17 21:15:28 -05:00
|
|
|
always @(posedge clk)
|
|
|
|
if(load)
|
2016-02-23 15:41:35 -05:00
|
|
|
begin
|
|
|
|
carry <= 1'b0;
|
|
|
|
count[DW-1:0] <= load_data[DW-1:0];
|
|
|
|
end
|
2015-12-17 13:50:59 -05:00
|
|
|
else if (en)
|
2016-02-23 15:41:35 -05:00
|
|
|
begin
|
|
|
|
carry <= carry_in;
|
|
|
|
count[DW-1:0] <= count_in[DW-1:0];
|
|
|
|
end
|
|
|
|
|
|
|
|
assign zero = ~(count[DW-1:0]);
|
|
|
|
|
|
|
|
// configure counter based on type
|
2015-12-17 13:50:59 -05:00
|
|
|
generate
|
2016-02-23 15:41:35 -05:00
|
|
|
if(TYPE=="INCREMENT")
|
|
|
|
begin
|
|
|
|
assign {carry_in,count_in[DW-1:0]} = count[DW-1:0] + in;
|
|
|
|
end
|
|
|
|
else if(TYPE=="DECREMENT")
|
2015-12-17 13:50:59 -05:00
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|