Advertisement
Device-Cheat

Untitled

Jun 27th, 2020
2,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.94 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. entity sarNowy is
  5.     port (
  6.     in_clk : in std_logic;
  7.     rst_n : in std_logic;
  8.     start : in std_logic;
  9.     comp_in : in std_logic;
  10.     data_out : out std_logic_vector (7 downto 0);
  11.     D_out : out std_logic_vector(7 downto 0);
  12.     B_hold : out std_logic_vector(7 downto 0);
  13.     sample : out std_logic;
  14.     hold : out std_logic;
  15.     eoc : out std_logic);
  16. end sarNowy;
  17.  
  18. architecture state_machine of sar is
  19. type state is (reset, state1, state2, state3, state4, state5, state6, state7, state8, state9, state10, state11, state12, state13, state14, state15, state16, state17, state18);
  20. signal pr_state, nx_state : state;
  21. begin            
  22.    
  23.     -- Lower sequential circuit
  24.     seq : process(in_clk)
  25.     begin
  26.         if rst_n'event and rst_n = '0' then -- negedge of rst
  27.             pr_state <= reset;
  28.         elsif in_clk'event and in_clk='1' then  -- posedge of clk
  29.             pr_state <= nx_state;
  30.         end if;
  31.     end process;
  32.    
  33.    
  34.     -- Upper combinational circuit
  35.     combinational : process (pr_state, start)
  36.     begin
  37.         case pr_state is
  38.             when reset => -- reset
  39.                 B_hold <= "11111111";
  40.                 D_out <= "00000000";
  41.                 data_out <= "00000000";
  42.                 hold <= '1';
  43.                 sample <= '0';
  44.                 eoc <= '0';
  45.                
  46.                 if start = '1' then
  47.                     nx_state <= state1;
  48.                 else
  49.                     nx_state <= reset;
  50.                 end if;
  51.            
  52.             when state1 =>        -- sample
  53.                 B_hold <= "00000000";
  54.                 hold <= '0';
  55.                 sample <= '1';
  56.                 nx_state <= state2;
  57.            
  58.             when state2 =>       -- hold
  59.                 B_hold <= "11111111";
  60.                 D_out <= "00000000";
  61.                 nx_state <= state3;
  62.            
  63.             when state3 =>       -- reset first bit
  64.                 B_hold(7) <= '0';
  65.                 D_out(7) <= '1';
  66.                 data_out(7) <= '1';
  67.                 nx_state <= state4;
  68.            
  69.             when state4 =>       -- check from comparator and set first bit
  70.                 if comp_in = '1' then
  71.                     B_hold(7) <= '0';
  72.                     D_out(7) <= '1';
  73.                     data_out(7) <= '1';
  74.                 else
  75.                     B_hold(7) <= '1';
  76.                     D_out(7) <= '0';
  77.                     data_out(7) <= '0';
  78.                 end if;
  79.                 nx_state <= state5;
  80.            
  81.             when state5 =>     -- reset second bit
  82.                 B_hold(6) <= '0';
  83.                 D_out(6) <= '1';
  84.                 data_out(6) <= '1';
  85.                 nx_state <= state6;
  86.            
  87.             when state6 =>   -- check comparator and set second bit
  88.                 if comp_in = '1' then
  89.                     B_hold(6) <= '0';
  90.                     D_out(6) <= '1';
  91.                     data_out(6) <= '1';
  92.                 else
  93.                     B_hold(6) <= '1';
  94.                     D_out(6) <= '0';
  95.                     data_out(6) <= '0';
  96.                 end if;
  97.                 nx_state <= state7;
  98.            
  99.             when state7 =>     -- reset third bit
  100.                 B_hold(5) <= '0';
  101.                 D_out(5) <= '1';
  102.                 data_out(5) <= '1';
  103.                 nx_state <= state8;
  104.            
  105.             when state8 =>   -- check comparator and set third bit
  106.                 if comp_in = '1' then
  107.                     B_hold(5) <= '0';
  108.                     D_out(5) <= '1';
  109.                     data_out(5) <= '1';
  110.                 else
  111.                     B_hold(5) <= '1';
  112.                     D_out(5) <= '0';
  113.                     data_out(5) <= '0';
  114.                 end if;
  115.                 nx_state <= state9;
  116.                
  117.             when state9 =>     -- reset fourth bit
  118.                 B_hold(4) <= '0';
  119.                 D_out(4) <= '1';
  120.                 data_out(4) <= '1';
  121.                 nx_state <= state10;
  122.            
  123.             when state10 =>  -- check comparator and set fourth bit
  124.                 if comp_in = '1' then
  125.                     B_hold(4) <= '0';
  126.                     D_out(4) <= '1';
  127.                     data_out(4) <= '1';
  128.                 else
  129.                     B_hold(4) <= '1';
  130.                     D_out(4) <= '0';
  131.                     data_out(4) <= '0';
  132.                 end if;
  133.                 nx_state <= state11;
  134.                
  135.             when state11 =>    -- reset fifth bit
  136.                 B_hold(3) <= '0';
  137.                 D_out(3) <= '1';
  138.                 data_out(3) <= '1';
  139.                 nx_state <= state12;
  140.            
  141.             when state12 =>  -- check comparator and set fifth bit
  142.                 if comp_in = '1' then
  143.                     B_hold(3) <= '0';
  144.                     D_out(3) <= '1';
  145.                     data_out(3) <= '1';
  146.                 else
  147.                     B_hold(3) <= '1';
  148.                     D_out(3) <= '0';
  149.                     data_out(3) <= '0';
  150.                 end if;
  151.                 nx_state <= state13;
  152.            
  153.             when state13 =>    -- reset sixth bit
  154.                 B_hold(2) <= '0';
  155.                 D_out(2) <= '1';
  156.                 data_out(2) <= '1';  
  157.                 nx_state <= state14;
  158.            
  159.             when state14 =>  -- check comparator and set sixth bit
  160.                 if comp_in = '1' then
  161.                     B_hold(2) <= '0';
  162.                     D_out(2) <= '1';
  163.                     data_out(2) <= '1';
  164.                 else
  165.                     B_hold(2) <= '1';
  166.                     D_out(2) <= '0';
  167.                     data_out(2) <= '0';
  168.                 end if;
  169.                 nx_state <= state15;
  170.                
  171.             when state15 =>    -- reset seventh bit
  172.                 B_hold(1) <= '0';
  173.                 D_out(1) <= '1';
  174.                 data_out(1) <= '1';
  175.                 nx_state <= state16;
  176.            
  177.             when state16 =>  -- check comparator and set seventh bit
  178.                 if comp_in = '1' then
  179.                     B_hold(1) <= '0';    
  180.                     D_out(1) <= '1';
  181.                     data_out(1) <= '1';
  182.                 else
  183.                     B_hold(1) <= '1';
  184.                     D_out(1) <= '0';
  185.                     data_out(1) <= '0';
  186.                 end if;
  187.                 nx_state <= state17;
  188.                
  189.             when state17 =>    -- reset eighth bit
  190.                 B_hold(0) <= '0';    
  191.                 D_out(0) <= '1';
  192.                 data_out(0) <= '1';
  193.                 nx_state <= state18;
  194.            
  195.             when state18 =>  -- check comparator and set eighth bit
  196.                 if comp_in = '1' then
  197.                     B_hold(0) <= '0';
  198.                     D_out(0) <= '1';
  199.                     data_out(0) <= '1';
  200.                 else
  201.                     B_hold(0) <= '1';
  202.                     D_out(0) <= '0';
  203.                     data_out(0) <= '0';
  204.                 end if;
  205.                 eoc <= '1';
  206.                 nx_state <= reset;
  207.         end case;
  208.     end process;
  209. end state_machine;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement