基于VHDL的四层电梯控制器_第1页
基于VHDL的四层电梯控制器_第2页
基于VHDL的四层电梯控制器_第3页
基于VHDL的四层电梯控制器_第4页
基于VHDL的四层电梯控制器_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PAGE四层电梯控制器实验目的:1、掌握更复杂的VHDL设计。2、掌握状态机设计方法。实验环境:EP1C3适配板、装有Quartusii软件的PC机一台。实验原理:电梯控制器的功能模块如下图所示,包括主控制器、分控制器、楼层选择器、状态显示器、译码器和楼层显示器。乘客在电梯中选择所要到达的楼层,通过主控制器的处理,电梯开始运行,状态显示器显示电梯的运行状态,电梯所在楼层数通过译码器译码从而在楼层显示器中显示。分控制器把有效的请求传给主控制器进行处理,同时显示电梯的运行状态和电梯所在楼层数。由于分控制器相对简单很多,所以主控制器是核心部分。状态显示器状态显示器主控制器楼层选择器分控制器译码器楼层显示器电梯控制器原理图外部按键外部按键请求信号寄存器状态寄存器内部软件执行机构外部硬件执行机构图2.2总流程图初始化判定电梯运行方向是否有请求?等待电梯运行楼层检测否电梯停止目标层与本层是否同层?是是否目标层?开门延时关门是否停止运行?是否是否是否停止图2.3电梯控制主流程图四层电梯控制器实现的功能及运行规则:eq\o\ac(○,1)电梯一层入口处设有上升请求开关,二三层入口处设有上、下请求开关,四层入口处设有下降请求开关,电梯内部设有顾客到达楼层的停站请求开关。eq\o\ac(○,2)每层电梯入口处设有位置指示装置及电梯运行模式(上升或下降)指示装置。eq\o\ac(○,3)电梯初始状态为一层开门状态。eq\o\ac(○,4)电梯每秒上升(下降)一层楼。eq\o\ac(○,5)电梯到达需要停止的楼层,经过1秒电梯门打开,开门指示灯亮,开门4秒后,电梯门关闭(开门指示灯灭),电梯继续运行,直至执行完最后一个请求信号后停留在当前层。eq\o\ac(○,6)电梯需要寄存器来记忆电梯内外所有请求,并按照电梯运行规则按顺序响应,每个请求信号保留至执行后消除。eq\o\ac(○,7)电梯的运行规则:当电梯处于上升模式时,只响应比电梯所在位置高的上楼请求信号和停站请求信号,由下而上逐个执行,直到最后一个上楼请求执行完毕;如果高层有下楼请求,则直接上升到有下楼请求的最高层,然后进入下降模式。当电梯处于下降模式时则与上升模式相反。四层电梯控制器的设计思路:电梯控制器设计两个进程相互配合,状态机进程作为主要进程,信号灯控制进程作为辅助进程。根据电梯的实际工作情况,可以为状态机设置十个状态,它们分别是“电梯停在一层”“开门”“关门”“开门等待第一秒”“开门等待第二秒”“开门等待第三秒”“开门等待第四秒”“上升”“下降”和“停止”。由于电梯每秒上升或下降一层,则可以用周期为1s的信号来作为电梯状态转换的触发时钟。状态机进程中的很多判断条件是以信号灯控制进程产生的信号灯信号为依据,而信号灯控制进程中信号灯的熄灭又是由状态机进程中传出的信号来控制。四层电梯控制器的设计主要是对实体和结构体的设计,它的VHDL描述模块流程如图3.1所示:元件库的说明元件库的说明定义实体结构体端口状态机进程信号灯控制进程结束按键信号灯图3.1四层电梯控制器的VHDL描述模块流程VHDL源代码说明:libraryIEEE;--库的说明useIEEE.std_logic_1164.all;--程序包的说明useIEEE.std_logic_unsigned.all;useIEEE.std_logic_arith.all;(arith)entityfourliftis--实体名称fourliftport(clk1:instd_logic;--按键读取时钟信号clk2:instd_logic;--led_7数码管显示扫描时钟信号reset:instd_logic;--异步复位端口 close:instd_logic; 关门请求f1upbutton:instd_logic;--一层上升请求端口f2upbutton:instd_logic;--二层上升请求端口f2dnbutton:instd_logic;--二层下降请求端口f3dnbutton:instd_logic;--三层下降请求端口f3upbutton:instd_logic;-三层上升请求端口f4dnbutton:instd_logic; --四层下降请求端口stop1button:instd_logic;--一层停站请求端口stop2button:instd_logic;--二层停站请求端口stop3button:instd_logic;--三层停站请求端口stop4button:instd_logic; --四层停站请求端口stair:bufferintegerrange1to4;--电梯位置信号udsig:bufferstd_logic;--电梯运行模式(上升1或下降0fuplight,fdnlight,stoplight:bufferstd_logic_vector(4downto1);--上升、下降、停站请求寄存信号 doorlight:outstd_logic;--开门状态(‘1’为开门状态)dout:outstd_logic_vector(6downto0);--数码管显示楼层段码 s:outstd_logic_vector(2downto0));--数码管显示楼层位码endentityfourlift;architecturechioffourliftis--结构体typelift_stateis--定义十个状态(stop_on_1,door_open,door_close,door_wait1,door_wait2,door_wait3,door_wait4,up,down,stop);signalstate:lift_state;signalclr_up:std_logic;--上升和停站请求清除信号signalclr_dn:std_logic;--下降和停站请求清除信号signalq:std_logic_vector(3downto0);分频进程中需要的信号signalbuttonclk,liftclk:std_logic;--分频后的电梯时钟和按键读取控制时钟beginclklift:process(clk1)--分频产生电梯控制时钟liftclk和按键读取控制时钟buttonclkbeginif(clk1'eventandclk1='1')then ifq="1111"thenq<="0000"; else q<=q+1; endif;endif;buttonclk<=q(0);liftclk<=q(3);endprocessclklift;statelift:process(reset,liftclk)--状态机进程variableposition:integerrange4downto1;beginifreset='1'then--异步复位,电梯的初始状态为一层开门状态state<=stop_on_1;clr_up<='0';clr_dn<='0';elseifliftclk'eventandliftclk='1'then--每个上升沿casestateiswhenstop_on_1=>doorlight<='1'; --开门stair<=1;position:=1;state<=door_wait1;--电梯等待4swhendoor_wait1=>clr_up<='0';clr_dn<='0'; if(close='1')thenstate<=door_close;--如果有关门信号,则转至关门状态 else state<=door_wait2;等待第二秒 endif;whendoor_wait2=>if(close='1')thenstate<=door_close; else state<=door_wait3;等待第三秒 endif;whendoor_wait3=> if(close='1')thenstate<=door_close; else state<=door_wait4;等待第四秒 endif;whendoor_wait4=>state<=door_close;whendoor_close=>--关门,判定电梯下一个运行方式doorlight<='0';ifudsig='1'then--电梯处在上升模式ifstair=4then iffuplight="0000"andfdnlight="0000"andstoplight="0000"then--没有请求信号时,电梯停在当前层udsig<='0';state<=door_close; elsiffdnlight(4)='1'orstoplight(4)='1'then--本层有请求信号时,电梯开门udsig<='0'; --转为下降state<=door_open; else--否则下降udsig<='0';state<=down; endif;elsifstair=3then iffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='1';state<=door_close; elsiffuplight(3)='1'orstoplight(3)='1'then--本层有上升或停站请求时,电梯开门udsig<='1';state<=door_open;elsiffuplight="0000"andstoplight="0000"andfdnlight="0100"then--只有3层有下降请求时,电梯开门udsig<='0';state<=door_open;elsifstoplight(4)='1'orfdnlight(4)='1'then--4层有停站请求或下降请求,则上升udsig<='1';state<=up;elseudsig<='0';state<=down;endif;elsifstair=2then iffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='1';state<=door_close; elsiffuplight(2)='1'orstoplight(2)='1'then--本层有上升或停站请求时,电梯开门udsig<='1';state<=door_open;elsiffuplight="0000"andstoplight="0000"andfdnlight="0010"then--只有2层有下降请求时,电梯开门udsig<='0';state<=door_open;elsifstoplight(4)='1'orfdnlight(4)='1'orstoplight(3)='1'orfdnlight(3)='1'orfuplight(3)='1'then--4层有停站请求或下降请求,则上升udsig<='1';state<=up;elseudsig<='0';state<=down;endif;elsifstair=1theniffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='1';state<=door_close;elsifstoplight(1)='1'orfuplight(1)='1'thenudsig<='1';state<=door_open;elseudsig<='1';state<=up;endif;endif;elsifudsig='0'then--电梯处在下降模式ifstair=4theniffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='0';state<=door_close;elsiffdnlight(4)='1'orstoplight(4)='1'thenudsig<='0';state<=door_open;elseudsig<='0';state<=down;endif;elsifstair=3theniffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='0';state<=door_close;elsiffdnlight(3)='1'orstoplight(3)='1'thenudsig<='0';state<=door_open;elsiffdnlight="0000"andstoplight="0000"andfuplight="0100"thenudsig<='1';state<=door_open;elsiffuplight(1)='1'orstoplight(1)='1'orfuplight(2)='1'orfdnlight(2)='1'orstoplight(2)='1'then--一层有停站请求或上升请求,则下降udsig<='0';state<=down;elseudsig<='1';state<=up;endif;elsifstair=2theniffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='0';state<=door_close;elsiffdnlight(2)='1'orstoplight(2)='1'thenudsig<='0';state<=door_open;elsiffdnlight="0000"andstoplight="0000"andfuplight="0010"thenudsig<='1';state<=door_open;elsiffuplight(1)='1'orstoplight(1)='1'then--一层有停站请求或上升请求,则下降udsig<='0';state<=down;elseudsig<='1';state<=up;endif;elsifstair=1theniffuplight="0000"andfdnlight="0000"andstoplight="0000"thenudsig<='1';state<=door_close;elsifstoplight(1)='1'orfuplight(1)='1'thenudsig<='1';state<=door_open;elseudsig<='1';state<=up;endif;endif;endif;whenup=>--电梯处于上升状态stair<=stair+1;--电梯楼层数加一position:=position+1;ifposition<4and(stoplight(position)='1'orfuplight(position)='1')thenstate<=stop;--电梯在123层,本层有停站或上升请求时,则停止elsifposition=4and(stoplight(position)='1'orfdnlight(position)='1')thenstate<=stop;--电梯处在4层,并且有4层停站或下降请求,则停止elsestate<=door_close;endif;whendown=>--电梯处在下降状态stair<=stair-1;--电梯楼层数减一position:=position-1;ifposition>1and(stoplight(position)='1'andfdnlight(position)='1')thenstate<=stop;elsifposition=1and(stoplight(position)='1'orfuplight(position)='1')thenstate<=stop;elsestate<=door_close;endif;whenstop=>state<=door_open;whendoor_open=>doorlight<='1';ifudsig='1'thenifstair<4and(fuplight(position)='1'orstoplight(position)='1')thenclr_up<='1';--清除当前层上升和停站请求elseclr_up<='1';clr_dn<='1';endif;elsifudsig='0'thenifstair>1and(fdnlight(position)='1'orstoplight(position)='1')thenclr_dn<='1';--清除当前层下降和停站请求elseclr_up<='1';clr_dn<='1';endif;endif;state<=door_wait1;endcase;endif;endif;endprocessstatelift;ctrlight:process(reset,buttonclk)--信号灯控制进程beginifreset='1'then--复位,寄存信号清零fuplight<="0000";fdnlight<="0000";stoplight<="0000";elseifbuttonclk'eventandbuttonclk='1'theniff1upbutton='1'then--记忆各层上升请求fuplight(1)<='1';endif;iff2upbutton='1'thenfuplight(2)<='1';endif;iff3upbutton='1'then fuplight(3)<='1'; endif;ifclr_up='1'then--上升和停站请求清零fuplight(stair)<='0';stoplight(stair)<='0';endif;iff2dnbutton='1'then--记忆各层下降请求fdnlight(2)<='1';endif;iff3dnbutton='1'thenfdnlight(3)<='1';endif;iff4dnbutton='1'then fdnlight(4)<='1';endif;ifclr_dn='1'then--下降和停站请求清零fdnlight(stair)<='0';stoplight(stair)<='0';endif;ifstop1button='1'then--记忆各层停站请求stoplight(1)<='1';endif;ifstop2button='1'thenstoplight(2)<='1';endif;ifstop3button='1'thenstoplight(3)<='1';endif;ifstop4button='1'then stoplight(4)<='1'; endif;endif;endif;endprocessctrlight;showlift:process(stair,clk2)--楼层显示进程begins<="000";ifstair=1thendout<="0110000";elsifstair=2thendout<="1101101";elsifstair=3thendout<="1111001";elsifstair=4thendout<="0110011";endif;endprocessshowlift;endarchitecturechi;四层电梯控制器的仿真:在波形仿真中,根据实际,我们有必要做一些假设,即是:eq\o\ac(○,1)外部请求上升的乘客,进入电梯后一定是按更高层的停站按钮;eq\o\ac(○,2)外部请求下降的乘客,进入电梯后一定是按更低层的停站按钮;eq\o\ac(○,3)如果有乘客进入电梯,则一定有停站请求;eq\o\ac(○,4)同一时刻有很多人按键的概率很小,所以我们认为请求信号都有一定的先

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论