Presentation is loading. Please wait.

Presentation is loading. Please wait.

Gray Code Converters Discussion D9.1 Example 16. Gray Code One method for generating a Gray code sequence: Start with all bits zero and successively flip.

Similar presentations


Presentation on theme: "Gray Code Converters Discussion D9.1 Example 16. Gray Code One method for generating a Gray code sequence: Start with all bits zero and successively flip."— Presentation transcript:

1 Gray Code Converters Discussion D9.1 Example 16

2 Gray Code One method for generating a Gray code sequence: Start with all bits zero and successively flip the right-most bit that produces a new string. Binary coding {0...7}: {000, 001, 010, 011, 100, 101, 110, 111} Gray coding {0...7}: {000, 001, 011, 010, 110, 111, 101, 100} Definition: An ordering of 2 n binary numbers such that only one bit changes from one entry to the next. Not unique

3 Binary coding {0...7}: {000, 001, 010, 011, 100, 101, 110, 111} Gray coding {0...7}: {000, 001, 011, 010, 110, 111, 101, 100} Binary - Gray Code Conversions Gray code: G(i), i = n – 1 downto 0 Binary code: B(i), i = n – 1 downto 0 Convert Binary to Gray: Copy the most significant bit. For each smaller i G(i) = B(i+1) xor B(i) Convert Gray to Binary: Copy the most significant bit. For each smaller i B(i) = B(i+1) xor G(i)

4 library IEEE; use IEEE.STD_LOGIC_1164.all; entity bin2gray is generic(width:positive := 3); port( b : in STD_LOGIC_VECTOR(width-1 downto 0); g : out STD_LOGIC_VECTOR(width-1 downto 0) ); end bin2gray; architecture bin2gray of bin2gray is begin process(b) begin g(width-1) <= b(width-1); for i in width-2 downto 0 loop g(i) <= b(i+1) xor b(i); end loop; end process; end bin2gray; bin2gray.vhd

5 Binary to Gray Code Conversion

6 library IEEE; use IEEE.STD_LOGIC_1164.all; entity gray2bin is generic(width:positive := 3); port( g : in STD_LOGIC_VECTOR(width-1 downto 0); b : out STD_LOGIC_VECTOR(width-1 downto 0) ); end gray2bin; architecture gray2bin of gray2bin is begin process(g) variable bv: STD_LOGIC_VECTOR(width-1 downto 0); begin bv(width-1) := G(width-1); for i in width-2 downto 0 loop bv(i) := bv(i+1) xor g(i); end loop; b <= bv; end process; end gray2bin; gray2bin.vhd

7 Gray Code to Binary Conversion


Download ppt "Gray Code Converters Discussion D9.1 Example 16. Gray Code One method for generating a Gray code sequence: Start with all bits zero and successively flip."

Similar presentations


Ads by Google