binarytogray.v
Upload User: saul_905
Upload Date: 2013-11-27
Package Size: 184k
Code Size: 1k
Development Platform:

Visual C++

  1. module binarytogray (clk, reset, binary_input, gray_output);
  2. input          clk, reset;
  3. input   [3:0]  binary_input;
  4. output         gray_output;
  5. reg     [3:0]  gray_output;
  6. always @ (posedge clk or posedge reset)
  7. if (reset)
  8.    begin
  9.    gray_output <= 4'b0;
  10.    end
  11. else begin
  12.      gray_output[3] <= binary_input[3];
  13.      gray_output[2] <= binary_input[3] ^ binary_input[2];
  14.      gray_output[1] <= binary_input[2] ^ binary_input[1];
  15.      gray_output[0] <= binary_input[1] ^ binary_input[0];
  16.      end
  17. endmodule