-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_handler.vhd
More file actions
156 lines (131 loc) · 5.75 KB
/
Copy pathrequest_handler.vhd
File metadata and controls
156 lines (131 loc) · 5.75 KB
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
154
155
156
------------------------------------------------------------------------
-- request_handler.vhd
-- 三层电梯请求寄存与调度模块
--
-- 功能: 接收消抖后的按键脉冲,寄存请求,响应清除信号
-- 标准: VHDL-93, Quartus II 9.1 兼容
-- 风格: 双进程(时序寄存器 + 组合逻辑)
-- 复位: 异步低电平有效 (rst_n)
------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity request_handler is
port(
clk_100hz : in std_logic; -- 100Hz 扫描时钟(请求寄存用)
rst_n : in std_logic; -- 异步复位(低电平有效)
-- 消抖后的按键脉冲输入(单周期脉冲,active high)
btn_up1_edge : in std_logic; -- 1楼上行按键脉冲
btn_up2_edge : in std_logic; -- 2楼上行按键脉冲
btn_dn2_edge : in std_logic; -- 2楼下行按键脉冲
btn_dn3_edge : in std_logic; -- 3楼下行按键脉冲
btn_go1_edge : in std_logic; -- 轿厢去1楼按键脉冲
btn_go2_edge : in std_logic; -- 轿厢去2楼按键脉冲
btn_go3_edge : in std_logic; -- 轿厢去3楼按键脉冲
-- 来自 elevator_ctrl 的清除信号和状态
clear_req : in std_logic_vector(2 downto 0); -- 到达楼层后清除对应请求
current_floor : in std_logic_vector(1 downto 0); -- 当前楼层
-- 输出到 elevator_ctrl 的请求状态
req_up : out std_logic_vector(2 downto 0); -- 上行请求 [1F, 2F, 未用]
req_dn : out std_logic_vector(2 downto 0); -- 下行请求 [未用, 2F, 3F]
req_go : out std_logic_vector(2 downto 0); -- 轿厢目标 [1F, 2F, 3F]
any_request : out std_logic -- 任意请求有效标志
);
end entity request_handler;
architecture rtl of request_handler is
---------------------------------------------------------------
-- 请求寄存器
-- req_up_reg: 上行外呼 (0)=1楼上行 (1)=2楼上行 (2)=未用恒为0
-- req_dn_reg: 下行外呼 (0)=未用恒为0 (1)=2楼下行 (2)=3楼下行
-- req_go_reg: 轿厢内选 (0)=去1楼 (1)=去2楼 (2)=去3楼
---------------------------------------------------------------
signal req_up_reg : std_logic_vector(2 downto 0);
signal req_dn_reg : std_logic_vector(2 downto 0);
signal req_go_reg : std_logic_vector(2 downto 0);
begin
---------------------------------------------------------------
-- 输出连接
---------------------------------------------------------------
req_up <= req_up_reg;
req_dn <= req_dn_reg;
req_go <= req_go_reg;
---------------------------------------------------------------
-- any_request: 所有请求位的 OR(组合逻辑)
---------------------------------------------------------------
any_request <= req_up_reg(0) or req_up_reg(1) or
req_dn_reg(1) or req_dn_reg(2) or
req_go_reg(0) or req_go_reg(1) or req_go_reg(2);
---------------------------------------------------------------
-- 时序进程: 请求寄存器更新
-- 置位: 按键脉冲到来时置1(使用 clk_100hz 与消抖模块同域捕获边沿)
-- 清除: clear_req 对应位有效时清0(清除优先于置位)
-- 约束: req_up(2) 恒为0, req_dn(0) 恒为0
---------------------------------------------------------------
process(clk_100hz, rst_n)
begin
if rst_n = '0' then
-- 复位清空所有请求
req_up_reg <= "000";
req_dn_reg <= "000";
req_go_reg <= "000";
elsif rising_edge(clk_100hz) then
-------------------------------------------------------
-- 上行请求寄存器
-------------------------------------------------------
-- req_up(0): 1楼上行
if clear_req(0) = '1' then
-- 到达1楼,清除1楼上行请求(清除优先)
req_up_reg(0) <= '0';
elsif btn_up1_edge = '1' then
-- 按键脉冲置位(允许同楼层请求,用于重新开门)
req_up_reg(0) <= '1';
end if;
-- req_up(1): 2楼上行
if clear_req(1) = '1' then
req_up_reg(1) <= '0';
elsif btn_up2_edge = '1' then
req_up_reg(1) <= '1';
end if;
-- req_up(2): 未使用,始终为0(3楼不可能有上行请求)
req_up_reg(2) <= '0';
-------------------------------------------------------
-- 下行请求寄存器
-------------------------------------------------------
-- req_dn(0): 未使用,始终为0(1楼不可能有下行请求)
req_dn_reg(0) <= '0';
-- req_dn(1): 2楼下行
if clear_req(1) = '1' then
req_dn_reg(1) <= '0';
elsif btn_dn2_edge = '1' then
req_dn_reg(1) <= '1';
end if;
-- req_dn(2): 3楼下行
if clear_req(2) = '1' then
req_dn_reg(2) <= '0';
elsif btn_dn3_edge = '1' then
req_dn_reg(2) <= '1';
end if;
-------------------------------------------------------
-- 轿厢内选请求寄存器
-------------------------------------------------------
-- req_go(0): 去1楼
if clear_req(0) = '1' then
req_go_reg(0) <= '0';
elsif btn_go1_edge = '1' then
req_go_reg(0) <= '1';
end if;
-- req_go(1): 去2楼
if clear_req(1) = '1' then
req_go_reg(1) <= '0';
elsif btn_go2_edge = '1' then
req_go_reg(1) <= '1';
end if;
-- req_go(2): 去3楼
if clear_req(2) = '1' then
req_go_reg(2) <= '0';
elsif btn_go3_edge = '1' then
req_go_reg(2) <= '1';
end if;
end if;
end process;
end architecture rtl;