2022年2022年基于VHDL的四层电梯控制器

上传人:公**** 文档编号:567337893 上传时间:2024-07-20 格式:PDF 页数:19 大小:340.99KB
返回 下载 相关 举报
2022年2022年基于VHDL的四层电梯控制器_第1页
第1页 / 共19页
2022年2022年基于VHDL的四层电梯控制器_第2页
第2页 / 共19页
2022年2022年基于VHDL的四层电梯控制器_第3页
第3页 / 共19页
2022年2022年基于VHDL的四层电梯控制器_第4页
第4页 / 共19页
2022年2022年基于VHDL的四层电梯控制器_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《2022年2022年基于VHDL的四层电梯控制器》由会员分享,可在线阅读,更多相关《2022年2022年基于VHDL的四层电梯控制器(19页珍藏版)》请在金锄头文库上搜索。

1、1 四层电梯控制器姓名:徐志聪学号:030902529 指导老师:赵彦敏名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 19 页 - - - - - - - - - 2 实验目的:1、掌握更复杂的 VHDL 设计。2、掌握状态机设计方法。实验环境:EP1C3适配板、装有 Quartusii软件的 PC机一台。实验原理:电梯控制器的功能模块如下图所示,包括主控制器、分控制器、楼层选择器、状态显示器、译码器和楼层显示器。乘客在电梯中选择所要到达的楼层,通过主控制器的处理,电梯

2、开始运行, 状态显示器显示电梯的运行状态,电梯所在楼层数通过译码器译码从而在楼层显示器中显示。分控制器把有效的请求传给主控制器进行处理, 同时显示电梯的运行状态和电梯所在楼层数。由于分控制器相对简单很多,所以主控制器是核心部分。电梯控制器原理图状态显示器主控制器楼层选择器分控制器译码器楼层显示器名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 19 页 - - - - - - - - - 3 外部按键请求信号寄存器状态寄存器内部软件执行机构外部硬件执行机构图 2.2 总流程

3、图初始化判定电梯运行方向是否有请求?等待电梯运行楼层检测否电梯停止目标层与本层是否同层?是是否目标层?开门延时关门是否停止运行?是否是否是否停止图 2.3 电梯控制主流程图名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 19 页 - - - - - - - - - 4 四层电梯控制器实现的功能及运行规则:1 电梯一层入口处设有上升请求开关,二三层入口处设有上、 下请求开关,四层入口处设有下降请求开关,电梯内部设有顾客到达楼层的停站请求开关。2 每层电梯入口处设有位置指示装

4、置及电梯运行模式 ( 上升或下降 )指示装置。3 电梯初始状态为一层开门状态。4 电梯每秒上升 (下降) 一层楼。5 电梯到达需要停止的楼层,经过1秒电梯门打开,开门指示灯亮,开门4 秒后,电梯门关闭 (开门指示灯灭 ) ,电梯继续运行,直至执行完最后一个请求信号后停留在当前层。6 电梯需要寄存器来记忆电梯内外所有请求,并按照电梯运行规则按顺序响应,每个请求信号保留至执行后消除。7 电梯的运行规则:当电梯处于上升模式时,只响应比电梯所在位置高的上楼请求信号和停站请求信号,由下而上逐个执行, 直到最后一个上楼请求执行完毕;如果高层有下楼请求, 则直接上升到有下楼请求的最高层,然后进入下降模式。当

5、电梯处于下降模式时则与上升模式相反。四层电梯控制器的设计思路:电梯控制器设计两个进程相互配合,状态机进程作为主要进程, 信号灯控制进程作为辅助进程。 根据电梯的实际工作情况,可以为状态机设置十个状态,它们分别是“电梯停在一层” “开门”“关门”“开门等待第一秒” “开门等待第二秒”“开门等待第三秒”“开门等待第四秒”“上升”“下降”和“停止”。由于电梯每秒上升或下降一层,则可以用周期为1s的信号来作为电梯状态转换的触发时钟。状态机进程中的很多判断条件是以信号灯控制进程产生的信号灯信号为依据,而信号灯控制进程中信号灯的熄灭又是由状态机进程中传出的信号来控制。四层电梯控制器的设计主要是对实体和结构

6、体的设计,它的VHDL 描述模块流程如图 3.1 所示:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 19 页 - - - - - - - - - 5 VHDL源代码说明:library IEEE; -库的说明use IEEE.std_logic_1164.all; -程序包的说明use IEEE.std_logic_unsigned.all; use IEEE.std_logic_arith.all; -(arith) entity fourlift is -实体名称

7、 fourlift port(clk1:in std_logic; -按键读取时钟信号clk2:in std_logic; -led_7 数码管显示扫描时钟信号reset:in std_logic; - 异步复位端口close:in std_logic; - 关门请求f1upbutton:in std_logic; - 一层上升请求端口f2upbutton:in std_logic; - 二层上升请求端口f2dnbutton:in std_logic; - 二层下降请求端口f3dnbutton:in std_logic; - 三层下降请求端口f3upbutton:in std_logic; -

8、 三层上升请求端口f4dnbutton:in std_logic; - 四层下降请求端口stop1button:in std_logic; - 一层停站请求端口stop2button:in std_logic; - 二层停站请求端口元件库的说明定义实体结构体端口状态机进程信号灯控制进程结束按键信号灯图 3.1 四层电梯控制器的 VHDL 描述模块流程名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 19 页 - - - - - - - - - 6 stop3button:i

9、n std_logic; -三层停站请求端口stop4button:in std_logic; -四层停站请求端口stair:buffer integer range 1 to 4; -电梯位置信号udsig:buffer std_logic; -电梯运行模式(上升1 或下降 0 fuplight,fdnlight,stoplight:buffer std_logic_vector(4 downto 1); -上升、下降、停站请求寄存信号doorlight:out std_logic; -开门状态( 1为开门状态)dout:out std_logic_vector(6 downto 0); -

10、 数码管显示楼层段码s:out std_logic_vector(2 downto 0); -数码管显示楼层位码end entity fourlift; architecture chi of fourlift is -结构体type lift_state is - 定 义 十 个 状 态(stop_on_1,door_open,door_close,door_wait1,door_wait2,door_wait3,door_wait4,up,down,stop); signal state:lift_state; signal clr_up:std_logic; -上升和停站请求清除信号si

11、gnal clr_dn:std_logic; -下降和停站请求清除信号signal q:std_logic_vector(3 downto 0); -分频进程中需要的信号signal buttonclk,liftclk:std_logic; -分频后的电梯时钟和按键读取控制时钟begin clklift:process(clk1) -分频产生电梯控制时钟liftclk和按键读取控制时钟buttonclk begin if (clk1event and clk1=1) then if q=1111 then q=0000; else q=q+1; end if; end if; buttoncl

12、k=q(0); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 19 页 - - - - - - - - - 7 liftclk=q(3); end process clklift; statelift:process(reset,liftclk) -状态机进程variable position:integer range 4 downto 1; begin if reset=1 then -异步复位,电梯的初始状态为一层开门状态state=stop_on_1; clr_

13、up=0; clr_dn doorlight=1; -开门stair=1; position:=1; state clr_up=0; clr_dn=0; if(close=1) then state=door_close;- 如果有关门信号,则转至关门状态else state if(close=1) then state=door_close; else state 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 19 页 - - - - - - - - - 8 if(c

14、lose=1) then state=door_close; else state state -关门, 判定电梯下一个运行方式doorlight=0; if udsig=1 then -电梯处在上升模式if stair=4 then if fuplight=0000 and fdnlight=0000 and stoplight=0000 then -没有请求信号时,电梯停在当前层udsig=0; state=door_close; elsif fdnlight(4)=1 or stoplight(4)=1 then -本层有请求信号时,电梯开门udsig=0; - 转为下降state=do

15、or_open; else -否则下降udsig=0; state=down; end if; elsif stair=3 then if fuplight=0000 and fdnlight=0000 and stoplight=0000 then udsig=1; state=door_close; elsif fuplight(3)=1 or stoplight(3)=1 then -本层有上升或停站请求时,电梯开门udsig=1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - -

16、第 8 页,共 19 页 - - - - - - - - - 9 state=door_open; elsif fuplight=0000 and stoplight=0000 and fdnlight=0100 then - 只有 3 层有下降请求时,电梯开门udsig=0; state=door_open; elsif stoplight(4)=1 or fdnlight(4)=1 then -4 层有停站请求或下降请求,则上升udsig=1; state=up; else udsig=0; state=down; end if; elsif stair=2 then if fupligh

17、t=0000 and fdnlight=0000 and stoplight=0000 then udsig=1; state=door_close; elsif fuplight(2)=1 or stoplight(2)=1 then -本层有上升或停站请求时,电梯开门udsig=1; state=door_open; elsif fuplight=0000 and stoplight=0000 and fdnlight=0010 then - 只有 2 层有下降请求时,电梯开门udsig=0; state=door_open; elsif stoplight(4)=1 or fdnligh

18、t(4)=1 or stoplight(3)=1 or fdnlight(3)=1 or fuplight(3)=1 then -4 层有停站请求或下降请求,则上升udsig=1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 19 页 - - - - - - - - - 10 state=up; else udsig=0; state=down; end if; elsif stair=1 then if fuplight=0000 and fdnlight=0000

19、 and stoplight=0000 then udsig=1; state=door_close; elsif stoplight(1)=1 or fuplight(1)=1 then udsig=1; state=door_open; else udsig=1; state=up; end if; end if; elsif udsig=0 then -电梯处在下降模式if stair=4 then if fuplight=0000 and fdnlight=0000 and stoplight=0000 then udsig=0; state=door_close; elsif fdn

20、light(4)=1 or stoplight(4)=1 then udsig=0; state=door_open; else udsig=0; state=down; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 19 页 - - - - - - - - - 11 end if; elsif stair=3 then if fuplight=0000 and fdnlight=0000 and stoplight=0000 then udsig=0; state=

21、door_close; elsif fdnlight(3)=1 or stoplight(3)=1 then udsig=0; state=door_open; elsif fdnlight=0000 and stoplight=0000 and fuplight=0100 then udsig=1; state=door_open; elsif fuplight(1)=1 or stoplight(1)=1 or fuplight(2)=1 or fdnlight(2)=1 or stoplight(2)=1 then -一层有停站请求或上升请求,则下降udsig=0; state=down

22、; else udsig=1; state=up; end if; elsif stair=2 then if fuplight=0000 and fdnlight=0000 and stoplight=0000 then udsig=0; state=door_close; elsif fdnlight(2)=1 or stoplight(2)=1 then udsig=0; state=door_open; elsif fdnlight=0000 and stoplight=0000 and 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - -

23、- - - - 名师精心整理 - - - - - - - 第 11 页,共 19 页 - - - - - - - - - 12 fuplight=0010 then udsig=1; state=door_open; elsif fuplight(1)=1 or stoplight(1)=1 then -一层有停站请求或上升请求,则下降udsig=0; state=down; else udsig=1; state=up; end if; elsif stair=1 then if fuplight=0000 and fdnlight=0000 and stoplight=0000 then

24、udsig=1; state=door_close; elsif stoplight(1)=1 or fuplight(1)=1 then udsig=1; state=door_open; else udsig=1; state -电梯处于上升状态stair=stair+1; -电梯楼层数加一position:=position+1; if position4 and (stoplight(position)=1 or fuplight(position)=1) then 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精

25、心整理 - - - - - - - 第 12 页,共 19 页 - - - - - - - - - 13 state=stop; -电梯在 1 2 3 层,本层有停站或上升请求时,则停止elsif position=4 and (stoplight(position)=1 or fdnlight(position)=1) then state=stop; -电梯处在4 层,并且有 4 层停站或下降请求,则停止else state -电梯处在下降状态stair1 and (stoplight(position)=1 and fdnlight(position)=1) then state=sto

26、p; elsif position=1 and (stoplight(position)=1 or fuplight(position)=1) then state=stop; else state state doorlight=1; if udsig=1 then if stair4 and (fuplight(position)=1 or stoplight(position)=1) then clr_up=1; -清除当前层上升和停站请求else 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - -

27、- - - - 第 13 页,共 19 页 - - - - - - - - - 14 clr_up=1; clr_dn1 and (fdnlight(position)=1 or stoplight(position)=1) then clr_dn=1; -清除当前层下降和停站请求else clr_up=1; clr_dn=1; end if; end if; state=door_wait1; end case; end if; end if; end process statelift; ctrlight:process(reset,buttonclk) -信号灯控制进程begin if

28、reset=1 then -复位,寄存信号清零fuplight=0000; fdnlight=0000; stoplight=0000; else if buttonclkevent and buttonclk=1 then if f1upbutton=1 then -记忆各层上升请求fuplight(1)=1; end if; if f2upbutton=1 then 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 14 页,共 19 页 - - - - - - - - - 15

29、fuplight(2)=1; end if; if f3upbutton=1 then fuplight(3)=1; end if; if clr_up=1 then -上升和停站请求清零fuplight(stair)=0; stoplight(stair)=0; end if; if f2dnbutton=1 then -记忆各层下降请求fdnlight(2)=1; end if; if f3dnbutton=1 then fdnlight(3)=1; end if; if f4dnbutton=1 then fdnlight(4)=1; end if; if clr_dn=1 then -

30、下降和停站请求清零fdnlight(stair)=0; stoplight(stair)=0; end if; if stop1button=1 then -记忆各层停站请求stoplight(1)=1; end if; if stop2button=1 then stoplight(2)=1; end if; if stop3button=1 then stoplight(3)=1; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 15 页,共 19 页 - - - - - - -

31、 - - 16 end if; if stop4button=1 then stoplight(4)=1; end if; end if; end if; end process ctrlight; showlift:process(stair,clk2) -楼层显示进程begin s=000; if stair=1 then dout=0110000; elsif stair=2 then dout=1101101; elsif stair=3 then dout=1111001; elsif stair=4 then dout=0110011; end if; end process sh

32、owlift; end architecture chi; 四层电梯控制器的仿真:在波形仿真中,根据实际,我们有必要做一些假设,即是:1 外部请求上升的乘客,进入电梯后一定是按更高层的停站按钮;2 外部请求下降的乘客,进入电梯后一定是按更低层的停站按钮;3 如果有乘客进入电梯,则一定有停站请求;名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 16 页,共 19 页 - - - - - - - - - 17 4 同一时刻有很多人按键的概率很小,所以我们认为请求信号都有一定的先后顺序。设

33、定仿真时间长度为60s,liftclk 信号为周期 1s 的时钟信号 , buttonclk 信号为周期 0.1s的时钟信号。 doorlight 信号逻辑1表示开门, 逻辑0表示关门。udsig 信号为逻辑 1表示电梯处在上升模式,逻辑0表示处在下降模式。fuplight,fdnlight,stoplight 是四位二进制向量,波形图中的0001表示一层有请求,0010 表示二层有请求, 0100表示三层有请求, 1000 表示四层有请求。图 1 所示的波形是在一层有上升请求的仿真波形,在reset信号产生一个脉冲时,电梯回复初始状态,即stopon_1状态,然后等待4s,关门检测没有请求信

34、号,于是电梯此时停在一层。当电梯时钟上升沿检测到一层上升请求信号fuplight(1) 为1时,电梯开门, fuplight(1)清零,等待4s,关门检测到二层停站请求,于是电梯上升到二层停止,开门stoplight(2)清零,stair 信号由 001 变为010,电梯最终停在二层。图 1 有上升请求的仿真波形图 2 所示的波形是三层有下降请求的波形,当电梯在一层关门后,检测到fdnlight 为 “0100” , 则上升到三层, 开门等待 4s, 关门检测到 stoplight 为 0001 ,于是电梯下降到一层,最终停在一层。名师资料总结 - - -精品资料欢迎下载 - - - - -

35、- - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 17 页,共 19 页 - - - - - - - - - 18 图 2 有下降请求的仿真波形图 3所示的波形为有多个停站请求的仿真波形,电梯在一层关门后, 检测到stoplight 为“0110” ,则上升至二层停止开门,stoplight(2)清零,等待 4s后关门,继续上升至三层,开门后stoplight(3)清零,乘客下站后电梯最终停在三层。图 3 有多个停站请求的仿真波形从前面所有的仿真波形来看, 电梯的的运行情况完全符合它的运行规则,电梯的位置变化合情合理。心得体会:在本设计的过程中,

36、我学习了VHDL 语言的基本语法,熟悉了QuartusII 的VHDL 文本设计流程全过程, 掌握了四层电梯控制器的设计方法,及它的仿真和硬件测试。 经过多次改进,本设计实现了四层电梯的基本功能,电梯的的运行情况完全符合它的运行规则, 电梯的位置变化合情合理。 本次四层电梯控制器的设名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 18 页,共 19 页 - - - - - - - - - 19 计采用 VHDL 语言,源程序经Quartus II 软件仿真,目标器件选用CPLD 器件。本设计代码具有良好的可读性和可移植性,运用了有限状态机的设计方法,使得它灵活、简单、运算速度快、可靠性高,并且此设计具有良好的扩展性。名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 19 页,共 19 页 - - - - - - - - -

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号