mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-30 02:32:53 +08:00
Cleaned up counter
-Not functional
This commit is contained in:
parent
d8d2d0c20e
commit
a7870ac9de
@ -1,67 +1,44 @@
|
|||||||
//#############################################################################
|
//#############################################################################
|
||||||
//# Function: Binary to gray encoder #
|
//# Function: Generic counter #
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
//# Author: Andreas Olofsson #
|
//# Author: Andreas Olofsson #
|
||||||
//# License: MIT (see LICENSE file in OH! repository) #
|
//# License: MIT (see LICENSE file in OH! repository) #
|
||||||
//#############################################################################
|
//#############################################################################
|
||||||
|
|
||||||
module oh_counter #(parameter DW = 32, // width of data inputs
|
module oh_counter #(parameter DW = 32 // width of data inputs
|
||||||
parameter TYPE = "INCREMENT" // also DECREMENT, GRAY, LFSR
|
|
||||||
)
|
)
|
||||||
(
|
(
|
||||||
|
//inputs
|
||||||
input clk, // clk input
|
input clk, // clk input
|
||||||
input in, // input to count
|
input in, // input to count
|
||||||
input en, // enable counter
|
input en, // enable counter
|
||||||
|
input dir,//0=increment, 1=decrement
|
||||||
|
input autowrap, //auto wrap around
|
||||||
input load, // load counter
|
input load, // load counter
|
||||||
input [DW-1:0] load_data,// load data
|
input [DW-1:0] load_data, // input data to load
|
||||||
output [DW-1:0] count, // current count value
|
//outputs
|
||||||
output carry, // carry out from counter
|
output [DW-1:0] count, // count value
|
||||||
output zero // counter is zero
|
output wraparund // wraparound indicator
|
||||||
);
|
);
|
||||||
|
|
||||||
// local variables
|
// local variables
|
||||||
reg [DW-1:0] count;
|
reg [DW-1:0] count;
|
||||||
reg carry;
|
|
||||||
wire [DW-1:0] count_in;
|
wire [DW-1:0] count_in;
|
||||||
wire carry_in;
|
|
||||||
|
|
||||||
// configure counter based on type
|
//Select count direction
|
||||||
generate
|
assign count_in[DW-1:0] = dir ? count[DW-1:0] - in :
|
||||||
if(TYPE=="INCREMENT")
|
count[DW-1:0] + in ;
|
||||||
begin
|
|
||||||
assign {carry_in,count_in[DW-1:0]} = count[DW-1:0] + in;
|
|
||||||
end
|
|
||||||
else if(TYPE=="DECREMENT")
|
|
||||||
begin
|
|
||||||
assign count_in[DW-1:0] = count[DW-1:0] + in;
|
|
||||||
end
|
|
||||||
else if (TYPE=="GRAY")
|
|
||||||
begin
|
|
||||||
initial
|
|
||||||
$display ("NOT IMPLEMENTED");
|
|
||||||
end
|
|
||||||
else if (TYPE=="LFSR")
|
|
||||||
begin
|
|
||||||
initial
|
|
||||||
$display ("NOT IMPLEMENTED");
|
|
||||||
end
|
|
||||||
endgenerate
|
|
||||||
|
|
||||||
// counter
|
// counter
|
||||||
always @(posedge clk)
|
always @(posedge clk)
|
||||||
if(load)
|
if(load)
|
||||||
begin
|
|
||||||
carry <= 1'b0;
|
|
||||||
count[DW-1:0] <= load_data[DW-1:0];
|
count[DW-1:0] <= load_data[DW-1:0];
|
||||||
end
|
else if (en & ~(wraparound & ~autowrap))
|
||||||
else if (en)
|
|
||||||
begin
|
|
||||||
carry <= carry_in;
|
|
||||||
count[DW-1:0] <= count_in[DW-1:0];
|
count[DW-1:0] <= count_in[DW-1:0];
|
||||||
end
|
|
||||||
|
|
||||||
// counter expired
|
// counter expired
|
||||||
assign zero = ~(count[DW-1:0]);
|
assign wraparound = (dir & en & ~(|count[DW-1:0])) |
|
||||||
|
(~dir & en & (&count[DW-1:0]));
|
||||||
|
|
||||||
endmodule // oh_counter
|
endmodule // oh_counter
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user