Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.42 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:    15:13:26 12/13/2018
  6. -- Design Name:
  7. -- Module Name:    funzionamento - 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_arith.ALL;
  23.  
  24. -- Uncomment the following library declaration if using
  25. -- arithmetic functions with Signed or Unsigned values
  26. use IEEE.NUMERIC_STD.ALL;
  27.  
  28. -- Uncomment the following library declaration if instantiating
  29. -- any Xilinx primitives in this code.
  30. --library UNISIM;
  31. --use UNISIM.VComponents.all;
  32. entity funzionamento is
  33.     Port ( clk : in  STD_LOGIC;
  34.            rst : in  STD_LOGIC;
  35.               timer :in integer range 0 to 31;  
  36.            freq : in  STD_LOGIC;
  37.            p : in  STD_LOGIC;        
  38.               stato_debug :out STD_LOGIC_VECTOR (0 TO 1);
  39.               count_debug : out  std_logic_vector (0 to 4);
  40.               irrigazione : out  STD_LOGIC;
  41.            ugello : out  STD_LOGIC);
  42. end funzionamento;
  43.  
  44. architecture Behavioral of funzionamento is
  45. type state is (off,high,attesa,low);
  46. signal cs,nxs : state;
  47. signal done:std_logic ;
  48. signal stato_contatore : STD_LOGIC_VECTOR (0 TO 1);
  49. component contatore
  50.  Port (    clock: in std_logic;
  51.               reset : in std_logic;
  52.               timex :in integer range 0 to 31;
  53.               stato_corrente : in  std_logic_vector (0 to 1);
  54.               conteggio_debug : out  std_logic_vector (0 to 4);          
  55.               fatto : out std_logic;
  56.               acqua : out std_logic;
  57.               uscita : out std_logic );
  58. end component;
  59.  
  60.  
  61.  
  62. begin
  63. processo_clock :process(clk)
  64.  --ISTANZIO UN CLOCK IN MODO CHE LA FSM FUNZIONI SUL FRONTE DI SALITA (RISING EDGE);
  65. --SEMPRE SU TALE FRONTE AGGIORNO UN CONTATORE CHE MI OCCORRÀ PER ALCUNE TRANSIZIONI DI STATO
  66. begin
  67.     if(rising_edge(clk)) then
  68.        if (rst='1') then cs<=off;
  69.             else cs<=nxs;
  70.        end if;
  71.     end if;
  72. end process;
  73.  
  74.  
  75. funzionamento_stati :process(p,freq,done,cs)
  76. begin
  77. --DESCRIVO IL COMPORTAMENTO DELLA MACCHINA ,
  78. -- SPECIFICANDO LE TRANSIZIONI CHE AVVENGONO IN BASE
  79. -- ALLA VARIAZIONE DI'P' , DI 'freq' E DI 'done'
  80.  
  81. case cs is
  82. when off =>
  83.  --STATO INIZIALE IN CUI LA MACCHINA È SPENTA
  84.  --O ARRIVA DOPO AVER TERMINATO IL PROPRIO CICLO DI FUNZIONAMENTO
  85.       if (done = '0') then
  86.       if (p='1' and freq='1' ) then nxs<=high;
  87.       elsif (p='1' and freq ='0' ) then nxs<=low;
  88.       else nxs<=off;
  89.       end if;
  90.       else nxs<=off;
  91.       end if;
  92.       stato_debug<=conv_std_logic_vector(state'POS(cs),2);
  93.       stato_contatore<=conv_std_logic_vector(state'POS(cs),2);
  94.      
  95. when high =>
  96. --FREQUENZA DI FUNZIONAMENTO ALTA,IN CUI L'IMPIANTO EROGA ACQUA
  97. -- AD INTERVALLI PIÙ RAVVICINATI
  98.      if (done= '0') then
  99.       if( p='1' and freq = '1' ) then nxs<=high;
  100.       elsif (p='0' and freq='0' ) then nxs<=attesa;
  101.       elsif (p='0' and freq='1' )  then nxs<=attesa;
  102.       elsif (p='1' and freq ='0' ) then nxs<=low;
  103.       else nxs<=off;
  104.       end if;
  105.       else nxs<=off;
  106.       end if;
  107.      stato_debug<=conv_std_logic_vector(state'POS(cs),2);
  108.       stato_contatore<=conv_std_logic_vector(state'POS(cs),2);
  109.      
  110.  
  111. when attesa => 
  112. --STATO DI PAUSA , IN CUI LA MACCHINA BLOCCA IL CONTATORE E L'EROGAZIONE DELL'ACQUA
  113.     if (done= '0') then
  114.       if( p='1' and freq = '1'  ) then nxs<=high;
  115.       elsif (p='0' and freq='0') then nxs<=attesa;
  116.       elsif (p='0' and freq='1')  then nxs<=attesa;
  117.       elsif (p='1' and freq ='0') then nxs<=low;
  118.       else nxs<=off;
  119.       end if;
  120.       else nxs<=off;
  121.       end if;
  122.      stato_debug<=conv_std_logic_vector(state'POS(cs),2);
  123.      stato_contatore<=conv_std_logic_vector(state'POS(cs),2);
  124.  
  125.      
  126. when low =>
  127.  --FREQUENZA DI FUNZIONAMENTO BASSA,IN CUI L'IMPIANTO EROGA ACQUA
  128.  --PIÙ LENTAMENTE RISPETTO ALLO STATO 'high'
  129.     if (done= '0') then
  130.       if( p='1' and freq = '1' ) then nxs<=high;
  131.       elsif (p='0' and freq='0') then nxs<=attesa;
  132.       elsif (p='0' and freq='1' )  then nxs<=attesa;
  133.       elsif (p='1' and freq ='0') then nxs<=low;
  134.       else nxs<=off;
  135.       end if;
  136.       else nxs<=off;
  137.       end if;
  138.      stato_debug<=conv_std_logic_vector(state'POS(cs),2);
  139.      stato_contatore<=conv_std_logic_vector(state'POS(cs),2);
  140.      
  141. end case;
  142. end process;
  143.  
  144. I0 : contatore port map ( clk,rst,timer,stato_contatore,count_debug,done,irrigazione,ugello);
  145.  
  146. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement