Advertisement
Synthron

8bit_double_dabble

Jun 17th, 2020
1,701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.59 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4.  
  5. entity bit8_double_dabble is
  6.     port(
  7.         binIN   : in  std_logic_vector (7 downto 0);
  8.         ones    : out std_logic_vector (3 downto 0);
  9.         tens    : out std_logic_vector (3 downto 0);
  10.         hunds   : out std_logic_vector (3 downto 0)
  11.     );
  12. end bit8_double_dabble;
  13.  
  14. architecture RTL of bit8_double_dabble is
  15. begin
  16.     conv : process (binIN)
  17.     variable temp : std_logic_vector (7 downto 0); -- temporäre Variable
  18.  
  19.     variable bcd  : unsigned (11 downto 0) := (others => '0');-- Arbeitsvariable
  20.  
  21.     begin
  22.         -- bcd löschen
  23.         bcd := (others => '0');
  24.         -- Input einlesen
  25.         temp (7 downto 0) := binIN;
  26.  
  27.         -- Eigentlicher Algorithmus
  28.         -- 8 Zyklen wegen 8 Input-Bits
  29.         for i in 0 to 7 loop
  30.             if bcd(3 downto 0) > 4 then
  31.                 bcd(3 downto 0) := bcd(3 downto 0) + 3;
  32.             end if;
  33.  
  34.             if bcd(7 downto 4) > 4 then
  35.                 bcd(7 downto 4) := bcd (7 downto 4) + 3;
  36.             end if;
  37.  
  38.             -- Hunderter müssen hier nicht geprüft werden, da max. 255
  39.  
  40.             -- Schieb bcd nach links, häng das MSB von tmp an
  41.             bcd := bcd(10 downto 0) & temp(7);
  42.  
  43.             -- Schieb temp eins nach links
  44.             temp := temp(6 downto 0) & '0';
  45.         end loop;
  46.        
  47.         -- Ausgänge setzen
  48.         ones  <= std_logic_vector(bcd(3 downto 0));
  49.         tens  <= std_logic_vector(bcd(7 downto 4));
  50.         hunds <= std_logic_vector(bcd(11 downto 8));
  51.     end process conv;
  52. end architecture RTL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement