Thursday, March 14, 2013

GRAY TO BINARY CONVERTER


This program is to convert gray code to binary code. The logic behind conversion is the most significant bit is same and the consequent bits are the result of ex-or of gray and binary bits. 

  
module bin_to_gray(
input clk,
input [2:0]gray_input,
output reg [2:0]bin_out
);
always@(posedge clk)
begin
bin_out[2] <= gray_input[2];
bin_out[1] <= bin_out[2] ^ gray_input[1];
bin_out[0] <= bin_out[1] ^ gray_input[0];
end
endmodule

No comments: