您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 电子设计/PCB > 基于FPGA三层电梯控制器程序—VHDL
libraryieee;--库的说明useieee.std_logic_1164.all;--程序包的说明useieee.std_logic_unsigned.all;useieee.std_logic_arith.all;entitythreeliftis--实体port(buttonclk:instd_logic;--按键时钟信号liftclk:instd_logic;--电梯时钟信号reset:instd_logic;--异步复位端口f1upbutton:instd_logic;--一层上升请求端口f2upbutton:instd_logic;--二层上升请求端口f2dnbutton:instd_logic;--二层下降请求端口f3dnbutton:instd_logic;--三层下降请求端口fuplight:bufferstd_logic_vector(3downto1);--上升请求寄存信号fdnlight:bufferstd_logic_vector(3downto1);--下降请求寄存信号stop1button,stop2button,stop3button:instd_logic;--停站请求端口stoplight:bufferstd_logic_vector(3downto1);--停站请求寄存信号position:bufferintegerrange1to3;--电梯位置信号doorlight:outstd_logic;--开关门信号udsig:bufferstd_logic);--电梯模式(上升或下降)信号endthreelift;architectureartofthreeliftis--结构体typelift_stateis--定义十个状态(stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop);signalmylift:lift_state;signalclearup:std_logic;--上升和停站请求清除信号signalcleardn:std_logic;--下降和停站请求清除信号begincontrolift:process(reset,liftclk)--状态机进程variablepos:integerrange3downto1;beginifreset='1'thenmylift=stopon1;--异步复位,电梯的初始状态为一层开门状态clearup='0';cleardn='0';pos:=1;position=1;elseifliftclk'eventandliftclk='1'thencasemyliftiswhenstopon1=doorlight='0';position=1;pos:=1;mylift=doorwait1;--电梯等待4swhendoorwait1=mylift=doorwait2;whendoorwait2=clearup='0';cleardn='0';mylift=doorwait3;whendoorwait3=mylift=doorwait4;whendoorwait4=mylift=doorclose;whendoorclose=doorlight='1';--关门,判定电梯下一个运行方式ifudsig='0'then--电梯处在上升模式ifposition=3thenifstoplight=111andfuplight=111andfdnlight=111then--没有请求信号时,电梯停在当前层udsig='1';mylift=doorclose;elsiffdnlight(3)='0'orstoplight(3)='0'then--本层有请求信号是,电梯开门udsig='1';mylift=dooropen;else--否则下降udsig='1';mylift=down;endif;elsifposition=2thenifstoplight=111andfuplight=111andfdnlight=111thenudsig='0';mylift=doorclose;elsiffuplight(2)='0'orstoplight(2)='0'then--本层有上升或停站请求时时,电梯开门udsig='0';mylift=dooropen;elsiffuplight=111andstoplight=111andfdnlight=101then--只有二层有下降请求时,电梯开门udsig='1';mylift=dooropen;elsifstoplight(3)='0'orfdnlight(3)='0'then--三层有停站请求或下降请求,则上升udsig='0';mylift=up;elseudsig='1';mylift=down;endif;elsifposition=1thenifstoplight=111andfuplight=111andfdnlight=111thenudsig='0';mylift=doorclose;elsifstoplight(1)='0'orfuplight(1)='0'thenudsig='0';mylift=dooropen;elseudsig='0';mylift=up;endif;endif;elsifudsig='1'then--电梯处在下降模式ifposition=1thenifstoplight=111andfuplight=111andfdnlight=111thenudsig='0';mylift=doorclose;elsifstoplight(1)='0'orfuplight(1)='0'thenudsig='0';mylift=dooropen;elseudsig='0';mylift=up;endif;elsifposition=2thenifstoplight=111andfuplight=111andfdnlight=111thenudsig='1';mylift=doorclose;elsiffdnlight(2)='0'orstoplight(2)='0'thenudsig='1';mylift=dooropen;elsiffdnlight=111andstoplight=111andfuplight=101thenudsig='0';mylift=dooropen;elsifstoplight(1)='0'orfuplight(1)='0'thenudsig='1';mylift=down;elseudsig='0';mylift=up;endif;elsifposition=3thenifstoplight=111andfuplight=111andfdnlight=111thenudsig='1';mylift=doorclose;elsiffdnlight(3)='0'orstoplight(3)='0'thenudsig='1';mylift=dooropen;elseudsig='1';mylift=down;endif;endif;endif;whenup=--电梯处于上升状态position=position+1;--电梯楼层数加一pos:=pos+1;ifpos3and(stoplight(pos)='0'orfuplight(pos)='0')thenmylift=stop;--电梯在一层或二层,本层有停站或上升请求时,则停止elsifpos=3and(stoplight(pos)='0'orfdnlight(pos)='0')thenmylift=stop;--电梯处在三层,并且有三层停站或下降请求,则停止elsemylift=doorclose;endif;whendown=--电梯处在下降状态position=position-1;--电梯楼层数减一pos:=pos-1;ifpos1and(stoplight(pos)='0'orfdnlight(pos)='0')thenmylift=stop;elsifpos=1and(stoplight(pos)='0'orfuplight(pos)='0')thenmylift=stop;elsemylift=doorclose;endif;whenstop=mylift=dooropen;whendooropen=doorlight='0';ifudsig='0'thenifposition3and(stoplight(pos)='0'orfuplight(pos)='0')thenclearup='1';--清除当前层上升和停站请求elseclearup='1';cleardn='1';endif;elsifudsig='1'thenifposition1and(stoplight(pos)='0'orfdnlight(pos)='0')thencleardn='1';--清除当前层下降和停站请求elseclearup='1';cleardn='1';endif;endif;mylift=doorwait1;endcase;endif;endif;endprocesscontrolift;controlight:process(reset,buttonclk)beginifreset='1'thenstoplight=111;fuplight=111;fdnlight=111;elseifbuttonclk'eventandbuttonclk='1'thenifclearup='1'then--上升和停站请求清零stoplight(position)='1';fuplight(position)='1';elseiff1upbutton='1'then--记忆各层上升请求fuplight(1)='0';elsiff2upbutton='1'thenfuplight(2)='0';endif;endif;ifcleardn='1'thenstoplight(position)='1';fdnlight(position)='1';elseiff2dnbutton='1'then--记忆各层下降请求fdnlight(2)='0';elsiff3dnbutton='1'thenfdnlight(3)='0';endif;endif;ifstop1button='1'then--记忆各层停站请求stoplight(1)='0';elsifstop2button='1'thenstoplight(2)='0';elsifstop3button='1'thenstoplight(3)='0';endif;endif;endif;endprocesscontrolight;endart;
本文标题:基于FPGA三层电梯控制器程序—VHDL
链接地址:https://www.777doc.com/doc-7308899 .html