电梯控制系统说明Clk:时钟信号Reset:复位Open1:一号电梯的开门键Open2:二号电梯的开门键Close1:一号电梯的关门键Close2:二号电梯的关门键Up1_1:一号电梯一楼的上楼按键Up1_2:一号电梯二楼的上楼按键Up2_1:二号电梯一楼的上楼按键Up2_2:二号电梯二楼的上楼按键Down1_2:一号电梯二楼的下楼按键Down1_3:一号电梯三楼的下楼按键Down2_2:二号电梯二楼的下楼按键Down2_3:二号电梯三楼的下楼按键Stop1_1:一号电梯内部的一楼按键Stop1_2:一号电梯内部的二楼按键Stop1_3:一号电梯内部的三楼按键Stop2_1:二号电梯内部的一楼按键Stop2_2:二号电梯内部的二楼按键Stop2_3:二号电梯内部的三楼按键Warn1:一号电梯的报警键Warn2:二号电梯的报警键Floor1:一号电梯的楼层位置Floor2:二号电梯的楼层位置Door_out1:一号电梯门的状态Door_out2:二号电梯门的状态Warn_out1:一号电梯的报警楼层Warn_out2:二号电梯的报警楼层实例说明:一楼先有人要上二楼,然后有另一人从一楼要上三楼,结果两部电梯分别从一楼运行到二楼和三楼停止。
这时,有人在一楼按上楼键,结果显示二楼的电梯下行到一楼。
符合电梯的实际运行规则。
library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity control isport(clk:in std_logic;up1_1,up2_1,up1_2,up2_2,down1_2,down2_2,down1_3,down2_3:in std_logic; stop1_1,stop1_2,stop1_3,stop2_1,stop2_2,stop2_3:in std_logic;warn1,warn2:in std_logic;open1,open2:in std_logic;close1,close2:in std_logic;floor1,floor2:out std_logic_vector(1 downto 0);mode1,mode2:out std_logic_vector(1 downto 0);warn_out1,warn_out2:out std_logic_vector(1 downto 0);reset:in std_logic;wait1:out std_logic;wait2:out std_logic;door_out1,door_out2:out std_logic);end control;architecture behave of control istype state_type is(c1,c2,c3,warn,open_door,wait_time);signal signal_up1,signal_up2:std_logic_vector(2 downto 1);signal signal_down1,signal_down2:std_logic_vector(3 downto 2);signal signal_mode1,signal_mode2:std_logic_vector(1 downto 0);signal signal_floor1,signal_floor2:std_logic_vector(1 downto 0);signal signal_stop1,signal_stop2:std_logic_vector(3 downto 1);signal state_1,state_2:state_type;signal door1,door2:std_logic;signal signal_warn1,signal_warn2:std_logic;signal signal_open1,signal_open2:std_logic:='0';begincon:process(clk)variable a_c1,c_a1:std_logic;variable open_count1:integer;variable a_c2,c_a2:std_logic;variable open_count2:integer;variable pass_time1,pass_time2:integer;variable state_temp1,state_temp2:state_type;beginif clk'event and clk='1' thenif reset='1' thenfloor1<="01";floor2<="01";mode1<="10";mode2<="10";door_out1<='0';door_out2<='0';signal_mode1<="10";signal_mode2<="10";signal_floor1<="01";signal_floor2<="01";state_1<=c1;state_2<=c1;signal_up1<="00";signal_up2<="00";signal_stop1<="000";signal_stop2<="000";signal_down1<="00";signal_down2<="00";door1<='0';door2<='0';signal_warn1<='0';signal_warn2<='0';warn_out1<="00";warn_out2<="00";signal_open1<='0';signal_open2<='0';open_count1:=0;open_count2:=0;pass_time1:=0;pass_time2:=0;a_c1:='0';c_a1:='0';a_c2:='0';c_a2:='0';------------------------------------elseif warn1='1' or warn2='1' thenif warn1='1' thensignal_warn1<='1';end if;if warn2='1' thensignal_warn2<='1';end if;--------------------------------------------------- elseif close1='1' thendoor1<='0';signal_open1<='0';end if;if close2='1' thendoor2<='0';signal_open2<='0';end if;if open1='1' thenopen_count1:=0;if state_1=c1 or state_1=c2 or state_1=c3 or state_1=open_door thensignal_open1<='1';door1<='1';end if;end if;if open2='1' thenopen_count2:=0;if (state_2=c1 or state_2=c2 or state_2=c3 or state_2=open_door) then signal_open2<='1';door2<='1';end if;end if;-------------------------------------------------------if stop1_1='1' thensignal_stop1(1)<='1';end if;if stop1_2='1' thensignal_stop1(2)<='1';end if;if stop1_3='1' thensignal_stop1(3)<='1';end if;if stop2_1='1' thensignal_stop2(1)<='1';end if;if stop2_2='1' thensignal_stop2(2)<='1';end if;if stop2_3='1' thensignal_stop2(3)<='1';end if;--------------------------------------if up1_1='1' or up2_1='1' thenif signal_up1(1)='0' and signal_up2(1)='0' thenif signal_mode1="00" and signal_mode2="00" thenif signal_stop1(2)='1' and signal_stop1(3)/='1' thensignal_up1(1)<='1';elsif signal_stop2(2)='1' and signal_stop2(3)/='1' thensignal_up2(1)<='1';elsif signal_floor1>=signal_floor2 thensignal_up1(1)<='1';elsesignal_up2(1)<='1';end if;end if;if signal_mode1="00" and signal_mode2="01" thensignal_up2(1)<='1';end if;if signal_mode1="00" and signal_mode2="10" thenif signal_stop1(2)='1' and signal_stop1(3)/='1' and signal_floor2="11" thensignal_up1(1)<='1';elsesignal_up2(1)<='1';end if;end if;if signal_mode1="01" and signal_mode2="00" thensignal_up1(1)<='1';end if;if signal_mode1="01" and signal_mode2="01" thenif signal_floor1>=signal_floor2 thensignal_up2(1)<='1';elsesignal_up1(1)<='1';end if;end if;if signal_mode1="01" and signal_mode2="10" thenif signal_floor1>=signal_floor2 thensignal_up2(1)<='1';elsesignal_up1(1)<='1';end if;end if;if signal_mode1="10" and signal_mode2="00" thenif signal_stop2(2)='1' and signal_stop2(3)/='1' and signal_floor1="11" thensignal_up2(1)<='1';elsesignal_up1(1)<='1';end if;end if;if signal_mode1="10" and signal_mode2="01" thenif signal_floor1>=signal_floor2 thensignal_up2(1)<='1';elsesignal_up1(1)<='1';end if;end if;if signal_mode1="10" and signal_mode2="10" thenif signal_floor1>=signal_floor2 thensignal_up2(1)<='1';elsesignal_up1(1)<='1';end if;end if;end if;end if;----------------------------------------------------------------------------------- if up1_2='1' or up2_2='1' thenif signal_up1(2)='0' and signal_up2(2)='0' thenif signal_mode1="00" and signal_mode2="00" thenif signal_floor1>=signal_floor2 thensignal_up2(2)<='1';elsesignal_up1(2)<='1';end if;end if;if signal_mode1="00" and signal_mode2="01" thenif signal_floor2="11" and signal_stop2(1)/='1' thensignal_up2(2)<='1';elsesignal_up1(2)<='1';end if;end if;if signal_mode1="00" and signal_mode2="10" thenif signal_floor1="01" and signal_floor2/="10" thensignal_up1(2)<='1';elsesignal_up2(2)<='1';end if;end if;if signal_mode1="01" and signal_mode2="00" thenif signal_floor1="11" and signal_stop1(1)/='1' thensignal_up1(2)<='1';elsesignal_up2(2)<='1';end if;end if;if signal_mode1="01" and signal_mode2="01" thenif signal_stop1(1)/='1' thensignal_up1(2)<='1';elsif signal_stop2(1)/='1' thensignal_up2(2)<='1';elsif signal_floor1>=signal_floor2 thensignal_up2(2)<='1';elsesignal_up1(2)<='1';end if;end if;if signal_mode1="01" and signal_mode2="10" thenif signal_stop1(1)/='1' and signal_floor1="11" and signal_floor2/="10" thensignal_up1(2)<='1';elsesignal_up2(2)<='1';end if;end if;if signal_mode1="10" and signal_mode2="00" thenif signal_floor2="01" and signal_floor1/="10" thensignal_up2(2)<='1';elsesignal_up1(2)<='1';end if;end if;if signal_mode1="10" and signal_mode2="01" thenif signal_stop2(1)/='1' and signal_floor2="11" and signal_floor1/="10" thensignal_up2(2)<='1';elsesignal_up1(2)<='1';end if;end if;if signal_mode1="10" and signal_mode2="10" thenif signal_floor1="10" thensignal_up1(2)<='1';elsif signal_floor2="10" thensignal_up2(2)<='1';elseend if;end if;end if;end if;------------------------------------------------------------------------------ if down1_3='1' or down2_3='1' thenif signal_down1(3)='0' and signal_down2(3)='0' thenif signal_mode1="00" and signal_mode2="00" thenif signal_floor1>=signal_floor2 thensignal_down1(3)<='1';elsesignal_down2(3)<='1';end if;end if;if signal_mode1="00" and signal_mode2="01" thensignal_down1(3)<='1';end if;if signal_mode1="00" and signal_mode2="10" thenif signal_floor2="01" thensignal_down1(3)<='1';elsesignal_down2(3)<='1';end if;end if;if signal_mode1="01" and signal_mode2="00" thensignal_down2(3)<='1';end if;if signal_mode1="01" and signal_mode2="01" thenif signal_stop1(1)/='1' thensignal_down1(3)<='1';elsif signal_stop2(1)/='1' thensignal_down2(3)<='1';elsif signal_floor1>=signal_floor2 thensignal_down2(3)<='1';elsesignal_down1(3)<='1';end if;end if;if signal_mode1="01" and signal_mode2="10" thenif signal_stop1(1)/='1' and signal_floor2="01" thensignal_down1(3)<='1';elseend if;end if;if signal_mode1="10" and signal_mode2="00" thenif signal_floor1="01" thensignal_down2(3)<='1';elsesignal_down1(3)<='1';end if;end if;if signal_mode1="10" and signal_mode2="01" thenif signal_stop2(1)/='1' and signal_floor1="01" thensignal_down2(3)<='1';elsesignal_down1(3)<='1';end if;end if;if signal_mode1="10" and signal_mode2="10" thenif signal_floor1>=signal_floor2 thensignal_down1(3)<='1';elsesignal_down2(3)<='1';end if;end if;end if;end if;------------------------------------------------------------if down1_2='1' or down2_2='1' thenif signal_down1(2)='0' and signal_down2(2)='0' thenif signal_mode1="00" and signal_mode2="00" thenif signal_stop1(3)/='1' thensignal_down1(2)<='1';elsif signal_stop2(3)/='1' thensignal_down2(2)<='1';elsif signal_floor1>=signal_floor2 thensignal_down1(2)<='1';elsesignal_down2(2)<='1';end if;end if;if signal_mode1="00" and signal_mode2="01" thensignal_down2(2)<='1';end if;if signal_mode1="00" and signal_mode2="10" thenif signal_stop1(3)/='1' and signal_floor2/="10" then signal_down1(2)<='1';elsesignal_down2(2)<='1';end if;end if;if signal_mode1="01" and signal_mode2="00" then if signal_stop2(3)/='1' and signal_floor1/="10" then signal_down2(2)<='1';elsesignal_down1(2)<='1';end if;end if;if signal_mode1="01" and signal_mode2="01" then if signal_floor1="11" thensignal_down1(2)<='1';elsif signal_floor2="11" thensignal_down2(2)<='1';elsesignal_down1(2)<='1';end if;end if;if signal_mode1="01" and signal_mode2="10" then if signal_floor1="11" and signal_floor2/="10" then signal_down1(2)<='1';elsesignal_down2(2)<='1';end if;end if;if signal_mode1="10" and signal_mode2="00" then if signal_stop2(3)/='1' and signal_floor1/="10" then signal_down2(2)<='1';elsesignal_down1(2)<='1';end if;end if;if signal_mode1="10" and signal_mode2="01" then if signal_floor2="11" and signal_floor1/="10" then signal_down2(2)<='1';elsesignal_down1(2)<='1';end if;end if;if signal_mode1="10" and signal_mode2="10" thenif signal_floor1="10" thensignal_down1(2)<='1';elsif signal_floor2="10" thensignal_down2(2)<='1';elsesignal_down1(2)<='1';end if;end if;end if;end if;end if;---------------------------------------------------------------------------if signal_open1='1' thenstate_1<=open_door;end if;if signal_warn1='1' thenstate_1<=warn;end if;if signal_up1="00" and signal_down1="00" and signal_stop1="000" then signal_mode1<="10";door1<='0';end if;if signal_open2='1' thenstate_2<=open_door;end if;if signal_warn2='1' thenstate_2<=warn;end if;if signal_up2="00" and signal_down2="00" and signal_stop2="000" then signal_mode2<="10";door2<='0';end if;case state_1 iswhen c1 =>signal_floor1<="01";signal_mode1<="00";if signal_up1="00" and signal_down1="00" and signal_stop1="000" then signal_mode1<="10";door1<='0';elsesignal_mode1<="00";door1<='0';if signal_stop1(1)='1' or signal_up1(1)='1' thenstate_1<=open_door;signal_open1<='1';signal_stop1(1)<='0';signal_up1(1)<='0';elsif signal_stop1(2)='1' or signal_up1(2)='1' thenstate_temp1:=c2;state_1<=wait_time;elsif signal_stop1(3)='1' thenstate_temp1:=c2;state_1<=wait_time;a_c1:='1';elsif signal_down1(3)='1' thenstate_temp1:=c2;state_1<=wait_time;a_c1:='1';signal_mode1<="01";elsif signal_down1(2)='1' thenstate_temp1:=c2;state_1<=wait_time;signal_mode1<="01";----------------------------------------------------------may be wrong!!!end if;end if;when c2=> signal_floor1<="10";if signal_up1="00" and signal_down1="00" and signal_stop1="000" thensignal_mode1<="10";door1<='0';elseif signal_mode1="00" thenif signal_stop1(2)='1' or signal_up1(2)='1' thenstate_1<=open_door;signal_open1<='1';signal_stop1(2)<='0';signal_up1(2)<='0';elsif signal_stop1(3)='1' or a_c1='1' thenstate_temp1:=c3;state_1<=wait_time;a_c1:='0';elsif signal_down1(2)='1' thenstate_1<=open_door;signal_open1<='1';signal_down1(2)<='0';elsif signal_up1(1)='1' or signal_stop1(1)='1' thenstate_temp1:=c1;state_1<=wait_time;signal_mode1<="01";end if;elseif signal_down1(2)='1' or signal_stop1(2)='1' thenstate_1<=open_door;signal_open1<='1';signal_down1(2)<='0';signal_stop1(2)<='0';elsif signal_up1(1)='1' or signal_stop1(1)='1' or c_a1='1' thenstate_temp1:=c1;state_1<=wait_time;c_a1:='0';elsesignal_mode1<="00";end if;end if;end if;when c3 => signal_floor1<="11";if signal_stop1(3)='1' or signal_down1(3)='1' thenstate_1<=open_door;signal_open1<='1';signal_stop1(3)<='0';signal_down1(3)<='0';elsif signal_stop1(2)='1' or signal_down1(2)='1' thenstate_1<=wait_time;state_temp1:=c2;elsif signal_stop1(1)='1' or signal_up1(1)='1' thenstate_1<=wait_time;state_temp1:=c2;c_a1:='1';elsif signal_up1(2)='1' thenstate_1<=wait_time;state_temp1:=c2;signal_mode1<="00";elsif signal_up1(1)='1' thenstate_1<=wait_time;state_temp1:=c2;signal_mode1<="00";c_a1:='1';end if;when open_door=>if signal_open1='1' thendoor1<='1';if open_count1<3 thenopen_count1:=open_count1+1;elseopen_count1:=0;signal_open1<='0';door1<='0';if signal_floor1="01" thenstate_1<=c1;elsif signal_floor1="10" thenstate_1<=c2;elsif signal_floor1="11" thenstate_1<=c3;end if;end if;elseopen_count1:=0;door1<='0';if signal_floor1="01" thenstate_1<=c1;elsif signal_floor1="10" thenstate_1<=c2;elsif signal_floor1="11" thenstate_1<=c3;end if;end if;when warn=> warn_out1<=signal_floor1;signal_mode1<="11";door1<='1';signal_stop1<="000";signal_up1<="00";signal_down1<="00";--if no_warn1='1' then--signal_warn1<='0';--warn_out1<="00";--if signal_floor1="01" then--state_1<=c1;--elsif signal_floor1="10" then--state_1<=c2;--elsif signal_floor1="11" then--state_1<=c3;--end if;--else-- signal_warn1<='1';-- end if;when wait_time=>if warn1='1' thenstate_1<=warn;elseif pass_time1<5 thenwait1<='1';state_1<=wait_time;pass_time1:=pass_time1+1;elsewait1<='0';pass_time1:=0;state_1<=state_temp1;if state_temp1=c1 thensignal_floor1<="01";elsif state_temp1=c2 thensignal_floor1<="10";elsif state_temp1=c3 thensignal_floor1<="11";end if;end if;end if;end case;--------------------------------------------------------------------------------------------------- case state_2 iswhen c1 => signal_floor2<="01";signal_mode2<="00";if signal_up2="00" and signal_down2="00" and signal_stop2="000" then signal_mode2<="10";door2<='0';elsesignal_mode2<="00";door2<='0';if signal_stop2(1)='1' or signal_up2(1)='1' thenstate_2<=open_door;signal_open2<='1';signal_stop2(1)<='0';signal_up2(1)<='0';elsif signal_stop2(2)='1' or signal_up2(2)='1' thenstate_temp2:=c2;state_2<=wait_time;elsif signal_stop2(3)='1' thenstate_temp2:=c2;state_2<=wait_time;a_c2:='1';elsif signal_down2(3)='1' thenstate_temp2:=c2;state_2<=wait_time;a_c2:='1';signal_mode2<="01";elsif signal_down2(2)='1' thenstate_temp2:=c2;state_2<=wait_time;signal_mode2<="01";----------------------------------------------------------may be wrong!!!end if;end if;when c2=> signal_floor2<="10";if signal_up2="00" and signal_down2="00" and signal_stop2="000" thensignal_mode2<="10";door2<='0';elseif signal_mode2="00" thenif signal_stop2(2)='1' or signal_up2(2)='1' thenstate_2<=open_door;signal_open2<='1';signal_stop2(2)<='0';signal_up2(2)<='0';elsif signal_stop2(3)='1' or a_c2='1' thenstate_temp2:=c3;state_2<=wait_time;a_c2:='0';elsif signal_down2(2)='1' thenstate_2<=open_door;signal_open2<='1';signal_down2(2)<='0';elsif signal_up2(1)='1' or signal_stop2(1)='1' thenstate_temp2:=c1;state_2<=wait_time;signal_mode2<="01";end if;elseif signal_down2(2)='1' or signal_stop2(2)='1' thenstate_2<=open_door;signal_open2<='1';signal_down2(2)<='0';signal_stop2(2)<='0';elsif signal_up2(1)='1' or signal_stop2(1)='1' or c_a2='1' thenstate_temp2:=c1;state_2<=wait_time;c_a2:='0';elsesignal_mode2<="00";end if;end if;end if;when c3 => signal_floor2<="11";if signal_stop2(3)='1' or signal_down2(3)='1' thenstate_2<=open_door;signal_open2<='1';signal_stop2(3)<='0';signal_down2(3)<='0';elsif signal_stop2(2)='1' or signal_down2(2)='1' thenstate_2<=wait_time;state_temp2:=c2;elsif signal_stop2(1)='1' or signal_up2(1)='1' thenstate_2<=wait_time;state_temp2:=c2;c_a2:='1';elsif signal_up2(2)='1' thenstate_2<=wait_time;state_temp2:=c2;signal_mode2<="00";elsif signal_up2(1)='1' thenstate_2<=wait_time;state_temp2:=c2;signal_mode2<="00";c_a2:='1';end if;when open_door=>if signal_open2='1' thendoor2<='1';if open_count2<3 thenopen_count2:=open_count2+1;state_2<=open_door;elseopen_count2:=0;signal_open2<='0';door2<='0';if signal_floor2="01" thenstate_2<=c1;elsif signal_floor2="10" thenstate_2<=c2;elsif signal_floor2="11" thenstate_2<=c3;end if;end if;elseopen_count2:=0;door2<='0';if signal_floor2="01" thenstate_2<=c1;elsif signal_floor2="10" thenstate_2<=c2;elsif signal_floor2="11" thenstate_2<=c3;end if;end if;when warn=> warn_out2<=signal_floor2;signal_mode2<="11";door2<='1';signal_stop2<="000";signal_up2<="00";signal_down2<="00";--if no_warn2='1' then--signal_warn2<='0';--warn_out2<="00";--if signal_floor2="01" then--state_2<=c1;--elsif signal_floor2="10" then--state_2<=c2;--elsif signal_floor2="11" then--state_2<=c3;--end if;-- else--signal_warn2<='1';--end if;when wait_time=>if pass_time2<5 thenwait2<='1';state_2<=wait_time;pass_time2:=pass_time2+1;elsewait2<='0';pass_time2:=0;state_2<=state_temp2;if state_temp2=c1 thensignal_floor2<="01";elsif state_temp2=c2 thensignal_floor2<="10";elsif state_temp2=c3 thensignal_floor2<="11";end if;end if;end case;end if;floor1<=signal_floor1;floor2<=signal_floor2;mode1<=signal_mode1;mode2<=signal_mode2;door_out1<=door1;door_out2<=door2;end if;end process con;end behave;。