vhdl奇怪问题,和老师研究半天了,贴出来请大家给看看,两桥箱的电梯控制
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity dianti is
port ( s: in std_logic;
clk_t : in std_logic; --时钟信号(频率为2hz)
full_t1,deng_t1,quick_t1,clr_t1 : in std_logic; --桥箱1超载、关门中断、提前关门清除报警信号
full_t2,deng_t2,quick_t2,clr_t2 : in std_logic; --桥箱2超载、关门中断、提前关门清除报警信号
c_u1_t,c_u2_t,c_u3_t,c_u4_t,c_u5_t : in std_logic; --电梯外人的上升请求信号
c_d2_t,c_d3_t,c_d4_t,c_d5_t,c_d6_t : in std_logic; --电梯外人的下降请求信号
d1_t1,d2_t1,d3_t1,d4_t1,d5_t1,d6_t1 : in std_logic; --桥箱1内人的请求信号
d1_t2,d2_t2,d3_t2,d4_t2,d5_t2,d6_t2 : in std_logic; --桥箱2内人的请求信号
g1_t1,g2_t1,g3_t1,g4_t1,g5_t1,g6_t1 : in std_logic; --桥箱1到达楼层信号
g1_t2,g2_t2,g3_t2,g4_t2,g5_t2,g6_t2 : in std_logic; --桥箱2到达楼层信号
distance_t : in std_logic_vector(1 downto 0); --当前请求楼层与两桥箱距离比较信号
direction_t : in std_logic_vector(1 downto 0); --运动方向信号
door_t1 : out std_logic_vector(1 downto 0); --桥箱1门控制信号
door_t2 : out std_logic_vector(1 downto 0); --桥箱2门控制信号
led_t1 : out std_logic_vector(6 downto 0); --桥箱1所在楼层显示
led_t2 : out std_logic_vector(6 downto 0); --桥箱2所在楼层显示
led_c_ut1 ut std_logic_vector(5 downto 0); --电梯外人上升请求信号显示
led_c_ut2 ut std_logic_vector(5 downto 0); --电梯外人上升请求信号显示
led_c_dt1 ut std_logic_vector(5 downto 0); --电梯外人下降请求信号显示
led_c_dt2 ut std_logic_vector(5 downto 0); --电梯外人下降请求信号显示
led_d_t1 : out std_logic_vector(5 downto 0); --电梯内请求信号显示
led_d_t2 : out std_logic_vector(5 downto 0); --电梯内请求信号显示
wahaha_t1 : out std_logic; --桥箱1看门狗报警信号
wahaha_t2 : out std_logic; --桥箱2看门狗报警信号
ud_t1,alarm_t1 : out std_logic; --桥箱1运动方向显示,超载警告信号
ud_t2,alarm_t2 : out std_logic; --桥箱2运动方向显示,超载警告信号
up_t1,down_t1 : out std_logic; --桥箱1电机控制信号和桥箱1运动
up_t2,down_t2 : out std_logic); --桥箱2电机控制信号和桥箱2运动
end dianti;
architecture behav of dianti is
signal
-- ss:std_logic_vector(3 downto 0);
--signal s: std_logic;
signal c_u11_t1,c_u22_t1,c_u33_t1,c_u44_t1,c_u55_t1:std_logic; --电梯外人上升请求信号寄存信号
signal c_d22_t1,c_d33_t1,c_d44_t1,c_d55_t1,c_d66_t1:std_logic; --电梯外人下降请求信号寄存信号
signal c_u11_t2,c_u22_t2,c_u33_t2,c_u44_t2,c_u55_t2:std_logic; --电梯外人上升请求信号寄存信号
signal c_d22_t2,c_d33_t2,c_d44_t2,c_d55_t2,c_d66_t2:std_logic; --电梯外人下降请求信号寄存信号
signal d11_t1,d22_t1,d33_t1,d44_t1,d55_t1,d66_t1:std_logic; --电梯内人请求信号寄存信号
signal q_t1:integer range 0 to 1; --分频信号
signal q1_t1:integer range 0 to 6; --关门延时计数器
signal q2_t1:integer range 0 to 9; --看门狗计数器
signal dd_t1,cc_u_t1,cc_d_t1,dd_cc_t1:std_logic_vector(5 downto 0); --电梯内外请求信号寄存器
signal opendoor_t1:std_logic; --开门使能信号
signal updown_t1:std_logic; --电梯运动方向信号寄存器
signal en_up_t1,en_dw_t1:std_logic; --预备上升、预备下降预*作使能信号
signal d11_t2,d22_t2,d33_t2,d44_t2,d55_t2,d66_t2:std_logic; --电梯内人请求信号寄存信号
signal q_t2:integer range 0 to 1; --分频信号
signal q1_t2:integer range 0 to 6; --关门延时计数器
signal q2_t2:integer range 0 to 9; --看门狗计数器
signal dd_t2,cc_u_t2,cc_d_t2,dd_cc_t2:std_logic_vector(5 downto 0); --电梯内外请求信号寄存器
signal opendoor_t2:std_logic; --开门使能信号
signal updown_t2:std_logic; --电梯运动方向信号寄存器
signal en_up_t2,en_dw_t2:std_logic; --预备上升、预备下降预*作使能信号
begin
box1:process(clk_t)
begin
if clk_t'event and clk_t='1' then
if clr_t1='1' then q1_t1<=0;q2_t1<=0;wahaha_t1<='0'; --清除故障报警
elsif full_t1='1' then alarm_t1<='1'; q1_t1<=0; --超载报警
if q1_t1>=3 then door_t1<="10";
else door_t1<="00";
end if;
elsif q_t1=1 then q_t1<=0;alarm_t1<='0';
if q2_t1=3 then wahaha_t1<='1'; --故障报警
else
if opendoor_t1='1' then door_t1<="10";q1_t1<=0;q2_t1<=0;up_t1<='0';down_t1<='0'; --开门*作
elsif en_up_t1='1' then --上升预*作
if deng_t1='1' then door_t1<="10";q1_t1<=0;q2_t1<=q2_t1+1; --关门中断
elsif quick_t1='1' then q1_t1<=3; --提前关门
elsif q1_t1=6 then door_t1<="00";updown_t1<='1';up_t1<='1'; --关门完毕,电梯进入上升状态
elsif q1_t1>=3 then door_t1<="01";q1_t1<=q1_t1+1; --电梯进入关门状态
else q1_t1<=q1_t1+1;door_t1<="00"; --电梯进入等待状态
end if;
elsif en_dw_t1='1' then --下降预*作
if deng_t1='1' then door_t1<="10";q1_t1<=0;q2_t1<=q2_t1+1;
elsif quick_t1='1' then q1_t1<=3;
elsif q1_t1=6 then door_t1<="00";updown_t1<='0';down_t1<='1';
elsif q1_t1>=3 then door_t1<="01";q1_t1<=q1_t1+1;
else q1_t1<=q1_t1+1;door_t1<="00";
end if;
end if;
if g1_t1='1' then led_t1<="1001111"; --电梯到达1楼,数码管显示1
if d11_t1='1' or c_u11_t1='1' then d11_t1<='0'; c_u11_t1<='0';opendoor_t1<='1';
--有当前层的请求,则电梯进入开门状态
elsif dd_cc_t1>"000001" then en_up_t1<='1'; opendoor_t1<='0';
--有上升请求,则电梯进入预备上升状态
elsif dd_cc_t1="000000" then opendoor_t1<='0'; --无请求时,电梯停在1楼待机
end if;
elsif g2_t1='1' then led_t1<="0010010"; --电梯到达2楼,数码管显示2
if updown_t1='1' then --电梯前一运动状态位上升
if d22_t1='1' or c_u22_t1='1' then d22_t1<='0'; c_u22_t1<='0'; opendoor_t1<='1';
--有当前层的请求,则电梯进入开门状态
elsif dd_cc_t1>"000011" then en_up_t1<='1'; opendoor_t1<='0';
--有上升请求,则电梯进入预备上升状态
elsif dd_cc_t1<"000010" then en_dw_t1<='1'; opendoor_t1<='0';
--有下降请求,则电梯进入预备下降状态
end if;
--电梯前一运动状态为下降
elsif d22_t1='1' or c_d22_t1='1' then d22_t1<='0'; c_d22_t1<='0';opendoor_t1<='1';
--有当前层的请求,则电梯进入开门状态
elsif dd_cc_t1<"000010" then en_dw_t1<='1'; opendoor_t1<='0';
--有下降请求,则电梯进入预备下降状态
elsif dd_cc_t1>"000011" then en_up_t1<='1'; opendoor_t1<='0';
--有上升请求,则电梯进入预备上升状态
end if;
elsif g3_t1='1' then led_t1<="0000110"; --电梯到达3楼,数码管显示3
if updown_t1='1' then
if d33_t1='1' or c_u33_t1='1' then d33_t1<='0'; c_u33_t1<='0';opendoor_t1<='1';
elsif dd_cc_t1>"000111" then en_up_t1<='1'; opendoor_t1<='0';
elsif dd_cc_t1<"000100" then en_dw_t1<='1'; opendoor_t1<='0';
end if;
elsif d33_t1='1' or c_d33_t1='1' then d33_t1<='0'; c_d33_t1<='0'; opendoor_t1<='1';
elsif dd_cc_t1<"000100" then en_dw_t1<='1'; opendoor_t1<='0';
elsif dd_cc_t1>"000111" then en_up_t1<='1'; opendoor_t1<='0';
end if;
elsif g4_t1='1' then led_t1<="1001100"; --电梯到达4楼,数码管显示4
if updown_t1='1' then
if d44_t1='1' or c_u44_t1='1' then d44_t1<='0'; c_u44_t1<='0'; opendoor_t1<='1';
elsif dd_cc_t1>"001111" then en_up_t1<='1'; opendoor_t1<='0';
elsif dd_cc_t1<"001000" then en_dw_t1<='1'; opendoor_t1<='0';
end if;
elsif d44_t1='1' or c_d44_t1='1' then d44_t1<='0'; c_d44_t1<='0'; opendoor_t1<='1';
elsif dd_cc_t1<"001000" then en_dw_t1<='1'; opendoor_t1<='0';
elsif dd_cc_t1>"001111" then en_up_t1<='1'; opendoor_t1<='0';
end if;
elsif g5_t1='1' then led_t1<="0100100"; --电梯到达5楼,数码管显示5
if updown_t1='1' then
if d55_t1='1' or c_u55_t1='1' then d55_t1<='0'; c_u55_t1<='0';opendoor_t1<='1';
elsif dd_cc_t1>"011111" then en_up_t1<='1'; opendoor_t1<='0';
elsif dd_cc_t1<"010000" then en_dw_t1<='1'; opendoor_t1<='0';
end if;
elsif d55_t1='1' or c_d55_t1='1' then d55_t1<='0'; c_d55_t1<='0';opendoor_t1<='1';
elsif dd_cc_t1<"010000" then en_dw_t1<='1'; opendoor_t1<='0';
elsif dd_cc_t1>"011111" then en_up_t1<='1'; opendoor_t1<='0';
end if;
elsif g6_t1='1' then led_t1<="0100000"; --电梯到达6楼,数码管显示6
if d66_t1='1' or c_d66_t1='1' then d66_t1<='0'; c_d66_t1<='0';opendoor_t1<='1';
elsif dd_cc_t1<"100000" then en_dw_t1<='1'; opendoor_t1<='0';
end if;
else en_up_t1<='0';en_dw_t1<='0'; --电梯进入上升或下降状态
end if;
end if;
else q_t1<=1;alarm_t1<='0'; --清除超载报警
if d1_t1='1' then d11_t1<=d1_t1; --对电梯内人请求信号进行检测和寄存
elsif d2_t1='1' then d22_t1<=d2_t1;
elsif d3_t1='1' then d33_t1<=d3_t1;
elsif d4_t1='1' then d44_t1<=d4_t1;
elsif d5_t1='1' then d55_t1<=d5_t1;
elsif d6_t1='1' then d66_t1<=d6_t1;
end if;
if s='0' then
if c_u1_t='1' then c_u11_t1<=c_u1_t; --对电梯外人上升请求信号进行检测和寄存
elsif c_u2_t='1' then c_u22_t1<=c_u2_t;
elsif c_u3_t='1' then c_u33_t1<=c_u3_t;
elsif c_u4_t='1' then c_u44_t1<=c_u4_t;
elsif c_u5_t='1' then c_u55_t1<=c_u5_t;
end if;
if c_d2_t='1' then c_d22_t1<=c_d2_t; --对电梯外人下降请求信号进行检测和寄存
elsif c_d3_t='1' then c_d33_t1<=c_d3_t;
elsif c_d4_t='1' then c_d44_t1<=c_d4_t;
elsif c_d5_t='1' then c_d55_t1<=c_d5_t;
elsif c_d6_t='1' then c_d66_t1<=c_d6_t;
end if;
end if;
dd_t1<=d66_t1&d55_t1&d44_t1&d33_t1&d22_t1&d11_t1; --电梯内人请求信号并置
cc_u_t1<='0'&c_u55_t1&c_u44_t1&c_u33_t1&c_u22_t1&c_u11_t1; --电梯外人上升请求信号并置
cc_d_t1<=c_d66_t1&c_d55_t1&c_d44_t1&c_d33_t1&c_d22_t1&'0'; --电梯外人下降请求信号并置
dd_cc_t1<=dd_t1 or cc_u_t1 or cc_d_t1; --电梯内、外人请求信号进行综合
end if;
ud_t1<=updown_t1; --电梯运动状态显示
led_d_t1<=dd_t1; --电梯内人请求信号显示
led_c_ut1<=cc_u_t1; --电梯外人上升请求信号显示
led_c_dt1<=cc_d_t1; --电梯外人下降请求信号显示
end if;
end process box1;
box2:process(clk_t)
begin
if clk_t'event and clk_t='1' then
if clr_t2='1' then q1_t2<=0;q2_t2<=0;wahaha_t2<='0'; --清除故障报警
elsif full_t2='1' then alarm_t2<='1'; q1_t2<=0; --超载报警
if q1_t2>=3 then door_t2<="10";
else door_t2<="00";
end if;
elsif q_t2=1 then q_t2<=0;alarm_t2<='0';
if q2_t2=3 then wahaha_t2<='1'; --故障报警
else
if opendoor_t2='1' then door_t2<="10";q1_t2<=0;q2_t2<=0;up_t2<='0';down_t2<='0'; --开门*作
elsif en_up_t2='1' then --上升预*作
if deng_t2='1' then door_t2<="10";q1_t2<=0;q2_t2<=q2_t2+1; --关门中断
elsif quick_t2='1' then q1_t2<=3; --提前关门
elsif q1_t2=6 then door_t2<="00";updown_t2<='1';up_t2<='1'; --关门完毕,电梯进入上升状态
elsif q1_t2>=3 then door_t2<="01";q1_t2<=q1_t2+1; --电梯进入关门状态
else q1_t2<=q1_t2+1;door_t2<="00"; --电梯进入等待状态
end if;
elsif en_dw_t2='1' then --下降预*作
if deng_t2='1' then door_t2<="10";q1_t2<=0;q2_t2<=q2_t2+1;
elsif quick_t2='1' then q1_t2<=3;
elsif q1_t2=6 then door_t2<="00";updown_t2<='0';down_t2<='1';
elsif q1_t2>=3 then door_t2<="01";q1_t2<=q1_t2+1;
else q1_t2<=q1_t1+1;door_t2<="00";
end if;
end if;
if g1_t2='1' then led_t2<="1001111"; --电梯到达1楼,数码管显示1
if d11_t2='1' or c_u11_t2='1' then d11_t2<='0'; c_u11_t2<='0';opendoor_t2<='1';
--有当前层的请求,则电梯进入开门状态
elsif dd_cc_t2>"000001" then en_up_t2<='1'; opendoor_t2<='0';
--有上升请求,则电梯进入预备上升状态
elsif dd_cc_t2="000000" then opendoor_t2<='0'; --无请求时,电梯停在1楼待机
end if;
elsif g2_t2='1' then led_t2<="0010010"; --电梯到达2楼,数码管显示2
if updown_t2='1' then --电梯前一运动状态位上升
if d22_t2='1' or c_u22_t2='1' then d22_t2<='0'; c_u22_t2<='0'; opendoor_t2<='1';
--有当前层的请求,则电梯进入开门状态
elsif dd_cc_t2>"000011" then en_up_t2<='1'; opendoor_t2<='0';
--有上升请求,则电梯进入预备上升状态
elsif dd_cc_t2<"000010" then en_dw_t2<='1'; opendoor_t2<='0';
--有下降请求,则电梯进入预备下降状态
end if;
--电梯前一运动状态为下降
elsif d22_t2='1' or c_d22_t2='1' then d22_t2<='0'; c_d22_t2<='0';opendoor_t2<='1';
--有当前层的请求,则电梯进入开门状态
elsif dd_cc_t2<"000010" then en_dw_t2<='1'; opendoor_t2<='0';
--有下降请求,则电梯进入预备下降状态
elsif dd_cc_t2>"000011" then en_up_t2<='1'; opendoor_t2<='0';
--有上升请求,则电梯进入预备上升状态
end if;
elsif g3_t2='1' then led_t2<="0000110"; --电梯到达3楼,数码管显示3
if updown_t2='1' then
if d33_t2='1' or c_u33_t2='1' then d33_t2<='0'; c_u33_t2<='0';opendoor_t2<='1';
elsif dd_cc_t2>"000111" then en_up_t2<='1'; opendoor_t2<='0';
elsif dd_cc_t2<"000100" then en_dw_t2<='1'; opendoor_t2<='0';
end if;
elsif d33_t2='1' or c_d33_t2='1' then d33_t2<='0'; c_d33_t2<='0'; opendoor_t2<='1';
elsif dd_cc_t2<"000100" then en_dw_t2<='1'; opendoor_t2<='0';
elsif dd_cc_t2>"000111" then en_up_t2<='1'; opendoor_t2<='0';
end if;
elsif g4_t2='1' then led_t2<="1001100"; --电梯到达4楼,数码管显示4
if updown_t2='1' then
if d44_t2='1' or c_u44_t2='1' then d44_t2<='0'; c_u44_t2<='0'; opendoor_t2<='1';
elsif dd_cc_t2>"001111" then en_up_t2<='1'; opendoor_t2<='0';
elsif dd_cc_t2<"001000" then en_dw_t2<='1'; opendoor_t2<='0';
end if;
elsif d44_t2='1' or c_d44_t2='1' then d44_t2<='0'; c_d44_t2<='0'; opendoor_t2<='1';
elsif dd_cc_t2<"001000" then en_dw_t2<='1'; opendoor_t2<='0';
elsif dd_cc_t2>"001111" then en_up_t2<='1'; opendoor_t2<='0';
end if;
elsif g5_t2='1' then led_t2<="0100100"; --电梯到达5楼,数码管显示5
if updown_t2='1' then
if d55_t2='1' or c_u55_t2='1' then d55_t2<='0'; c_u55_t2<='0';opendoor_t2<='1';
elsif dd_cc_t2>"011111" then en_up_t2<='1'; opendoor_t2<='0';
elsif dd_cc_t2<"010000" then en_dw_t2<='1'; opendoor_t2<='0';
end if;
elsif d55_t2='1' or c_d55_t2='1' then d55_t2<='0'; c_d55_t2<='0';opendoor_t2<='1';
elsif dd_cc_t2<"010000" then en_dw_t2<='1'; opendoor_t2<='0';
elsif dd_cc_t2>"011111" then en_up_t2<='1'; opendoor_t2<='0';
end if;
elsif g6_t2='1' then led_t2<="0100000"; --电梯到达6楼,数码管显示6
if d66_t2='1' or c_d66_t2='1' then d66_t2<='0'; c_d66_t2<='0';opendoor_t2<='1';
elsif dd_cc_t2<"100000" then en_dw_t2<='1'; opendoor_t2<='0';
end if;
else en_up_t2<='0';en_dw_t2<='0'; --电梯进入上升或下降状态
end if;
end if;
else q_t2<=1;alarm_t2<='0'; --清除超载报警
if d1_t2='1' then d11_t2<=d1_t2; --对电梯内人请求信号进行检测和寄存
elsif d2_t2='1' then d22_t2<=d2_t2;
elsif d3_t2='1' then d33_t2<=d3_t2;
elsif d4_t2='1' then d44_t2<=d4_t2;
elsif d5_t2='1' then d55_t2<=d5_t2;
elsif d6_t2='1' then d66_t2<=d6_t2;
end if;
if s='1' then
if c_u1_t='1' then c_u11_t2<=c_u1_t; --对电梯外人上升请求信号进行检测和寄存
elsif c_u2_t='1' then c_u22_t2<=c_u2_t;
elsif c_u3_t='1' then c_u33_t2<=c_u3_t;
elsif c_u4_t='1' then c_u44_t2<=c_u4_t;
elsif c_u5_t='1' then c_u55_t2<=c_u5_t;
end if;
if c_d2_t='1' then c_d22_t2<=c_d2_t; --对电梯外人下降请求信号进行检测和寄存
elsif c_d3_t='1' then c_d33_t2<=c_d3_t;
elsif c_d4_t='1' then c_d44_t2<=c_d4_t;
elsif c_d5_t='1' then c_d55_t2<=c_d5_t;
elsif c_d6_t='1' then c_d66_t2<=c_d6_t;
end if;
end if;
dd_t2<=d66_t2&d55_t2&d44_t2&d33_t2&d22_t2&d11_t2; --电梯内人请求信号并置
cc_u_t2<='0'&c_u55_t2&c_u44_t2&c_u33_t2&c_u22_t2&c_u11_t2; --电梯外人上升请求信号并置
cc_d_t2<=c_d66_t2&c_d55_t2&c_d44_t2&c_d33_t2&c_d22_t2&'0'; --电梯外人下降请求信号并置
dd_cc_t2<=dd_t1 or cc_u_t2 or cc_d_t2; --电梯内、外人请求信号进行综合
end if;
ud_t2<=updown_t2; --电梯运动状态显示
led_d_t2<=dd_t2; --电梯内人请求信号显示
led_c_ut2<=cc_u_t2; --电梯外人上升请求信号显示
led_c_dt2<=cc_d_t2; --电梯外人下降请求信号显示
end if;
end process box2;
end behav;
这是从单桥箱扩展的
有s信号控制将电梯外的请求信号给桥箱1还是给2
结果仿真有错
请大家帮忙看看
多谢 |