-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge_detector.vhd
101 lines (89 loc) · 2.2 KB
/
edge_detector.vhd
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
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 15:51:12 02/20/2012
-- Design Name:
-- Module Name: edge_detector - 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;
-- 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 rotation_detector is
Port ( ROT_A : in STD_LOGIC;
ROT_B : in STD_LOGIC;
CLK : in STD_LOGIC;
CW, CCW : out STD_LOGIC
);
end rotation_detector;
architecture Behavioral of rotation_detector is
type STATES is (idle, cw_state, ccw_state);
signal STATE_REG, STATE_NEXT : STATES;
signal DELAY_A_REG : STD_LOGIC;
signal DB_ROT_A, DB_ROT_B, CW_REG, CW_NEXT, CCW_REG, CCW_NEXT : STD_LOGIC;
signal TICK_A : STD_LOGIC;
begin
DEBOUNCE_A : entity work.db_fsm (arch)
port map(
clk => CLK,
reset => '0',
sw => ROT_A,
db => DB_ROT_A
);
DEBOUNCE_B : entity work.db_fsm (arch)
port map(
clk => CLK,
reset => '0',
sw => ROT_B,
db => DB_ROT_B
);
process(clk)
begin
if(clk'event and clk='1') then
DELAY_A_REG <= DB_ROT_A;
STATE_REG <= STATE_NEXT;
CW_REG <= CW_NEXT;
CCW_REG <= CCW_NEXT;
end if;
end process;
TICK_A <= (not DELAY_A_REG) and DB_ROT_A;
CW <= CW_REG;
CCW <= CCW_REG;
process(CLK, STATE_REG, TICK_A)
begin
CW_NEXT <= '0';
CCW_NEXT <= '0';
STATE_NEXT <= STATE_REG;
case STATE_REG is
when idle =>
if(TICK_A = '1' and DB_ROT_B ='0') then
STATE_NEXT <= cw_state;
elsif(TICK_A = '1' and DB_ROT_B ='1') then
STATE_NEXT <= ccw_state;
end if;
when cw_state =>
CW_NEXT <= '1';
STATE_NEXT <= idle;
when ccw_state =>
CCW_NEXT <= '1';
STATE_NEXT <= idle;
end case;
end process;
end Behavioral;