Guest User

Untitled

a guest
Jan 14th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 3.49 KB | None | 0 0
  1. library ieee ;  use ieee.std_logic_1164.all;
  2.         use ieee.numeric_std.all;
  3. library work ; use work.basic.all;
  4.  
  5. entity fsm is
  6.     port(   Convert_i,
  7.             Clk_i       : in std_logic;
  8.             Data_id     : in std_logic_vector(7 downto 0);
  9.             S4_o, S3n_o,
  10.             S2n_o, S1_o,
  11.             Busy_o,
  12.             New_data_o,
  13.             Reset_i     : out std_logic
  14.            
  15.         );
  16. end;
  17.  
  18. architecture Behavior of fsm is
  19.  
  20.     type State_type is (Zero, Disconnect_1, Disconnect_2, Sample, Compute, Update, Next_Byte);
  21.    
  22.     signal Next_sate, Current_state : State_type;
  23.     signal inc_cnt_s                : std_logic;
  24.     signal N_s                      : integer range 8 to 0;  
  25.    
  26. begin
  27.    
  28.     cur_st : PROCESS(Clk_i, Reset_i)
  29.     begin
  30.         if Reset_i = '1' then
  31.             Current_state <= Zero;
  32.         elsif rising_edge(Clk_i) then
  33.             Current_state <= Next_state;
  34.         end if;
  35.     end process;
  36.  
  37.     next_st : PROCESS(Current_state, Convert_i, N_s)
  38.     begin
  39.         case Current_state is
  40.             when Zero =>
  41.                 if Convert_i = '1' then
  42.                     Next_state  <= Disconnect_1;
  43.                 else
  44.                     Next_state  <= Zero;
  45.                 end if;
  46.  
  47.             when Disconnect_1 =>
  48.                 if N_s = 8 then
  49.                     Next_state  <= Compute;
  50.                 else
  51.                     Next_state  <= Sample;
  52.                 end if;
  53.  
  54.             when Sample =>
  55.                 Next_state      <= Disconnect_2;
  56.  
  57.             when Disconnect_2 =>
  58.                 Next_state      <= Compute;
  59.  
  60.             when Compute =>
  61.                 Next_state      <= Disconnect_1;
  62.  
  63.             when Update =>
  64.                 Next_state      <= Next_Byte;
  65.  
  66.             when Next_Byte =>
  67.                 Next_state      <= Zero
  68.  
  69.             when others =>
  70.                 Next_state      <= Zero;
  71.  
  72.         end case;
  73.     end process;
  74.    
  75.    
  76.     decode : PROCESS(Current_state, Data_i, N_s)
  77.     begin
  78.         -- Default output --
  79.         S1_o         <= '0';
  80.         S2n_o        <= '1';
  81.         S3n_o        <= '1';
  82.         S4_o         <= '0';
  83.         Busy_o       <= '1';
  84.         New_data_o   <= '0';
  85.         inc_cnt_s    <= '0';
  86.        
  87.         case(Current_state) is
  88.             when Zero =>
  89.                 S2n_o       <= '0';
  90.                 S3n_o       <= '0';
  91.                 Busy_o      <= '0';
  92.              
  93.             when Disconnect_1 => -- Default
  94.             when Disconnect_2 => -- Default
  95.  
  96.             when Sample =>
  97.                 if Data_i[N_s] = '1' then
  98.                     S1_o    <= '1';
  99.                 else
  100.                     S1_o    <= '0';
  101.  
  102.                 Busy_o      <= '1';
  103.            
  104.             when Compute =>
  105.                 S3n_o       <= '0';
  106.                 inc_cnt_s   <= '1';
  107.                 Busy_o      <= '1';
  108.  
  109.             when Update =>
  110.                 S4_o        <= '1';
  111.                 Busy_o      <= '1';
  112.                
  113.             when Next_Byte =>
  114.                 New_data_o  <= '1';
  115.                 inc_cnt_s   <= '1';
  116.  
  117.         end case;
  118.     end process;
  119.    
  120.  
  121.     counter : PROCESS(Clk_i, Reset_i)
  122.     begin
  123.         if Reset_i = '1' then
  124.             N_s <= 0;
  125.         elsif rising_edge(Clk_i) then
  126.  
  127.             if inc_cnt_s = '1' then
  128.                 N_s <= N_s + 1;
  129.             elsif N_s > 8 then
  130.                 N_s = 0;
  131.             end if;
  132.         end if;
  133.     end process;
  134.    
  135.  
  136. end Behavior;
Add Comment
Please, Sign In to add comment