Advertisement
Vedro

MA_STOP

May 16th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.21 KB | None | 0 0
  1. library IEEE;                                                       -- zmienić na i := '0' warunek początkowy w sterowaniu
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. entity Stoper is
  5.     Port ( rst_i : in  STD_LOGIC;                                                  
  6.               clk_i : in  STD_LOGIC;                                                    -- 50 MHz
  7.               start_stop_button_i   : in STD_LOGIC := '0';
  8.               an_o    : out STD_LOGIC_VECTOR (3 downto 0);                         
  9.               seg_o  : out STD_LOGIC_VECTOR (7 downto 0));
  10. end Stoper;
  11.  
  12. architecture Behavioral of Stoper is
  13.     signal cyferki : STD_LOGIC_VECTOR (31 downto 0);            -- bez kropek
  14. --  signal wlacznik   : STD_LOGIC := '0';
  15.     signal CLK_dziel : STD_LOGIC;
  16.     signal BTN_stabilny : STD_LOGIC := '0';
  17.     signal BTN_zbocze_nar : STD_LOGIC := '0';  
  18.     signal i : integer range 0 to 3 := 0;
  19.     signal ms1 : integer range 0 to 10000 := 0;
  20.     signal ms10 : integer range 0 to 10 := 0;
  21.     signal ms100 : integer range 0 to 10 := 0;
  22.     signal ms1000 : integer range 0 to 10 := 0;
  23.     signal ms10000 : integer range 0 to 10 := 0;
  24.    
  25.     component dzielnik_czt
  26.         port ( CLK_i : in  STD_LOGIC;
  27.                  RST_i : in  STD_LOGIC;          
  28.                 led7 : out  STD_LOGIC
  29.         );
  30.     end component;
  31.     component eliminator_drg
  32.         port ( CLK_i : in STD_LOGIC;
  33.                  guzik_drg : in STD_LOGIC;
  34.                  guzik_stab : out STD_LOGIC
  35.         );
  36.     end component;
  37.     component wykr_zbocza
  38.         port ( CLK_i : in STD_LOGIC;
  39.                  sygn_wej : in STD_LOGIC;
  40.                  zbocze : out STD_LOGIC
  41.         );
  42.     end component;
  43.     component sterowanie
  44.         port ( CLK_i : in STD_LOGIC;
  45.                  RST_i : in STD_LOGIC;
  46.                  AN : out STD_LOGIC_vector (3 downto 0)
  47.         );
  48.     end component;
  49.    
  50.     function Dekoder (arg: integer) return STD_LOGIC_VECTOR is
  51.         begin
  52.             case arg is                                                                                
  53.                 when 0 => return "0000001"; --0
  54.                 when 1 => return "1001111";   --1
  55.                 when 2 => return "0010010"; --2
  56.                 when 3 => return "0000110"; --3
  57.                 when 4 => return "1001100"; --4
  58.                 when 5 => return "0100100"; --5
  59.                 when 6 => return "0100000"; --6
  60.                 when 7 => return "0001111"; --7
  61.                 when 8 => return "0000000"; --8
  62.                 when 9 => return "0000100"; --9
  63.                 when others => return "1111110";        -- "-"
  64.             end case;
  65.     end function Dekoder;
  66.                  
  67. begin  
  68.     CMP1: dzielnik_czt port map(
  69.                                     CLK_i => clk_i,
  70.                                     RST_i => rst_i,
  71.                                     led7    => CLK_dziel);
  72.     CMP2: eliminator_drg port map(
  73.                                     CLK_i => clk_i,
  74.                                     guzik_drg => start_stop_button_i,
  75.                                     guzik_stab => BTN_stabilny);
  76.     CMP3: wykr_zbocza port map(
  77.                                     CLK_i => clk_i,
  78.                                     sygn_wej => BTN_stabilny,
  79.                                     zbocze => BTN_zbocze_nar);
  80.     CMP4: sterowanie port map(
  81.                                     CLK_i => clk_i,
  82.                                     RST_i => rst_i,
  83.                                     AN => an_o);
  84.                                    
  85. --  Start_stop : process (CLK_i) is
  86. --      begin
  87. --          if rising_edge(CLK_i) then
  88. --              if (BTN_zbocze_nar = '1') then
  89. --                  wlacznik <= not(wlacznik);
  90. --              end if;
  91. --          end if;
  92. --      end process Start_stop;
  93.                        
  94.     Dzialanie : process (CLK_i, CLK_dziel, RST_i) is
  95.     variable wlacznik   : STD_LOGIC := '0';
  96.         begin
  97.             if rising_edge(CLK_i) then
  98.                 if (BTN_zbocze_nar = '1') then
  99.                     wlacznik := not(wlacznik);
  100.                 end if;
  101.             end if;
  102.            
  103.             if (RST_i = '1') then
  104.                 ms1 <= 0;
  105.                 ms10 <= 0;
  106.                 ms100 <= 0;
  107.                 ms1000 <= 0;
  108.                 ms10000 <= 0;
  109.                 wlacznik := '0';
  110.             elsif rising_edge(CLK_dziel) then
  111.                 if (wlacznik = '1') then               
  112.                     ms1 <= ms1 + 1;
  113.                     if (ms1 = 10) then ms10 <= ms10 + 1;    ms1 <= 0;   end if;
  114.                     if (ms10 = 10) then ms100 <= ms100 + 1; ms10 <= 0;  end if;
  115.                     if (ms100 = 10) then ms1000 <= ms1000 + 1;  ms100 <= 0; end if;                    
  116.                     if (ms1000 = 10) then ms10000 <= ms10000 + 1;   ms1000 <= 0;    end if;
  117.                     if ms10000 > 5 then
  118.                         ms10 <= 10;
  119.                         ms100 <= 10;
  120.                         ms1000 <= 10;
  121.                         ms10000 <= 10;
  122.                     end if;
  123.                 end if;
  124.                    
  125.                 case i is
  126.                     when 3 => seg_o <= cyferki(31 downto 24); i <= i - 1;
  127.                     when 2 => seg_o <= cyferki(23 downto 16); i <= i - 1;
  128.                     when 1 => seg_o <= cyferki(15 downto 8);  i <= i - 1;
  129.                     when 0 => seg_o <= cyferki(7 downto 0); i <= 3;                
  130.                 end case;
  131.             end if;
  132.         end process Dzialanie;
  133.        
  134.         cyferki(31 downto 25) <= Dekoder(ms10000);
  135.         cyferki(23 downto 17) <= Dekoder(ms1000);
  136.         cyferki(15 downto 9) <= Dekoder(ms100);
  137.         cyferki(7 downto 1) <= Dekoder(ms10);
  138.         cyferki(0) <= '1';
  139.         cyferki(8) <= '1';
  140.         cyferki(16) <= '0';
  141.         cyferki(24) <= '1';
  142. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement