Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Hi can somebody tell me how this code count up or shift the LED

Status
Not open for further replies.

Ivan-Holm

Member level 5
Joined
Jun 3, 2010
Messages
84
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Location
Denmark
Activity points
1,894

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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
----------------------------------------------------------------------------------
-- 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: 
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.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 is
    Port (        rotary_a : in std_logic;
                  rotary_b : in std_logic;
              rotary_press : in std_logic;
                       clk : in std_logic);
end Rotary;
 
architecture Behavioral of Rotary is
 
signal      rotary_a_in : std_logic;                    -- indgang på FPGA
signal      rotary_b_in : std_logic;                    -- indgang på FPGA
signal  rotary_press_in : std_logic;                    -- indgang på FPGA
signal        rotary_in : std_logic_vector(1 downto 0); -- bit kombination af a og b
signal        rotary_q1 : std_logic;                    -- state 1
signal        rotary_q2 : std_logic;                    -- state 2
signal  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)
 
 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;
      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 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;
  
  --
  -- 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)
  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;
  
end Behavioral;
 
 
 
-------- INSPIRATION
 
 
  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(6 downto 0) & led_pattern(7); --rotate LEDs to left
         else
          led_pattern <= led_pattern(0) & led_pattern(7 downto 1); --rotate LEDs to right
        end if;
      end if;
 
     
     -- 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";  
      end if;
 
      -- Ouput LED drive to the pins making use of the output flip-flops in input/output blocks.
      led <= led_drive; 
 
    end if;
  end process led_display;

 

It doesnt do any counting that I can see.

Check out lines 134 and 137 for the rotation. Its commented quite well.
 

I know it's shift the LED on the FPGA starter Board I have loadet this code in the Board
 

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.

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top