lgeorge123
Full Member level 2
I have a rotary encoder write in VHDL but this code does not work in real CPLD , output port led do not show any increase in number!
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity left_right_leds is Port ( led : out unsigned(7 downto 0); rotary_a : in std_logic; rotary_b : in std_logic; clk : in std_logic); end left_right_leds; architecture Behavioral of left_right_leds is -- signal rotary_a_in : std_logic; signal rotary_b_in : std_logic; signal rotary_in : std_logic_vector(1 downto 0); signal rotary_q1 : std_logic; signal rotary_q2 : std_logic; signal delay_rotary_q1 : std_logic; signal rotary_event : std_logic; signal rotary_left : std_logic; signal led_pattern : unsigned(7 downto 0):= "10000000"; --initial value puts one LED on near the middle. begin rotary_filter: process(clk) begin if clk'event and 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; --concatinate rotary input signals to form vector for case construct. rotary_in <= rotary_b_in & rotary_a_in; case rotary_in is when "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; when others => rotary_q1 <= rotary_q1; rotary_q2 <= rotary_q2; end case; end if; end process rotary_filter; direction: process(clk) begin if clk'event and 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; end if; end if; end process direction; led_display: process(clk) begin if clk'event and clk='1' then if rotary_event='1' then if rotary_left='1' then led_pattern <= led_pattern+ 1; if led_pattern = 255 then led_pattern <= "11111111"; else led_pattern <= led_pattern - 1; if led_pattern = 0 then led_pattern <= "00000000"; end if; end if; end if; end if; led <= led_pattern ; end if; end process led_display; end Behavioral;
Last edited by a moderator: