Forum Discussion
Altera_Forum
Honored Contributor
13 years agoHello,
I made a simplest program for hex counter it supposed to count push-button clicks. It present the result on a single 7seg display and 4 LEDs, unfortunately I've got a bouncing problem. I'm using a Altera Cyclone II BAIXUN ASK2CB dev. board it has on board push-button Can you please suggest how can i debounce it, so the bits go one by one? Here is my code: ======================================== library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity test is port (Y : out std_logic_vector (6 downto 0); -- 7 seg digit B : out std_logic; pb : in std_logic; count : out std_logic_vector(3 downto 0); reset :in std_logic ); end entity test; architecture Behavioral of test is signal c: std_logic_vector(3 downto 0) :=(others => '0'); --initializing count to zero. begin counting: process(pb,reset) is begin if rising_edge (pb) then if(c = "1111") then -- when count reaches its maximum(that is 15) reset it to 0 c <="0000"; end if; c <= c+'1'; --increment count at every positive edge of clk. end if; if(reset='0') then --when reset equal to '0' make count equal to 0. c <=(others => '0'); -- c ="0000" end if; case c is when "0000"=>Y<="1000000";-- 0 when "0001"=>Y<="1111001";-- 1 when "0010"=>Y<="0100100";-- 2 when "0011"=>Y<="0110000";-- 3 when "0100"=>Y<="0011001";-- 4 when "0101"=>Y<="0010010";-- 5 when "0110"=>Y<="0000010";-- 6 when "0111"=>Y<="1111000";-- 7 when "1000"=>Y<="0000000";-- 8 when "1001"=>Y<="0010000";-- 9 when "1010"=>Y<="0001000";-- A when "1011"=>Y<="0000011";-- b when "1100"=>Y<="1000110";-- C when "1101"=>Y<="0100001";-- d when "1110"=>Y<="0000110";-- E when "1111"=>Y<="0001110";-- F when others=>Y<="1111111";-- in other cases balnk end case; end process counting; B<='0'; count<=c; end architecture Behavioral; ==========================================