diff --git a/bin2gray.sv b/bin2gray.sv new file mode 100644 index 0000000..f17e671 --- /dev/null +++ b/bin2gray.sv @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// bin2gray.sv +// Konstantin Pavlov, pavlovconst@gmail.com +//------------------------------------------------------------------------------ + +// INFO ------------------------------------------------------------------------ +// Gray code to binary converter +// Combinational design + + +/* --- INSTANTIATION TEMPLATE BEGIN --- + +bin2gray #( + .WIDTH( 32 ) +) BG1 ( + .bin_in( ), + .gray_out( ) +); + +--- INSTANTIATION TEMPLATE END ---*/ + +module bin2gray #( parameter + WIDTH = 32 +)( + input [WIDTH-1:0] bin_in, + output logic[WIDTH-1:0] gray_out +); + +always_comb begin + gray_out[WIDTH-1:0] = bin_in[WIDTH-1:0]^(bin_in[WIDTH-1:0]>>1); +end + +endmodule + diff --git a/gray2bin.sv b/gray2bin.sv new file mode 100644 index 0000000..6c3fe4a --- /dev/null +++ b/gray2bin.sv @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// gray2bin.sv +// 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, + output [WIDTH-1:0] bin_out +); + +genvar i; +generate + for( i=0; i