------------------------------------------------------------------------------------ Company: UCN T&B - IT-Teknolog - Electronics-- Engineer: Ivan & Mads-- -- Create Date: 11:13:55 04/29/2011 -- Design Name: -- Module Name: Rotary - Behavioral -- Project Name: -- Target Devices: -- Tool versions: -- Description: ---- Dependencies: ---- Revision: -- Revision 0.01 - File Created-- Additional Comments: ------------------------------------------------------------------------------------libraryIEEE;useIEEE.STD_LOGIC_1164.ALL;useIEEE.STD_LOGIC_ARITH.ALL;useIEEE.STD_LOGIC_UNSIGNED.ALL;-- Uncomment the following library declaration if using-- arithmetic functions with Signed or Unsigned values--use IEEE.NUMERIC_STD.ALL;-- Uncomment the following library declaration if instantiating-- any Xilinx primitives in this code.--library UNISIM;--use UNISIM.VComponents.all;entity Rotary isPort( rotary_a :instd_logic;
rotary_b :instd_logic;
rotary_press :instd_logic;
clk :instd_logic);end Rotary;architecture Behavioral of Rotary issignal rotary_a_in :std_logic;-- indgang på FPGAsignal rotary_b_in :std_logic;-- indgang på FPGAsignal rotary_press_in :std_logic;-- indgang på FPGAsignal rotary_in :std_logic_vector(1downto0);-- bit kombination af a og bsignal rotary_q1 :std_logic;-- state 1signal rotary_q2 :std_logic;-- state 2signal delay_rotary_q1 :std_logic;--signal rotary_event :std_logic;--signal rotary_left :std_logic;------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Start of circuit description--begin-------------------------------------------------------------------------------------------------------------------------------------- Interface to rotary encoder.-- Detection of movement and direction.-------------------------------------------------------------------------------------------------------------------------------------- The rotary switch contacts are filtered using their offset (one-hot) style to -- clean them. Circuit concept by Peter Alfke.-- Note that the clock rate is fast compared with the switch rate.
rotary_filter:process(clk)beginif clk'eventand clk='1' then--Synchronise inputs to clock domain using flip-flops in input/output blocks.
rotary_a_in <= rotary_a;
rotary_b_in <= rotary_b;
rotary_press_in <= rotary_press;--concatinate rotary input signals to form vector for case construct.
rotary_in <= rotary_b_in & rotary_a_in;case rotary_in iswhen"00"=> rotary_q1 <= '0';
rotary_q2 <= rotary_q2;when"01"=> rotary_q1 <= rotary_q1;
rotary_q2 <= '0';when"10"=> rotary_q1 <= rotary_q1;
rotary_q2 <= '1';when"11"=> rotary_q1 <= '1';
rotary_q2 <= rotary_q2;whenothers=> rotary_q1 <= rotary_q1;
rotary_q2 <= rotary_q2;endcase;endif;endprocess rotary_filter;---- The rising edges of 'rotary_q1' indicate that a rotation has occurred and the -- state of 'rotary_q2' at that time will indicate the direction. --
direction:process(clk)beginif clk'eventand clk='1' then delay_rotary_q1 <= rotary_q1;if rotary_q1='1' and delay_rotary_q1='0' then rotary_event <= '1';
rotary_left <= rotary_q2;else
rotary_event <= '0';
rotary_left <= rotary_left;endif;endif;endprocess direction;end Behavioral;-------- INSPIRATION
led_display:process(clk)beginif clk'eventand clk='1' thenif rotary_event='1' thenif rotary_left='1' then
led_pattern <= led_pattern(6downto0)& led_pattern(7);--rotate LEDs to leftelse
led_pattern <= led_pattern(0)& led_pattern(7downto1);--rotate LEDs to rightendif;endif;-- Pressing the rotary encoder will cause all LED drive bits to be inverted.if rotary_press_in='0' then
led_drive <= led_pattern;else
led_drive <= led_pattern xor"11111111";endif;-- Ouput LED drive to the pins making use of the output flip-flops in input/output blocks.
led <= led_drive;endif;endprocess led_display;
What are you asking exactly, do you want to know about the operation of rotary encoder?
You have included the code in your post without writing anything else, the only question I see in in the title of your post but the code has comments and explains what it does in each part.