Guest User

Untitled

a guest
Dec 23rd, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.57 KB | None | 0 0
  1. architecture Behavioral of PC is
  2.  
  3.     type state is (idle, init, subtract, test, operation_sub1, operation_sub0, correction, finished);
  4.     signal current_state, next_state : state;
  5.  
  6. begin
  7.    
  8.     control:    process(current_state, start, S_in, counted)
  9.                 begin
  10.                     en_M <= '0';
  11.                     en_Q <= '0';
  12.                     en_A <= '0';
  13.                     en_C <= '0';
  14.                     en_S <= '0';
  15.                     reset_M <= '1';
  16.                     reset_Q <= '1';
  17.                     reset_A <= '1';
  18.                     reset_C <= '1';
  19.                     reset_S <= '1';
  20.                     shift <= '0';
  21.                     stop <= '0';
  22.                     start_out <= '0';
  23.                     sub <= '0';
  24.  
  25.                     case current_state is
  26.                         when idle =>
  27.                             if start='1' then
  28.                                 reset_M <= '0';
  29.                                 reset_Q <= '0';
  30.                                 reset_A <= '0';
  31.                                 reset_C <= '0';
  32.                                 reset_S <= '0';
  33.                                 next_state <= init;
  34.                             else
  35.                                 next_state <= idle;
  36.                             end if;
  37.                        
  38.                         when init =>
  39.                             en_A <= '1'; -- "A" carica i MSB del dividendo
  40.                             en_Q <= '1'; -- "Q" carica i LSB del dividendo
  41.                             en_M <= '1'; -- "M" carica il divisore
  42.                             reset_S <= '0';
  43.                             start_out <= '1';
  44.                             next_state <= subtract;
  45.                        
  46.                         when subtract =>
  47.                             en_A <= '1';
  48.                             en_M <= '1';
  49.                             en_S <= '1';
  50.                             sub <= '1';
  51.                             next_state <= test;
  52.                        
  53.                         when test => -- shift
  54.                             en_Q <= '1';
  55.                             shift <= '1';
  56.                             en_C <= '1';
  57.                            
  58.                             if counted=N/2-1 then
  59.                                 if S_in='0' then
  60.                                     sub <= '1';
  61.                                     next_state <= finished;
  62.                                 else
  63.                                     sub <= '0'; --
  64.                                     next_state <= correction;
  65.                                 end if;
  66.                             else
  67.                                 en_A <= '1';
  68.                                 en_S <= '1';
  69.                                
  70.                                 if S_in='0' then
  71.                                     sub <= '1';
  72.                                     next_state <= operation_sub1;
  73.                                 else
  74.                                     sub <= '0'; --
  75.                                     next_state <= operation_sub0;
  76.                                 end if;
  77.                             end if;
  78.                        
  79.                         when operation_sub1 =>
  80.                             en_A <= '1';
  81.                             en_M <= '1';
  82.                             en_S <= '1';
  83.                             sub <= '1';
  84.                             next_state <= test;
  85.                            
  86.                         when operation_sub0 =>
  87.                             en_A <= '1';
  88.                             en_M <= '1';
  89.                             en_S <= '1';
  90.                             sub <= '0'; --
  91.                             next_state <= test;
  92.                        
  93.                         when correction =>
  94.                             if S_in='1' then
  95.                                 en_A <= '1';
  96.                                 en_M <= '1';
  97.                                 sub <= '0'; --
  98.                             else
  99.                                 sub <= '1';
  100.                             end if;
  101.                            
  102.                             next_state <= finished;
  103.                        
  104.                         when finished =>
  105.                             stop <= '1';
  106.                             next_state <= idle;
  107.                     end case;
  108.                 end process;
  109.    
  110.     update:     process(clk_in, next_state)
  111.                 begin
  112.                     if rising_edge(clk_in) then
  113.                         current_state <= next_state;
  114.                     end if;
  115.                 end process;
  116.  
  117. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment