三层电梯控制系统的实验设计指导老师:***学生:马小娟班级:电科092学号:*********三层电梯控制系统的设计第一节设计要求要求用FPGA设计实现一个3层电梯的控制系统。
系统的要求如下:(1)电梯运行规则:当电梯处在上升模式时,只响应比电梯所在位置高的上楼请求,由下向上逐个执行,直到最后一个上楼请求执行完毕。
如果高层有下楼请求,直接升到有下楼请求的最高楼层,然后进入下降模式。
电梯处在下降模式时,工作方式与上升模式相反。
设电梯共有3层,每秒上升或下降一层。
(2)电梯初始状态为一层,处在开门状态,开门指示灯亮。
(3)每层电梯入口处均设有上下请求开关,电梯内部设有乘客到达楼层的停站请求开关及其显示。
(4)设置电梯所处位置的指示及电梯上升或下降的指示。
(5)电梯到达有停站请求的楼层后,电梯门打开,开门指示灯亮。
开门4妙后,电梯门关闭,开门指示灯灭,电梯继续运行,直至执行完最后一个请求信号后停在当前层。
(6)电梯控制系统能记忆电梯内外的请求信号,并按照电梯运行规则工作,每个请求信号执行完毕后清除。
第二节三层电梯控制系统的功能模块及流程图电梯控制器的功能模块如图2.1所示,包括主控制器、分控制器、楼层选择器、状态显示器、译码器和楼层显示器。
乘客在电梯中选择所要到达的楼层,通过主控制器的处理,电梯开始运行,状态显示器显示电梯的运行状态,电梯所在楼层数通过译码器译码从而在楼层显示器中显示。
分控制器把有效的请求传给主控制器进行处理,同时显示电梯的运行状态和电梯所在楼层数。
由于分控制器相对简单很多,所以主控制器是核心部分。
图2.1 电梯控制器原理图第三节三层电梯控制器的具体设计本设计尝试用硬件描述语言VHDL来实现对三层电梯的控制,源程序经A1tera公司的MAX+plus II软件仿真,保证了设计的正确性。
使用VHDL进行电梯控制器的设计,主要就是对电梯软件部分的设计,使用VHDL中的逻辑关系建立电梯的升降模式,开门,关门达到动作,而外部器件的硬件设备基本上保持不变。
使用VHDL硬件描述语言设计电梯控制器可以为电梯实现智能控制奠定基础。
一三层电梯控制器实现的功能及运行规则①电梯一层入口处设有上升请求开关,二层入口处设有上、下请求开关,三层入口处设有下降请求开关,电梯内部设有顾客到达楼层的停站请求开关。
②每层电梯入口处设有位置指示装置及电梯运行模式 (上升或下降)指示装置。
③电梯初始状态为一层开门状态。
④电梯每秒上升(下降)一层楼。
⑤电梯到达需要停止的楼层,经过1秒电梯门打开,开门指示灯亮,开门4秒后,电梯门关闭(开门指示灯灭),电梯继续运行,直至执行完最后一个请求信号后停留在当前层。
⑥电梯需要寄存器来记忆电梯内外所有请求,并按照电梯运行规则按顺序响应,每个请求信号保留至执行后消除。
⑦电梯的运行规则:当电梯处于上升模式时,只响应比电梯所在位置高的上楼请求信号和停站请求信号,由下而上逐个执行,直到最后一个上楼请求执行完毕;如果高层有下楼请求,则直接上升到有下楼请求的最高层,然后进入下降模式。
当电梯处于下降模式时则与上升模式相反。
二三层电梯控制器的综合设计1三层电梯控制器的设计思路电梯控制器设计两个进程相互配合,状态机进程作为主要进程,信号灯控制进程作为辅助进程。
根据电梯的实际工作情况,可以为状态机设置十个状态,它们分别是“电梯停在一层”“开门”“关门”“开门等待第一秒”“开门等待第二秒”“开门等待第三秒”“开门等待第四秒”“上升”“下降”和“停止”。
由于电梯每秒上升或下降一层,则可以用周期为1s的信号来作为电梯状态转换的触发时钟。
状态机进程中的很多判断条件是以信号灯控制进程产生的信号灯信号为依据,而信号灯控制进程中信号灯的熄灭又是由状态机进程中传出的信号来控制。
三层电梯控制器的设计主要是对实体和结构体的设计,它的VHDL描述模块流程如图3.1所示:图3.1 三层电梯控制器的VHDL描述模块流程2实体设计实体设计即是对端口名、端口模式及数据类型的说明。
首先考虑输入端口,一个异步复位端口“reset”,用于当电梯出现非正常情况时回到初始状态;在电梯外部,一层入口处设有上升请求端,二层入口处设有上升和下降请求端,三层入口处设有下降请求端;在电梯内部,应设有各层停站请求端口;一个电梯时钟输入端口,它提供周期为1s的时钟信号,用作电梯状态转换的触发时钟;还有一个频率很高的按键时钟输入端口。
其次考虑输出端口,当有各层上升或下降请求时,各层入口处应该有端口显示请求是否被响应,有请求时端口输出逻辑‘1’,被执行后则恢复成逻辑‘0’;同样的,电梯内部也应有各层停站请求是否被响应的指示端口;一个开关门指示端口,当门开着时,它为逻辑‘1’,门关着时,则为逻辑‘0’;还需要端口来显示电梯所处的位置和模式(上升或下降)。
3结构体设计在结构体中,首先说明了状态机设置的十个状态,分别是:电梯停在1层(stopon1)、开门(dooropen)、关门(doorclose)、开门等待第1秒(doorwait1)、开门等待第2秒(doorwait2)、开门等待第3秒(doorwait3)、开门等待第4秒(doorwait4)、上升(up)、下降(down)和停止(stop)。
在结构体最前端用如下的定义语句,来定义状态机。
type lift_state is(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,u p,down,stop);接着描述电梯内部功能实现,在结构体中设计了两个进程,一个状态机进程(ctrlift),它是以reset和liftclk作为敏感信号,控制电梯的状态转移;另外一个是信号灯控制进程(ctrlight),它是以reset和buttonclk作为敏感信号,控制寄存信号的逻辑值。
在状态机进程中,电梯关门后根据信号灯的情况,来决定下一个状态是上升、下降还是停止;在信号灯控制进程中,由于使用了专门的频率较高的按键时钟,所以使得按键的灵敏度大,但是时钟频率不能过高,否则容易使按键过于灵敏,而信号灯的熄灭是由状态机进程中传出clearup和cleardn信号来控制。
4 VHDL源代码语法的简单说明⑴本程序设计调用了ieee库,ieee库是VHDL设计中最为常用的库,它包含有ieee标准的程序包和其他一些支持工业标准的程序包。
本设计采用std-logic-1164、std-logic-unsigned、std-logic-arith程序包。
⑵以关键词entity引导,end entity threelift结尾的部分是程序的实体部分。
VHDL的实体描述了电路器件的外部情况,本设计定义了关于三层电梯控制器用到的各类时钟、异步复位按键、信号灯指示端口、电梯的请求端口。
它描述了端口模式主要有in、buffer、out,以及各端口信号的数据类型主要有std-logic、std-logic-vector、integer。
(3)以关键词architecture引导,end architecture one结尾的语句部分是结构体部分,结构体描述电路器件的内部逻辑功能。
5 VHDL源代码根据主模块中3个进程的工作原理和状态机设计流程编写的主模块VHDL程序如下:library ieee; --库的说明use ieee.std_logic_1164.all; --程序包的说明use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity threelift is --实体port(buttonclk:in std_logic; --按键时钟信号liftclk:in std_logic; --电梯时钟信号reset:in std_logic; --异步复位端口f1upbutton:in std_logic; --一层上升请求端口f2upbutton:in std_logic; --二层上升请求端口f2dnbutton:in std_logic; --二层下降请求端口f3dnbutton:in std_logic; --三层下降请求端口stop1button:in std_logic; --一层停站请求端口stop2button:in std_logic; --二层停站请求端口stop3button:in std_logic; --三层停站请求端口position:buffer integer range 1 to 3; --电梯位置信号udsig:buffer std_logic; --电梯模式(上升或下降)信号fuplight,fdnlight,stoplight:buffer std_logic_vector(3 downto 1);--上升、下降、停站请求寄存信号doorlight:out std_logic; --开关门信号dout1:out std_logic_vector(3 downto 0));end entity threelift;architecture one of threelift is --结构体type lift_state is --定义十个状态(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,u p,down,stop);signal mylift:lift_state;signal clearup:std_logic; --上升和停站请求清除信号signal cleardn:std_logic; --下降和停站请求清除信号beginctrlift:process(reset,liftclk) --状态机进程variable pos:integer range 3 downto 1;beginif reset='1' then --异步复位,电梯的初始状态为一层开门状态mylift<=stopon1;clearup<='0';cleardn<='0';elseif liftclk'event and liftclk='1' thencase mylift iswhen stopon1=>doorlight<='1';position<=1;pos:=1;mylift<=doorwait1; --电梯等待4swhen doorwait1=>mylift<=doorwait2;when doorwait2=>clearup<='0';cleardn<='0';mylift<=doorwait3;when doorwait3=>mylift<=doorwait4;when doorwait4=>mylift<=doorclose;when doorclose=> --关门,判定电梯下一个运行方式doorlight<='0';if udsig='1' then --电梯处在上升模式if position=3 thenif fuplight="000" and fdnlight="000" and stoplight="000" then --没有请求信号时,电梯停在当前层udsig<='0';mylift<=doorclose;elsif fdnlight(3)='1' or stoplight(3)='1' then --本层有请求信号是,电梯开门udsig<='0';mylift<=dooropen;else --否则下降udsig<='0';mylift<=down;end if;elsif position=2 thenif fuplight="000" and fdnlight="000" andstoplight="000" thenudsig<='1';mylift<=doorclose;elsif fuplight(2)='1' or stoplight(2)='1' then--本层有上升或停站请求时时,电梯开门udsig<='1';mylift<=dooropen;elsif fuplight="000" and stoplight="000" andfdnlight="010" then --只有二层有下降请求时,电梯开门udsig<='0';mylift<=dooropen;elsif stoplight(3)='1' or fdnlight(3)='1' then --三层有停站请求或下降请求,则上升udsig<='1';mylift<=up;elseudsig<='0';mylift<=down;end if;elsif position=1 thenif fuplight="000" and fdnlight="000" andstoplight="000" thenudsig<='1';mylift<=doorclose;elsif stoplight(1)='1' or fuplight(1)='1' thenudsig<='1';mylift<=dooropen;elseudsig<='1';mylift<=up;end if;end if;elsif udsig='0' then --电梯处在下降模式if position=3 thenif fuplight="000" and fdnlight="000" andstoplight="000" thenudsig<='0';mylift<=doorclose;elsif fdnlight(3)='1' or stoplight(3)='1' thenudsig<='0';mylift<=dooropen;elseudsig<='0';mylift<=down;end if;elsif position=2 thenif fuplight="000" and fdnlight="000" and stoplight="000" thenudsig<='0';mylift<=doorclose;elsif fdnlight(2)='1' or stoplight(2)='1' thenudsig<='0';mylift<=dooropen;elsif fdnlight="000" and stoplight="000" and fuplight="010" thenudsig<='1';mylift<=dooropen;elsif fuplight(1)='1' or stoplight(1)='1' then--一层有停站请求或上升请求,则下降 udsig<='0';mylift<=down;elseudsig<='1';mylift<=up;end if;elsif position=1 thenif fuplight="000" and fdnlight="000" and stoplight="000" thenudsig<='1';mylift<=doorclose;elsif stoplight(1)='1' or fuplight(1)='1' thenudsig<='1';mylift<=dooropen;elseudsig<='1';mylift<=up;end if;end if;end if;when up=> --电梯处于上升状态position<=position+1; --电梯楼层数加一pos:=pos+1;if pos<3 and (stoplight(pos)='1' or fuplight(pos)='1') then mylift<=stop;--电梯在一层或二层,本层有停站或上升请求时,则停止 elsif pos=3 and (stoplight(pos)='1' or fdnlight(pos)='1') thenmylift<=stop;--电梯处在三层,并且有三层停站或下降请求,则停止elsemylift<=doorclose;end if;when down=> --电梯处在下降状态position<=position-1; --电梯楼层数减一pos:=pos-1;if pos>1 and (stoplight(pos)='1' and fdnlight(pos)='1') then mylift<=stop;elsif pos=1 and (stoplight(pos)='1' or fuplight(pos)='1') thenmylift<=stop;elsemylift<=doorclose;end if;when stop=>mylift<=dooropen;when dooropen=>doorlight<='1';if udsig='1' thenif position<3 and (fuplight(pos)='1' or stoplight(pos)='1') thenclearup<='1'; --清除当前层上升和停站请求elseclearup<='1';cleardn<='1';end if;elsif udsig='0' thenif position>1 and (fdnlight(pos)='1' or stoplight(pos)='1') thencleardn<='1'; --清除当前层下降和停站请求 elseclearup<='1';cleardn<='1';end if;end if;mylift<=doorwait1;end case;end if;end if;end process ctrlift;ctrlight:process(reset,buttonclk) --信号灯控制进程beginif reset='1' then --复位,寄存信号清零fuplight<="000";fdnlight<="000";stoplight<="000";elseif buttonclk'event and buttonclk='1' thenif clearup='1' then --上升和停站请求清零fuplight(position)<='0';stoplight(position)<='0';elseif f1upbutton='1' then --记忆各层上升请求 fuplight(1)<='1';elsif f2upbutton='1' thenfuplight(2)<='1';end if;end if;if cleardn='1' then --下降和停站请求清零fdnlight(position)<='0';stoplight(position)<='0';elseif f2dnbutton='1' then --记忆各层下降请求 fdnlight(2)<='1';elsif f3dnbutton='1' thenfdnlight(3)<='1';end if;end if;if stop1button='1' then --记忆各层停站请求 stoplight(1)<='1';elsif stop2button='1' thenstoplight(2)<='1';elsif stop3button='1' thenstoplight(3)<='1';end if;end if;end if;end process ctrlight;process(position) --楼层显示进程beginif position=1 thendout1<="0001";elsif position=2 thendout1<="0010";elsif position=3 thendout1<="0011";end if;end process;end architecture one;小结本设计运用有限状态机的方法,在结构体最前端首先定义了十个状态;然后在结构体中设计了两个进程,状态机进程作为主要进程,信号灯控制进程作辅助进程。