2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Function: Gray to binary encoder #
|
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
2021-07-26 22:34:03 -04:00
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
2015-12-17 13:50:59 -05:00
|
|
|
|
2021-07-26 22:34:03 -04:00
|
|
|
module oh_gray2bin #(parameter N = 32) // width of data inputs
|
2016-04-11 12:01:59 -04:00
|
|
|
(
|
2021-07-26 22:34:03 -04:00
|
|
|
input [N-1:0] in, //gray encoded input
|
|
|
|
output [N-1:0] out //binary encoded output
|
2016-04-11 12:01:59 -04:00
|
|
|
);
|
2021-07-26 22:34:03 -04:00
|
|
|
|
|
|
|
reg [N-1:0] bin;
|
|
|
|
wire [N-1:0] gray;
|
|
|
|
|
2016-01-10 13:33:31 -05:00
|
|
|
integer i,j;
|
|
|
|
|
2021-07-26 22:34:03 -04:00
|
|
|
assign gray[N-1:0] = in[N-1:0];
|
|
|
|
assign out[N-1:0] = bin[N-1:0];
|
2016-04-13 20:46:02 -04:00
|
|
|
|
2016-01-10 13:33:31 -05:00
|
|
|
always @*
|
|
|
|
begin
|
2021-07-26 22:34:03 -04:00
|
|
|
bin[N-1] = gray[N-1];
|
|
|
|
for (i=0; i<(N-1); i=i+1)
|
2016-01-10 13:33:31 -05:00
|
|
|
begin
|
2021-07-26 22:34:03 -04:00
|
|
|
bin[i] = 1'b0;
|
|
|
|
for (j=i; j<N; j=j+1)
|
2016-01-10 13:33:31 -05:00
|
|
|
bin[i] = bin[i] ^ gray [j];
|
|
|
|
end
|
|
|
|
end
|
2016-04-13 20:46:02 -04:00
|
|
|
|
2015-12-17 13:50:59 -05:00
|
|
|
endmodule // oh_gray2bin
|