LIBRARY IEEE;
	USE IEEE.STD_LOGIC_1164.ALL;
	USE IEEE.STD_LOGIC_ARITH.ALL;
	USE IEEE.STD_LOGIC_UNSIGNED.ALL;

ENTITY debounce IS
	PORT	(
				iCLK			:	IN		STD_LOGIC;
				iBUTTON			:	IN		STD_LOGIC;
				oBUTTON			:	OUT		STD_LOGIC
			);

END debounce;

ARCHITECTURE TERASIC OF debounce IS

	SIGNAL	BUTTON0			:	STD_LOGIC;
	SIGNAL	BUTTON1			:	STD_LOGIC;
	SIGNAL	BUTTON2			:	STD_LOGIC;
	SIGNAL	BUTTON3			:	STD_LOGIC;
	SIGNAL	BUTTON4			:	STD_LOGIC;
	SIGNAL	BUTTON5			:	STD_LOGIC;
	SIGNAL	BUTTON6			:	STD_LOGIC;
	SIGNAL	BUTTON7			:	STD_LOGIC;
	SIGNAL	BUTTON8			:	STD_LOGIC;
	SIGNAL	BUTTON9			:	STD_LOGIC;
	SIGNAL	BUTTON10		:	STD_LOGIC;
	SIGNAL	BUTTON11		:	STD_LOGIC;
	SIGNAL	BUTTON12		:	STD_LOGIC;
	SIGNAL	BUTTON13		:	STD_LOGIC;
	SIGNAL	BUTTON14		:	STD_LOGIC;
	SIGNAL	BUTTON15		:	STD_LOGIC;
	SIGNAL	BUTTON16		:	STD_LOGIC;
	SIGNAL	BUTTON17		:	STD_LOGIC;
	SIGNAL	BUTTON18		:	STD_LOGIC;
	SIGNAL	BUTTON19		:	STD_LOGIC;
	SIGNAL	BUTTON20		:	STD_LOGIC;
	SIGNAL	BUTTON21		:	STD_LOGIC;
	SIGNAL	BUTTON22		:	STD_LOGIC;
	SIGNAL	BUTTON23		:	STD_LOGIC;
	SIGNAL	BUTTON24		:	STD_LOGIC;
	SIGNAL	BUTTON25		:	STD_LOGIC;
	SIGNAL	BUTTON26		:	STD_LOGIC;
	SIGNAL	BUTTON27		:	STD_LOGIC;
	SIGNAL	BUTTON28		:	STD_LOGIC;
	SIGNAL	BUTTON29		:	STD_LOGIC;
	SIGNAL	BUTTON30		:	STD_LOGIC;
	SIGNAL	BUTTON31		:	STD_LOGIC;
	SIGNAL	BUTTON32		:	STD_LOGIC;
	SIGNAL	BUTTON33		:	STD_LOGIC;
	SIGNAL	BUTTON34		:	STD_LOGIC;
	SIGNAL	BUTTON35		:	STD_LOGIC;
	SIGNAL	BUTTON36		:	STD_LOGIC;
	SIGNAL	BUTTON37		:	STD_LOGIC;
	SIGNAL	BUTTON38		:	STD_LOGIC;
	SIGNAL	BUTTON39		:	STD_LOGIC;
	SIGNAL	BUTTON40		:	STD_LOGIC;
	SIGNAL	BUTTON41		:	STD_LOGIC;
	SIGNAL	BUTTON42		:	STD_LOGIC;
	SIGNAL	BUTTON43		:	STD_LOGIC;
	SIGNAL	BUTTON44		:	STD_LOGIC;
	SIGNAL	BUTTON45		:	STD_LOGIC;
	SIGNAL	BUTTON46		:	STD_LOGIC;
	SIGNAL	BUTTON47		:	STD_LOGIC;
	SIGNAL	BUTTON48		:	STD_LOGIC;
	SIGNAL	BUTTON49		:	STD_LOGIC;
	SIGNAL	BUTTON50		:	STD_LOGIC;
	SIGNAL	BUTTON51		:	STD_LOGIC;
	SIGNAL	BUTTON52		:	STD_LOGIC;
	SIGNAL	BUTTON53		:	STD_LOGIC;
	SIGNAL	BUTTON54		:	STD_LOGIC;
	SIGNAL	BUTTON55		:	STD_LOGIC;
	SIGNAL	BUTTON56		:	STD_LOGIC;
	SIGNAL	BUTTON57		:	STD_LOGIC;
	SIGNAL	BUTTON58		:	STD_LOGIC;
	SIGNAL	BUTTON59		:	STD_LOGIC;
	SIGNAL	BUTTON60		:	STD_LOGIC;
	SIGNAL	BUTTON61		:	STD_LOGIC;
	SIGNAL	BUTTON62		:	STD_LOGIC;
	SIGNAL	BUTTON63		:	STD_LOGIC;
	
BEGIN

--------------------------------------------------------------------------------
	PROCESS(iCLK)
	BEGIN
		IF iCLK' EVENT AND iCLK = '1' THEN
			BUTTON0		<=	iBUTTON;
			BUTTON1		<=	BUTTON0;
			BUTTON2		<=	BUTTON1;
			BUTTON3		<=	BUTTON2;
			BUTTON4		<=	BUTTON3;
			BUTTON5		<=	BUTTON4;
			BUTTON6		<=	BUTTON5;
			BUTTON7		<=	BUTTON6;
			BUTTON8		<=	BUTTON7;
			BUTTON9		<=	BUTTON8;
			BUTTON10	<=	BUTTON9;
			BUTTON11	<=	BUTTON10;
			BUTTON12	<=	BUTTON11;
			BUTTON13	<=	BUTTON12;
			BUTTON14	<=	BUTTON13;
			BUTTON15	<=	BUTTON14;
			BUTTON16	<=	BUTTON15;
			BUTTON17	<=	BUTTON16;
			BUTTON18	<=	BUTTON17;
			BUTTON19	<=	BUTTON18;
			BUTTON20	<=	BUTTON19;
			BUTTON21	<=	BUTTON20;
			BUTTON22	<=	BUTTON21;
			BUTTON23	<=	BUTTON22;
			BUTTON24	<=	BUTTON23;
			BUTTON25	<=	BUTTON24;
			BUTTON26	<=	BUTTON25;
			BUTTON27	<=	BUTTON26;
			BUTTON28	<=	BUTTON27;
			BUTTON29	<=	BUTTON28;
			BUTTON30	<=	BUTTON29;
			BUTTON31	<=	BUTTON30;
			BUTTON32	<=	BUTTON31;
			BUTTON33	<=	BUTTON32;
			BUTTON34	<=	BUTTON33;
			BUTTON35	<=	BUTTON34;
			BUTTON36	<=	BUTTON35;
			BUTTON37	<=	BUTTON36;
			BUTTON38	<=	BUTTON37;
			BUTTON39	<=	BUTTON38;
			BUTTON40	<=	BUTTON39;
			BUTTON41	<=	BUTTON40;
			BUTTON42	<=	BUTTON41;
			BUTTON43	<=	BUTTON42;
			BUTTON44	<=	BUTTON43;
			BUTTON45	<=	BUTTON44;
			BUTTON46	<=	BUTTON45;
			BUTTON47	<=	BUTTON46;
			BUTTON48	<=	BUTTON47;
			BUTTON49	<=	BUTTON48;
			BUTTON50	<=	BUTTON49;
			BUTTON51	<=	BUTTON50;
			BUTTON52	<=	BUTTON51;
			BUTTON53	<=	BUTTON52;
			BUTTON54	<=	BUTTON53;
			BUTTON55	<=	BUTTON54;
			BUTTON56	<=	BUTTON55;
			BUTTON57	<=	BUTTON56;
			BUTTON58	<=	BUTTON57;
			BUTTON59	<=	BUTTON58;
			BUTTON60	<=	BUTTON59;
			BUTTON61	<=	BUTTON60;
			BUTTON62	<=	BUTTON61;
			BUTTON63	<=	BUTTON62;
		END IF;
	END PROCESS;
	

	oBUTTON	<=	(BUTTON0 or BUTTON1 or BUTTON2 or BUTTON3 or BUTTON4 or BUTTON5 or
				 BUTTON6 or BUTTON7 or BUTTON8 or BUTTON9 or BUTTON10 or BUTTON11 or
				 BUTTON12 or BUTTON13 or BUTTON14 or BUTTON15 or BUTTON16 or BUTTON17 or
				 BUTTON18 or BUTTON19 or BUTTON20 or BUTTON21 or BUTTON22 or BUTTON23 or
				 BUTTON24 or BUTTON25 or BUTTON26 or BUTTON27 or BUTTON28 or BUTTON29 or
				 BUTTON30 or BUTTON31 or BUTTON32 or BUTTON33 or BUTTON34 or BUTTON35 or
				 BUTTON36 or BUTTON37 or BUTTON38 or BUTTON39 or BUTTON40 or BUTTON41 or
				 BUTTON42 or BUTTON43 or BUTTON44 or BUTTON45 or BUTTON46 or BUTTON47 or
				 BUTTON48 or BUTTON49 or BUTTON50 or BUTTON51 or BUTTON52 or BUTTON53 or
				 BUTTON54 or BUTTON55 or BUTTON56 or BUTTON57 or BUTTON58 or BUTTON59 or
				 BUTTON60 or BUTTON61 or BUTTON62 or BUTTON63
				 );
	

--------------------------------------------------------------------------------
END TERASIC;
--------------------------------------------------------------------------------