Advertisement
Guest User

DivCtrlUnit

a guest
May 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.44 KB | None | 0 0
  1. brary IEEE;
  2. use IEEE.STD_LOGIC_1164.all;
  3.  
  4. entity DivCtrlUnit is
  5.    generic(numBits  : positive);
  6.    port(clk         : in  std_logic;
  7.         reset       : in  std_logic;
  8.         start       : in  std_logic;
  9.         busy        : out std_logic;
  10.         done        : out std_logic;
  11.         regsInit    : out std_logic;
  12.         accEnable   : out std_logic;
  13.           shiftBit    : out  std_logic;
  14.           accBit      : out  std_logic;
  15.           MSB         : in  std_logic;
  16.         regsShift   : out std_logic);
  17. end DivCtrlUnit;
  18.  
  19. architecture Behavioral of DivCtrlUnit is
  20. type TState is (ST_IDLE, ST_INIT, ST_SHIFT_RIGHT, ST_SUB, ST_ACC, ST_SHIFT_LEFT);
  21. signal s_currentState, s_nextState : TState;
  22.  
  23. subtype TCounter is natural range 0 to numBits;
  24. signal s_iterCnt : TCounter;
  25.  
  26. begin
  27.     process(clk)
  28.     begin
  29.         if(rising_edge(clk)) then
  30.             if(reset = '1') then
  31.                 s_currentState <= ST_IDLE;
  32.             else
  33.                 s_currentState <= s_nextState;
  34.             end if;
  35.         end if;
  36.     end process;
  37.    
  38.     process(s_currentState, start)
  39.     begin
  40.         s_nextState <= s_currentState;
  41.        
  42.         case s_currentState is
  43.        
  44.         when ST_IDLE =>
  45.             if(start = '1') then
  46.                 s_nextState <= ST_INIT;
  47.             end if;
  48.        
  49.         when ST_INIT =>
  50.             s_nextState <= ST_SHIFT_RIGHT;
  51.            
  52.         when ST_SHIFT_RIGHT =>
  53.             s_nextState <= ST_SUB;
  54.            
  55.         when ST_SUB =>
  56.             if(MSB = '1') then
  57.                 s_nextState <= ST_ACC;
  58.             else
  59.                 s_nextState <= ST_SHIFT_LEFT;
  60.             end if;
  61.            
  62.         when ST_ACC =>
  63.             s_nextState <= ST_SHIFT_LEFT;
  64.            
  65.         when ST_SHIFT_LEFT =>
  66.             if(s_iterCnt < numBits) then
  67.                 s_nextState <= ST_INIT;
  68.             else
  69.                 s_nextState <= ST_IDLE;
  70.             end if;
  71.            
  72.       end case;
  73.    end process;
  74.    
  75.  
  76.     process(s_currentState)
  77.    begin
  78.       busy      <= '0';
  79.       done      <= '0';
  80.       regsInit  <= '0';
  81.       accEnable <= '0';
  82.       regsShift <= '0';
  83.         shiftBit  <= '0';
  84.         accBit    <= '0';
  85.        
  86.       case s_currentState is
  87.       when ST_IDLE =>
  88.          done      <= '1';
  89.             accEnable <= '0';
  90.             busy      <= '0';
  91.  
  92.       when ST_INIT =>
  93.          busy      <= '1';
  94.          regsInit  <= '1';
  95.             accEnable <= '1';
  96.  
  97.         when ST_SHIFT_RIGHT =>
  98.          busy      <= '1';
  99.    
  100.         when ST_ACC =>
  101.          busy      <= '1';
  102.             accBit <= '1';         
  103.    
  104.       when ST_SHIFT_LEFT =>
  105.          busy      <= '1';
  106.          regsShift <= '1';
  107.            if(MSB = '1') then
  108.                 shiftBit <= '0';
  109.             else
  110.                 shiftBit <= '1';
  111.             s_iterCnt <= s_iterCnt + 1;
  112.            
  113.             end if;
  114.       end case;
  115.    end process;
  116. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement