]> jspc29.x-matter.uni-frankfurt.de Git - trb3.git/commitdiff
Gray code to binary converter
authorTobias Weber <toweber86@gmail.com>
Sat, 2 Jun 2018 21:23:34 +0000 (23:23 +0200)
committerTobias Weber <toweber86@gmail.com>
Sat, 2 Jun 2018 21:23:34 +0000 (23:23 +0200)
mupix/Mupix8/sources/Gray2Binary.vhd [new file with mode: 0644]

diff --git a/mupix/Mupix8/sources/Gray2Binary.vhd b/mupix/Mupix8/sources/Gray2Binary.vhd
new file mode 100644 (file)
index 0000000..fb94162
--- /dev/null
@@ -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;