OpenCores
URL https://opencores.org/ocsvn/z80soc/z80soc/trunk

Subversion Repositories z80soc

[/] [z80soc/] [trunk/] [V0.6/] [S3E/] [rot_ctrl.vhd] - Blame information for rev 40

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 40 rrred
--
2
-- Rotary Control for Spartan 3E Starter Kit
3
-- Adapted to attach to z80soc by:
4
--
5
-- Ronivon C. Costa
6
-- 2008/05/12
7
--
8
-------------------------------------------------------------------------------------------
9
-- Reference design - Rotary encoder and simple LEDs on Spartan-3E Starter Kit (Revision C)
10
--
11
-- Ken Chapman - Xilinx Ltd - November 2005
12
-- Revised 20th February 2006
13
--
14
-- This design demonstrates how to interface to the rotary encoder and simple LEDs.
15
--    At the start, only one LED is on. 
16
--    Turning the rotary encoder to the left or right will cause
17
--    the LED which is on to appear to also move in the corresponding direction.
18
--    Pressing the rotary encoder will invert all LEDs so that only one is off.
19
--
20
-- The design also uses the 50MHz oscillator provided on the board.
21
--
22
-- Instructional value
23
--   Basic VHDL including definition of inputs and outputs.
24
--   UCF (User Constraints File) constraints to define pin assignments to match board.
25
--   UCF constraints to apply pull-up and pull-down resistors to input pins.
26
--   Detecting rotary movement.
27
--   Synchronous design.
28
--
29
------------------------------------------------------------------------------------
30
--
31
-- NOTICE:
32
--
33
-- Copyright Xilinx, Inc. 2006.   This code may be contain portions patented by other 
34
-- third parties.  By providing this core as one possible implementation of a standard,
35
-- Xilinx is making no representation that the provided implementation of this standard 
36
-- is free from any claims of infringement by any third party.  Xilinx expressly 
37
-- disclaims any warranty with respect to the adequacy of the implementation, including 
38
-- but not limited to any warranty or representation that the implementation is free 
39
-- from claims of any third party.  Furthermore, Xilinx is providing this core as a 
40
-- courtesy to you and suggests that you contact all third parties to obtain the 
41
-- necessary rights to use this implementation.
42
--
43
------------------------------------------------------------------------------------
44
--
45
-- Library declarations
46
--
47
-- Standard IEEE libraries
48
--
49
library IEEE;
50
use IEEE.STD_LOGIC_1164.ALL;
51
use IEEE.STD_LOGIC_ARITH.ALL;
52
use IEEE.STD_LOGIC_UNSIGNED.ALL;
53
 
54
ENTITY ROT_CTRL IS
55
        PORT (
56
                CLOCK                           : IN STD_LOGIC;
57
                ROT_A                           : IN STD_LOGIC;
58
                ROT_B                           : IN STD_LOGIC;
59
                DIRECTION               : OUT   STD_LOGIC_VECTOR(1 DOWNTO 0));
60
END ROT_CTRL;
61
 
62
ARCHITECTURE RTL OF ROT_CTRL IS
63
 
64
SIGNAL rotary_in                        : std_logic_vector(1 downto 0);
65
SIGNAL rotary_in_a              : std_logic;
66
SIGNAL rotary_in_b              : std_logic;
67
SIGNAL rotary_q1                        : std_logic;
68
SIGNAL rotary_q2                        : std_logic;
69
SIGNAL delay_rotary_q1  : std_logic;
70
SIGNAL rotary_event             : std_logic;
71
SIGNAL rotary_left              : std_logic;
72
SIGNAL counter                          : std_logic_vector(21 downto 0);
73
 
74
BEGIN
75
--
76
-- Define direction based on rotary movement, and return to processor
77
--
78
  return_dir: process(CLOCK)
79
  begin
80
                if CLOCK'event and CLOCK = '1' then
81
                        if rotary_event='1' then
82
                                if rotary_left='1' then
83
                                        DIRECTION <= "10"; -- Rotating to the left
84
                                        counter <= "0000000000000000000000";
85
                                else
86
                                        DIRECTION <= "01"; -- Rotating to the right
87
                                        counter <= "0000000000000000000000";
88
                                end if;
89
                        else
90
                                if counter = "1111111111111111111111" then
91
                                        DIRECTION <= "00";
92
                                        counter <= "0000000000000000000000";
93
                                else
94
                                        counter <= counter + 1;
95
                                end if;
96
                        end if;
97
                end if;
98
        end process;
99
 
100
  ----------------------------------------------------------------------------------------------------------------------------------
101
  -- Interface to rotary encoder.
102
  -- Detection of movement and direction.
103
  ----------------------------------------------------------------------------------------------------------------------------------
104
  --
105
  -- The rotary switch contacts are filtered using their offset (one-hot) style to  
106
  -- clean them. Circuit concept by Peter Alfke.
107
  -- Note that the clock rate is fast compared with the switch rate.
108
 
109
--
110
-- The rising edges of 'rotary_q1' indicate that a rotation has occurred and the 
111
-- state of 'rotary_q2' at that time will indicate the direction. 
112
--
113
rotary_direction: process(CLOCK)
114
begin
115
        if CLOCK'event and CLOCK='1' then
116
                delay_rotary_q1 <= rotary_q1;
117
                if rotary_q1='1' and delay_rotary_q1='0' then
118
                        rotary_event <= '1';
119
                        rotary_left <= rotary_q2;
120
                else
121
                        rotary_event <= '0';
122
                        rotary_left <= rotary_left;
123
                end if;
124
        end if;
125
end process;
126
 
127
rotary_filter: process(CLOCK)
128
begin
129
        if CLOCK'event and CLOCK='1' then
130
      --Synchronise inputs to clock domain using flip-flops in input/output blocks.             
131
                rotary_in_a <= ROT_A;
132
                rotary_in_b <= ROT_B;
133
                rotary_in <= rotary_in_a & rotary_in_b;
134
 
135
                case rotary_in is
136
                        when "00" =>
137
                                rotary_q1 <= '0';
138
                                rotary_q2 <= rotary_q2;
139
                        when "01" =>
140
                                rotary_q1 <= rotary_q1;
141
                                rotary_q2 <= '0';
142
                        when "10" =>
143
                                rotary_q1 <= rotary_q1;
144
                                rotary_q2 <= '1';
145
                        when "11" =>
146
                                rotary_q1 <= '1';
147
                                rotary_q2 <= rotary_q2;
148
                        when others =>
149
                                rotary_q1 <= rotary_q1;
150
                                rotary_q2 <= rotary_q2;
151
                end case;
152
        end if;
153
end process;
154
 
155
end;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.