三层电梯控制电路设计一. 设计要求1. 每层电梯入口处设有上下请求开关,电梯内设有顾客到达层次的停站请求开关。
2. 设有电梯入口处位置指示装置及电梯运行模式(上升或下降)指示装置。
3. 电梯每秒升(降)一层楼。
4. 电梯到达有停站请求的楼层,经过1秒电梯门打开,开门指示灯亮,开门4秒后,电梯门关闭(开门指示灯灭),电梯继续进行,直至执行完最后一个请求信号后停留在当前层。
5. 能记忆电梯内外所有请求,并按照电梯运行规则按顺序响应,每个请求信号保留至执行后消除。
6. 电梯运行规则一当电梯处于上升模式时,只响应比电梯所在位置高的上楼请求信号,由下而上逐个执行,直到最后一个上楼请求执行完毕;如果高层有下楼请求,则相反。
7. 电梯初始状态为一层开门状态。
二. 设计目的电梯控制器是控制电梯按顾客要求自动上下的装置。
本文采用VHDL语言来设计实用三层电梯控制器,其代码具有良好的可读性和易理解性, 通过对三层电梯控制器的设计,可以发现本设计有一定的扩展性,而且可以作为更多层电梯控制器实现的基础。
三. 控制器的设计方案.控制器的功能模块如图1所示,包括主控制器、分控制器、楼层选择器、状态显示器、译码器和楼层显示器。
乘客在电梯中选择所要到达的楼层,通过主控制器的处理,电梯开始运行,状态显示器显示电梯的运行状态,电梯所在楼层数通过译码器译码从而在楼层显示器中显示。
分控制器把有效的请求传给主控制器进行处理,同时显示电梯的运行状态和电梯所在楼层数。
由于分控制器相对简单很多,所以主控制器是核心部分。
图1. 电梯控制器原理图四. 三层电梯控制器的结构体设计首先说明一下状态。
状态机设置了lO个状态,分别是电梯停留在l层(stoponl)、开门(dooropen)、关门(doorclose)、开门等待第1秒(doorwaitl)、开门等待第2秒(doorwait2)、开门等待第3秒(doorwait3)、开门等待第4秒(doorwait4)、上升(up)、下降(down)和停止(stop)。
在实体说明定义完端口之后,在结构体architecture和begin之间需要有如下的定义语句,来定义状态机。
在结构体中,设计了俩个进程互相配合,一个是状态机进程作为主要进程,另外一个是信号灯控制进程作为辅助进程。
状态机进程中的很多判断条件是以信号灯进程产生的信号灯信号为依据的,而信号灯进程中信号灯的熄灭又是由状态机进程中传出的clearup和cleardn信号来控制。
在状态机进程中,在电梯的上升状态中,通过对信号灯的判断,决定下一个状态是继续上升还是停止;在电梯下降状态中,也是通过对信号灯的判断,决定下一个状态是继续下降还是停止;在电梯停止状态中,判断是最复杂的,通过对信号的判断,决定电梯是上升、下降还是停止。
本设计需要完成的任务是编写VHDL代码来模拟现实中的三层电梯工作。
在点阵上显示电梯所在的楼层,当其它楼层有上或下的请求信号时,表示该楼层上或下的绿色或黄色指示灯亮,电梯开始上或下运行,当到达该楼层时,表示该楼层上或下的绿色或黄色指示灯灭,表示到达该楼层的红色指示灯亮,点阵显示楼层数,红色指示灯灭。
五. vhdl源程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;--------------------------------------------------------------------entity elevator isport( clk : in std_logic; --Clock Signalk1,k2u,k2d,k3 : in std_logic; --Push buttond1,d2u,d2d,d3 : out std_logic; --Led ofevery floordoor1,door2,door3 : buffer std_logic; --doorledr0,r1,r2,r3,r4,r5,r6,r7 : out std_logic; --7 segment driversa,sb,sc : out std_logic); --Display Selectend elevator;-------------------------------------------------------------------- architecture behave of elevator issignal state1,state3 : std_logic;signal state2u,state2d : std_logic;signal doorflag : std_logic;signal udflag,runflag : std_logic; --up and down flag,run flag signal dcount : std_logic_vector(2 downto 0); --display countersignal display : std_logic_vector(7 downto 0);signal location : std_logic_vector(1 downto 0);signal wcount : std_logic_vector(10 downto 0); --wait countersignal doorcount : std_logic_vector(9 downto 0); --door countersignal col1,col2,col3,col4,col5,col6 : std_logic_vector(7 downto 0);beginprocess(clk) -- judge the key is or is not been pushedbeginif(clk'event and clk='1') thenif(k1='0' and door1='0') thenstate1<='1';d1<='1';elsif(location=0 and wcount=0) thend1<='0';if(doorcount=1020) thenstate1<='0';end if;end if;if(k2u='0' and door2='0') thenstate2u<='1';d2u<='1';elsif(location=1 and udflag='1' and wcount=0) thend2u<='0';if(doorcount=1020) thenstate2u<='0';end if;end if;if(k2d='0' and door2='0') thenstate2d<='1';d2d<='1';elsif(location=1 and udflag='0' and wcount=0) thend2d<='0';if(doorcount=1020) thenstate2d<='0';end if;end if;if(k3='0' and door3='0') thenstate3<='1';d3<='1';elsif(location=2 and wcount=0) then d3<='0';if(doorcount=1020) thenstate3<='0';end if;end if;end if;end process;process(clk)beginif(clk'event and clk='1') thenif(location=0) then --display 1 col1<="00000001";col2<="00100001";col3<="01111111";col4<="11111111";col5<="00000001";col6<="00000001";elsif(location=1) then --display 2 col1<="01100011";col2<="11100111";col3<="10001101";col4<="10011001";col5<="11110011";col6<="01100111";elsif(location=2) then --display 3 col1<="01000010";col2<="11011011";col3<="10011001";col4<="10011001";col5<="11111111";col6<="01100110";end if;end if;end process;process(clk) --accumulate dcountbeginif(clk'event and clk='1') thendcount<=dcount+1;end if;end process;process(clk)beginif(clk'event and clk='1') thensa<=dcount(0);sb<=dcount(1);sc<=dcount(2);case dcount iswhen "111"=>display<="00000000";……when others=>display<="00000000";end case;end if;end process;process(clk) --In this process, a,b,c,d,e,f,g and dot will output beginif(clk'event and clk='1') thenr0<=display(7);……r7<=display(0);end if;end process;end behave;注释:1.本程序设计调用了IEEE库,IEEE库是VHDL设计中最为常用的库,它包含有IEEE标准的程序包和其他一些支持工业标准的程序包。