Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library IEEE;
- use IEEE.STD_LOGIC_1164.ALL;
- use IEEE.NUMERIC_STD.ALL;
- entity LedCounter is
- Port ( clk : in STD_LOGIC;
- rst : in STD_LOGIC;
- button : in STD_LOGIC;
- leds : out STD_LOGIC_VECTOR (7 downto 0));
- end LedCounter;
- architecture Behavioral of LedCounter is
- -- Clocks since the button was last pressed
- signal csp : unsigned(31 downto 0) := (others => '0');
- -- Holds the value that will be assigned to the LEDs
- signal leds_counter : unsigned(leds'range) := (others => '0');
- -- Last sampled value of the button
- signal last_button_value : std_logic := '0';
- begin
- -- Always assign LEDs the value of leds_counter
- leds <= std_logic_vector(leds_counter);
- process(clk, rst)
- begin
- -- clear things
- if(rst = '1') then
- leds_counter <= (others => '0');
- csp <= (others => '0');
- -- Assume the button has not been pressed
- last_button_value <= '0';
- elsif(rising_edge(clk)) then
- -- Check to make sure some time has passed since the button was pressed
- if(csp > 100_000_000 / 5) then
- -- Check to see if the button is on the rising edge
- if(button = '1' and last_button_value = '0') then
- -- Increment the counter and reset the counts since last pressed
- leds_counter <= leds_counter + 1;
- csp <= (others => '0');
- end if;
- else
- -- The max count has not been reached. Increment.
- csp <= csp + 1;
- end if;
- -- Always update the last value signal with the current value
- last_button_value <= button;
- end if;
- end process;
- -- process(clk, rst)
- -- variable c : unsigned(31 downto 0) := (others => '0');
- -- begin
- -- if(rst = '1') then
- -- c := (others => '0');
- -- elsif(rising_edge(clk)) then
- -- if(c > 100_000_000 / 10 and button = '1' and last_button_value = '0') then
- -- leds_counter <= leds_counter + 1;
- -- c := (others => '0');
- -- else
- -- if(c <= 100_000_000 / 4) then
- -- c := c + 1;
- -- end if;
- -- end if;
- -- end if;
- --
- -- last_button_value <= '0';
- -- end process;
- end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement