Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 1.29 KB | None | 0 0
  1. constant COUNT_MAX : integer := 3;
  2. --set it '1' if the button creates a high pulse when its pressed, otherwise '0'.
  3. constant BTN_ACTIVE : std_logic := '1';
  4.  
  5. signal count : integer := 0;
  6. signal count2 : integer := 0;
  7. type state_type is (idle,wait_time); --state machine
  8. signal state : state_type := idle;
  9.  
  10. begin
  11.  
  12. process(Reset,Clk)
  13. begin
  14.     if(Reset = '1') then
  15.         state <= idle;
  16.         pulse_out <= '0';
  17.    elsif(rising_edge(Clk)) then
  18.         case (state) is
  19.             when idle =>
  20.                 if(but_in = BTN_ACTIVE) then  
  21.                     state <= wait_time;
  22.                 else
  23.                     state <= idle;
  24.                            if(count2 = COUNT_MAX) then
  25.                                 count2 <= 0;
  26.                                 pulse_out<='0';
  27.                             else
  28.                                 count2<=count2+1;
  29.                             end if;
  30.                 end if;
  31.                
  32.             when wait_time =>
  33.                 if(count = COUNT_MAX) then
  34.                     count <= 0;
  35.                     if(but_in = BTN_ACTIVE) then
  36.                         pulse_out <= '1';
  37.                           else
  38.                                 pulse_out <= '0';
  39.                     end if;
  40.                           count2<=0;
  41.                     state <= idle;  
  42.                 else
  43.                     count <= count + 1;
  44.                 end if;
  45.         end case;      
  46.     end if;        
  47. end process;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement