Advertisement
nex036ara

zmigavac

Nov 29th, 2011
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 7.62 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    20:22:45 11/29/2011
  6. -- Design Name:
  7. -- Module Name:    zmigavac - Behavioral
  8. -- Project Name:
  9. -- Target Devices:
  10. -- Tool versions:
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. ----------------------------------------------------------------------------------
  20. library IEEE;
  21. use IEEE.STD_LOGIC_1164.ALL;
  22. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  23. use IEEE.STD_LOGIC_ARITH.ALL;
  24.  
  25. -- Uncomment the following library declaration if using
  26. -- arithmetic functions with Signed or Unsigned values
  27. --use IEEE.NUMERIC_STD.ALL;
  28.  
  29. -- Uncomment the following library declaration if instantiating
  30. -- any Xilinx primitives in this code.
  31. --library UNISIM;
  32. --use UNISIM.VComponents.all;
  33.  
  34. entity zmigavac is
  35.     Port ( iCLK : in  STD_LOGIC;
  36.            inRST : in  STD_LOGIC;
  37.            iLEFT : in  STD_LOGIC;
  38.            iRIGHT : in  STD_LOGIC;
  39.            iHAZ : in  STD_LOGIC;
  40.            oLEFT : out  STD_LOGIC_VECTOR (2 downto 0);
  41.            oRIGHT : out  STD_LOGIC_VECTOR (2 downto 0));
  42. end zmigavac;
  43.  
  44. architecture Behavioral of zmigavac is
  45. type tSTANJA is (sIDLE, sL1,sL2,sL3,sLR3,sR1,sR2,sR3);
  46. signal sSTANJE,sSLEDECE_STANJE: tSTANJA;
  47. signal sCNT: STD_LOGIC_VECTOR(15 downto 0);
  48. signal sTC: STD_LOGIC;
  49. begin
  50.  
  51.  
  52. ---brojac pola sekunde
  53.     process (iCLK, inRST) begin
  54.                 if(inRST = '0')then
  55.                     sCNT <= (others => '0');
  56.                     elsif (iCLK'event and iCLK = '1')then
  57.                         if(sCNT = x"B71B00") then
  58.                         sCNT <= (others =>'0');
  59.                         else sCNT <= sCNT+1;
  60.                     end if;
  61.                 end if;
  62.             end process;
  63.         sTC<= '1' when (sCNT = x"B71B00") else '0'; ---izlaz komparatora je jedan kada brojac dodje na 0.5s
  64.    
  65. ---opis automata
  66.        
  67.         ---1: kombinaciona mreza koja na osnovu trenutnog stanja i vrednosti ulaza generise kod narednog stanja
  68.         process (iLEFT,iRIGHT,iHAZ, sTC, sSTANJE)begin
  69.            
  70.             case sSTANJE is
  71.            
  72.            
  73.         when sIDLE =>
  74.                 case iLEFT is
  75.                             when '0' =>sSLEDECE_STANJE<=sIDLE;
  76.                             when '1' =>sSLEDECE_STANJE<=sL1;
  77.                             when others => sSLEDECE_STANJE <=sL1;
  78.                 end case;
  79.                
  80.                 case iRIGHT is
  81.                              when '0' =>sSLEDECE_STANJE<=sIDLE;
  82.                             when '1' =>sSLEDECE_STANJE<=sR1;
  83.                             when others => sSLEDECE_STANJE <=sR1;
  84.                 end case;
  85.                
  86.                 case iHAZ is
  87.                             when '0' =>sSLEDECE_STANJE<=sIDLE;
  88.                             when '1' =>sSLEDECE_STANJE<=sLR3;
  89.                             when others => sSLEDECE_STANJE <=sLR3;
  90.             end case;
  91.            
  92.            
  93.         when sL1 =>
  94.                 case sTC is
  95.                         when '0' =>sSLEDECE_STANJE <= sL1;
  96.                         when '1' => sSLEDECE_STANJE<= sL2;
  97.                         when others => sSLEDECE_STANJE <=sL2;
  98.                 end case;
  99.                
  100.                
  101.         when sL2 =>
  102.                     case sTC is
  103.                         when '0' => sSLEDECE_STANJE <= sL2;
  104.                         when '1' => sSLEDECE_STANJE<= sL3;
  105.                         when others => sSLEDECE_STANJE <=sL3;
  106.                     end case;
  107.        
  108.         when sL3 =>
  109.                     case sTC is
  110.                         when '0' => sSLEDECE_STANJE<= sL3;
  111.                         when '1' => sSLEDECE_STANJE<= sIDLE;
  112.                         when others => sSLEDECE_STANJE <=sIDLE;
  113.                     end case;
  114.                    
  115.         when sLR3 =>
  116.                     case sTC is
  117.                         when '0' => sSLEDECE_STANJE<= sLR3;
  118.                         when '1' => sSLEDECE_STANJE<= sLR3;
  119.                         when others => sSLEDECE_STANJE <=sLR3;
  120.                     end case;
  121.                
  122.         when sR1 =>
  123.                     case sTC is
  124.                         when '0' => sSLEDECE_STANJE<= sR1;
  125.                         when '1' =>sSLEDECE_STANJE<= sR2;
  126.                         when others => sSLEDECE_STANJE <=sR2;
  127.                     end case;
  128.                    
  129.         when sR2 =>
  130.                     case sTC is
  131.                         when '0' => sSLEDECE_STANJE<= sR2;
  132.                         when '1' =>sSLEDECE_STANJE<= sR3;
  133.                         when others => sSLEDECE_STANJE <=sR3;
  134.                     end case;
  135.                    
  136.         when sR3 =>
  137.                     case sTC is
  138.                         when '0' =>sSLEDECE_STANJE<= sR3;
  139.                         when '1' => sSLEDECE_STANJE<= sIDLE;
  140.                         when others => sSLEDECE_STANJE <=sIDLE;
  141.                     end case;
  142.                    
  143.             end case;
  144.     end process;
  145.    
  146.    
  147. ---2: kombinaciona mreza za opisivanje vrednosti izlaznog vektora na osnovu trenutnog stanja
  148. ---oLEFT : out  STD_LOGIC_VECTOR (2 downto 0)
  149. ---oRIGHT : out  STD_LOGIC_VECTOR (2 downto 0))
  150.  
  151.         process(sSTANJE)begin --izlaz zavisi samo od stanja
  152.                 case sSTANJE is
  153.                     when sL1=>  oLEFT <= "001"; oRIGHT<="000";
  154.                     when sL2=>  oLEFT <= "011"; oRIGHT<="000";
  155.                     when sL3=> oLEFT <= "111"; oRIGHT<="000";
  156.                    
  157.                     when sR1=> oRIGHT<= "001"; oLEFT<="000";
  158.                     when sR2=> oRIGHT<= "011"; oLEFT<="000";
  159.                     when sR3=> oRIGHT<= "111"; oLEFT<="000";
  160.                    
  161.                     when sLR3=> oLEFT <= "111"; oRIGHT<="111";
  162.                     when sIDLE=> oLEFT <= "000"; oRIGHT<="000";
  163.                 end case;
  164.         end process;
  165.        
  166.        
  167.        
  168. ---3:flip flopovi za smestanje koda trenutnog stanja, postavljanje pocetnog stanja
  169. ---je sinhrono sa signalom takta
  170.  
  171.     process(iCLK)begin
  172.         if(iCLK'event and iCLK='1')then
  173.             if(inRST='0')then
  174.                 sSTANJE <= sIDLE;
  175.             else
  176.                 sSTANJE<=sSLEDECE_STANJE;
  177.             end if;
  178.         end if;
  179.     end process;
  180. end Behavioral;
  181.  
  182.  
  183.  
  184.  
  185. ----tb
  186.  
  187.  
  188.  
  189.  
  190.  
  191. --------------------------------------------------------------------------------
  192. -- Company:
  193. -- Engineer:
  194. --
  195. -- Create Date:   22:25:27 11/29/2011
  196. -- Design Name:  
  197. -- Module Name:   C:/Users/Branislav/Documents/University/Lprs/e13592/test_kodovi/ocena3/tb.vhd
  198. -- Project Name:  ocena3
  199. -- Target Device:  
  200. -- Tool versions:  
  201. -- Description:  
  202. --
  203. -- VHDL Test Bench Created by ISE for module: zmigavac
  204. --
  205. -- Dependencies:
  206. --
  207. -- Revision:
  208. -- Revision 0.01 - File Created
  209. -- Additional Comments:
  210. --
  211. -- Notes:
  212. -- This testbench has been automatically generated using types std_logic and
  213. -- std_logic_vector for the ports of the unit under test.  Xilinx recommends
  214. -- that these types always be used for the top-level I/O of a design in order
  215. -- to guarantee that the testbench will bind correctly to the post-implementation
  216. -- simulation model.
  217. --------------------------------------------------------------------------------
  218. LIBRARY ieee;
  219. USE ieee.std_logic_1164.ALL;
  220.  
  221. -- Uncomment the following library declaration if using
  222. -- arithmetic functions with Signed or Unsigned values
  223. --USE ieee.numeric_std.ALL;
  224.  
  225. ENTITY tb IS
  226. END tb;
  227.  
  228. ARCHITECTURE behavior OF tb IS
  229.  
  230.     -- Component Declaration for the Unit Under Test (UUT)
  231.  
  232.     COMPONENT zmigavac
  233.     PORT(
  234.          iCLK : IN  std_logic;
  235.          inRST : IN  std_logic;
  236.          iLEFT : IN  std_logic;
  237.          iRIGHT : IN  std_logic;
  238.          iHAZ : IN  std_logic;
  239.          oLEFT : OUT  std_logic_vector(2 downto 0);
  240.          oRIGHT : OUT  std_logic_vector(2 downto 0)
  241.         );
  242.     END COMPONENT;
  243.    
  244.  
  245.    --Inputs
  246.    signal iCLK : std_logic := '0';
  247.    signal inRST : std_logic := '0';
  248.    signal iLEFT : std_logic := '0';
  249.    signal iRIGHT : std_logic := '0';
  250.    signal iHAZ : std_logic := '0';
  251.  
  252.     --Outputs
  253.    signal oLEFT : std_logic_vector(2 downto 0);
  254.    signal oRIGHT : std_logic_vector(2 downto 0);
  255.  
  256.    -- Clock period definitions
  257.    constant iCLK_period : time := 10 ns;
  258.  
  259. BEGIN
  260.  
  261.     -- Instantiate the Unit Under Test (UUT)
  262.    uut: zmigavac PORT MAP (
  263.           iCLK => iCLK,
  264.           inRST => inRST,
  265.           iLEFT => iLEFT,
  266.           iRIGHT => iRIGHT,
  267.           iHAZ => iHAZ,
  268.           oLEFT => oLEFT,
  269.           oRIGHT => oRIGHT
  270.         );
  271.  
  272.    -- Clock process definitions
  273.    iCLK_process :process
  274.    begin
  275.         iCLK <= '0';
  276.         wait for iCLK_period/2;
  277.         iCLK <= '1';
  278.         wait for iCLK_period/2;
  279.    end process;
  280.  
  281.  
  282.    -- Stimulus process
  283.    stim_proc: process
  284.    begin       
  285. inRST <= '1';
  286.     iLEFT <= '1';
  287.     iRIGHT<= '0';
  288.     iHAZ<= '0';
  289.     wait for iCLK_period*2;
  290.    
  291.     iLEFT <= '0';
  292.     iRIGHT<= '1';
  293.     iHAZ<= '0';
  294.     wait for iCLK_period*2;
  295.    
  296.     iLEFT <= '0';
  297.     iRIGHT<= '0';
  298.     iHAZ<= '1';
  299.     wait for iCLK_period*2;
  300. inRST <= '0';
  301. wait;
  302.  
  303.    end process;
  304.  
  305. END;
  306.  
  307.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement