From 5239caa6707cdd41b1be713dc02133c61b6407a5 Mon Sep 17 00:00:00 2001 From: Tobias Weber Date: Sat, 2 Jun 2018 23:23:34 +0200 Subject: [PATCH] Gray code to binary converter --- mupix/Mupix8/sources/Gray2Binary.vhd | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 mupix/Mupix8/sources/Gray2Binary.vhd diff --git a/mupix/Mupix8/sources/Gray2Binary.vhd b/mupix/Mupix8/sources/Gray2Binary.vhd new file mode 100644 index 0000000..fb94162 --- /dev/null +++ b/mupix/Mupix8/sources/Gray2Binary.vhd @@ -0,0 +1,41 @@ +-------------------------------------------------- +-- Convert gray code to a binary code +-- Tobias Weber +-- Ruhr University Bochum +-- based on code by Niklaus Berger +------------------------------------------------- +library ieee; +use ieee.std_logic_1164.all; +use ieee.numeric_std.all; + +entity gray_to_binary is + generic(NBITS : integer := 10); + port ( + clk : in std_logic; -- clk input + reset : in std_logic; -- reset input + gray_in : in std_logic_vector (NBITS - 1 downto 0); -- gray counter input + bin_out : out std_logic_vector (NBITS - 1 downto 0) -- binary counter output + ); +end gray_to_binary; + +architecture rtl of gray_to_binary is + +begin + + process(clk) + variable decoding : std_logic_vector(NBITS - 1 downto 0); + begin + if rising_edge(clk) then + if reset = '1' then + bin_out <= (others => '0'); + else + decoding(NBITS - 1) := gray_in(NBITS - 1); + for i in NBITS - 2 downto 0 loop + decoding(i) := gray_in(i) xor decoding(i + 1); + end loop; + bin_out <= decoding; + end if; + end if; + end process; + +end rtl; -- 2.43.0