mirror of
https://github.com/aolofsson/oh.git
synced 2025-01-30 02:32:53 +08:00
de63dfd907
-stdcells moved to asiclib, doesn't make sense to be vectorized -common is a stupid name, renamed as stdlib
34 lines
1003 B
Verilog
34 lines
1003 B
Verilog
//#############################################################################
|
|
//# Function: Gray to binary encoder #
|
|
//#############################################################################
|
|
//# Author: Andreas Olofsson #
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
|
//#############################################################################
|
|
|
|
module oh_gray2bin #(parameter N = 32) // width of data inputs
|
|
(
|
|
input [N-1:0] in, //gray encoded input
|
|
output [N-1:0] out //binary encoded output
|
|
);
|
|
|
|
reg [N-1:0] bin;
|
|
wire [N-1:0] gray;
|
|
|
|
integer i,j;
|
|
|
|
assign gray[N-1:0] = in[N-1:0];
|
|
assign out[N-1:0] = bin[N-1:0];
|
|
|
|
always @*
|
|
begin
|
|
bin[N-1] = gray[N-1];
|
|
for (i=0; i<(N-1); i=i+1)
|
|
begin
|
|
bin[i] = 1'b0;
|
|
for (j=i; j<N; j=j+1)
|
|
bin[i] = bin[i] ^ gray [j];
|
|
end
|
|
end
|
|
|
|
endmodule // oh_gray2bin
|