收藏 分销(赏)

基于FPGA三层电梯控制器程序—VHDL.doc

上传人:a199****6536 文档编号:1449268 上传时间:2024-04-27 格式:DOC 页数:5 大小:13.74KB 下载积分:6 金币
下载 相关 举报
基于FPGA三层电梯控制器程序—VHDL.doc_第1页
第1页 / 共5页
基于FPGA三层电梯控制器程序—VHDL.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
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;--三层下降请求端口 fuplight:buffer std_logic_vector(3 downto 1);--上升请求寄存信号 fdnlight:buffer std_logic_vector(3 downto 1);--下降请求寄存信号 stop1button,stop2button,stop3button:in std_logic;--停站请求端口 stoplight:buffer std_logic_vector(3 downto 1);--停站请求寄存信号 position:buffer integer range 1 to 3;--电梯位置信号 doorlight:out std_logic;--开关门信号 udsig:buffer std_logic);--电梯模式(上升或下降)信号 end threelift; architecture art of threelift is--结构体 type lift_state is--定义十个状态 (stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop); signal mylift:lift_state; signal clearup:std_logic;--上升和停站请求清除信号 signal cleardn:std_logic;--下降和停站请求清除信号 begin controlift:process(reset,liftclk)--状态机进程 variable pos:integer range 3 downto 1; begin if reset='1' then mylift <= stopon1;--异步复位,电梯的初始状态为一层开门状态 clearup <= '0'; cleardn <= '0'; pos:=1; position<=1; else if liftclk'event and liftclk='1' then case mylift is when stopon1 => doorlight <= '0'; position <= 1; pos:=1; mylift <= doorwait1;--电梯等待4s when doorwait1 => mylift <=doorwait2; when doorwait2 => clearup<='0'; cleardn<='0'; mylift <=doorwait3; when doorwait3 => mylift <=doorwait4; when doorwait4 => mylift <= doorclose; when doorclose => doorlight <= '1';--关门,判定电梯下一个运行方式 if udsig='0' then--电梯处在上升模式 if position=3 then if stoplight="111" and fuplight="111" and fdnlight="111" then--没有请求信号时,电梯停在当前层 udsig <= '1'; mylift <= doorclose; elsif fdnlight(3)='0' or stoplight(3)='0' then--本层有请求信号是,电梯开门 udsig<='1'; mylift<=dooropen; else --否则下降 udsig<='1'; mylift<=down; end if; elsif position=2 then if stoplight="111" and fuplight="111" and fdnlight="111" then udsig<='0'; mylift<=doorclose; elsif fuplight(2)='0' or stoplight(2)='0' then--本层有上升或停站请求时时,电梯开门 udsig<='0'; mylift<=dooropen; elsif fuplight="111" and stoplight="111" and fdnlight="101" then--只有二层有下降请求时,电梯开门 udsig<='1'; mylift<=dooropen; elsif stoplight(3)='0' or fdnlight(3)='0' then--三层有停站请求或下降请求,则上升 udsig<='0'; mylift<=up; else udsig<='1'; mylift<=down; end if; elsif position=1 then if stoplight="111" and fuplight="111" and fdnlight="111" then udsig<='0'; mylift<=doorclose; elsif stoplight(1)='0' or fuplight(1)='0' then udsig<='0'; mylift<=dooropen; else udsig<='0'; mylift<=up; end if; end if; elsif udsig='1' then--电梯处在下降模式 if position=1 then if stoplight="111" and fuplight="111" and fdnlight="111" then udsig<='0'; mylift<=doorclose; elsif stoplight(1)='0' or fuplight(1)='0' then udsig<='0'; mylift<=dooropen; else udsig<='0'; mylift<=up; end if; elsif position=2 then if stoplight="111" and fuplight="111" and fdnlight="111" then udsig<='1'; mylift<=doorclose; elsif fdnlight(2)='0' or stoplight(2)='0' then udsig<='1'; mylift<=dooropen; elsif fdnlight="111" and stoplight="111" and fuplight="101" then udsig<='0'; mylift<=dooropen; elsif stoplight(1)='0' or fuplight(1)='0' then udsig<='1'; mylift<=down; else udsig<='0'; mylift<=up; end if; elsif position=3 then if stoplight="111" and fuplight="111" and fdnlight="111" then udsig<='1'; mylift<=doorclose; elsif fdnlight(3)='0' or stoplight(3)='0' then udsig<='1'; mylift<=dooropen; else udsig<='1'; mylift<=down; end if; end if; end if; when up=> --电梯处于上升状态 position<=position+1;--电梯楼层数加一 pos:=pos+1; if pos <3 and (stoplight(pos)='0' or fuplight(pos)='0') then mylift <= stop;--电梯在一层或二层,本层有停站或上升请求时,则停止 elsif pos=3 and (stoplight(pos)='0' or fdnlight(pos)='0') then mylift <= stop;--电梯处在三层,并且有三层停站或下降请求,则停止 else mylift <= doorclose; end if; when down =>--电梯处在下降状态 position <=position-1;--电梯楼层数减一 pos:=pos-1; if pos >1 and (stoplight(pos)='0' or fdnlight(pos)='0') then mylift <= stop; elsif pos=1 and (stoplight(pos)='0' or fuplight(pos)='0') then mylift <= stop; else mylift <= doorclose; end if; when stop => mylift <= dooropen; when dooropen => doorlight <= '0'; if udsig='0' then if position<3 and (stoplight(pos)='0' or fuplight(pos)='0') then clearup <= '1'; --清除当前层上升和停站请求 else clearup<='1'; cleardn<='1'; end if; elsif udsig='1' then if position >1 and (stoplight(pos)='0' or fdnlight(pos)='0') then cleardn <= '1';--清除当前层下降和停站请求 else clearup <= '1'; cleardn <= '1'; end if; end if; mylift <= doorwait1; end case; end if; end if; end process controlift; controlight:process(reset,buttonclk) begin if reset='1' then stoplight <= "111"; fuplight <= "111"; fdnlight <= "111"; else if buttonclk'event and buttonclk='1' then if clearup='1' then--上升和停站请求清零 stoplight(position) <= '1'; fuplight(position) <= '1'; else if f1upbutton='1' then --记忆各层上升请求 fuplight(1)<='0'; elsif f2upbutton='1' then fuplight(2)<='0'; end if; end if; if cleardn='1' then stoplight(position) <= '1'; fdnlight(position) <= '1'; else if f2dnbutton='1' then --记忆各层下降请求 fdnlight(2)<='0'; elsif f3dnbutton='1' then fdnlight(3)<='0'; end if; end if; if stop1button='1' then --记忆各层停站请求 stoplight(1)<='0'; elsif stop2button='1' then stoplight(2)<='0'; elsif stop3button='1' then stoplight(3)<='0'; end if; end if; end if; end process controlight; end art;
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服