2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Function: Binary to gray 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_bin2gray
|
|
|
|
#(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, //binary encoded input
|
|
|
|
output [N-1:0] out //gray encoded output
|
2016-04-11 12:01:59 -04:00
|
|
|
);
|
2016-04-13 20:46:02 -04:00
|
|
|
|
2021-07-26 22:34:03 -04:00
|
|
|
reg [N-1:0] gray;
|
|
|
|
wire [N-1:0] bin;
|
|
|
|
|
|
|
|
integer i;
|
|
|
|
|
|
|
|
assign bin[N-1:0] = in[N-1:0];
|
|
|
|
assign out[N-1:0] = gray[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
|
|
|
gray[N-1] = bin[N-1];
|
|
|
|
for (i=0; i<(N-1); i=i+1)
|
|
|
|
gray[i] = bin[i] ^ bin[i+1];
|
2016-01-10 13:33:31 -05:00
|
|
|
end
|
2021-07-26 22:34:03 -04:00
|
|
|
|
2015-12-17 13:50:59 -05:00
|
|
|
endmodule // oh_bin2gray
|