2020-02-25 15:38:56 +03:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// gray2bin.sv
|
2023-02-24 05:59:40 +03:00
|
|
|
// published as part of https://github.com/pConst/basic_verilog
|
2020-02-25 15:38:56 +03:00
|
|
|
// Konstantin Pavlov, pavlovconst@gmail.com
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// INFO ------------------------------------------------------------------------
|
|
|
|
// Binary to gray code converter
|
|
|
|
// Combinational design
|
|
|
|
|
|
|
|
|
|
|
|
/* --- INSTANTIATION TEMPLATE BEGIN ---
|
|
|
|
|
|
|
|
gray2bin #(
|
|
|
|
.WIDTH( 32 )
|
|
|
|
) GB1 (
|
|
|
|
.gray_in( ),
|
|
|
|
.bin_out( )
|
|
|
|
);
|
|
|
|
|
|
|
|
--- INSTANTIATION TEMPLATE END ---*/
|
|
|
|
|
|
|
|
module gray2bin #( parameter
|
|
|
|
WIDTH = 32
|
|
|
|
)(
|
|
|
|
input [WIDTH-1:0] gray_in,
|
2023-02-24 05:59:40 +03:00
|
|
|
output logic [WIDTH-1:0] bin_out
|
2020-02-25 15:38:56 +03:00
|
|
|
);
|
|
|
|
|
2023-02-24 05:59:40 +03:00
|
|
|
always_comb begin
|
|
|
|
bin_out[WIDTH-1:0] = '0;
|
|
|
|
|
|
|
|
for( integer i=0; i<WIDTH; i++ ) begin
|
|
|
|
bin_out[WIDTH-1:0] ^= gray_in[WIDTH-1:0] >> i;
|
|
|
|
end
|
2020-02-25 15:38:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|