完整word版基于VHDL的四层电梯控制器.docx

上传人:b****3 文档编号:5451051 上传时间:2022-12-16 格式:DOCX 页数:17 大小:45.24KB
下载 相关 举报
完整word版基于VHDL的四层电梯控制器.docx_第1页
第1页 / 共17页
完整word版基于VHDL的四层电梯控制器.docx_第2页
第2页 / 共17页
完整word版基于VHDL的四层电梯控制器.docx_第3页
第3页 / 共17页
完整word版基于VHDL的四层电梯控制器.docx_第4页
第4页 / 共17页
完整word版基于VHDL的四层电梯控制器.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

完整word版基于VHDL的四层电梯控制器.docx

《完整word版基于VHDL的四层电梯控制器.docx》由会员分享,可在线阅读,更多相关《完整word版基于VHDL的四层电梯控制器.docx(17页珍藏版)》请在冰豆网上搜索。

完整word版基于VHDL的四层电梯控制器.docx

完整word版基于VHDL的四层电梯控制器

四层电梯控制器

 

姓名:

徐志聪

学号:

030902529

指导老师:

赵彦敏

 

实验目的:

1、掌握更复杂的VHDL设计。

2、掌握状态机设计方法.

实验环境:

EP1C3适配板、装有Quartusii软件的PC机一台。

实验原理:

电梯控制器的功能模块如下图所示,包括主控制器、分控制器、楼层选择器、状态显示器、译码器和楼层显示器。

乘客在电梯中选择所要到达的楼层,通过主控制器的处理,电梯开始运行,状态显示器显示电梯的运行状态,电梯所在楼层数通过译码器译码从而在楼层显示器中显示。

分控制器把有效的请求传给主控制器进行处理,同时显示电梯的运行状态和电梯所在楼层数。

由于分控制器相对简单很多,所以主控制器是核心部分。

状态显示器

主控制器

楼层选择器

分控制器

译码器

楼层显示器

电梯控制器原理图

外部按键

请求信号寄存器

状态寄存器

内部软件执行机构

外部硬件执行机构

图2.2总流程图

初始化

判定电梯运行方向

是否有请求?

等待

电梯运行

楼层检测

电梯停止

目标层与本层是否同层?

是否目标层?

开门

延时

关门

是否停止运行?

停止

图2.3电梯控制主流程图

四层电梯控制器实现的功能及运行规则:

电梯一层入口处设有上升请求开关,二三层入口处设有上、下请求开关,四层入口处设有下降请求开关,电梯内部设有顾客到达楼层的停站请求开关。

每层电梯入口处设有位置指示装置及电梯运行模式(上升或下降)指示装置。

电梯初始状态为一层开门状态。

电梯每秒上升(下降)一层楼。

电梯到达需要停止的楼层,经过1秒电梯门打开,开门指示灯亮,开门4秒后,电梯门关闭(开门指示灯灭),电梯继续运行,直至执行完最后一个请求信号后停留在当前层。

电梯需要寄存器来记忆电梯内外所有请求,并按照电梯运行规则按顺序响应,每个请求信号保留至执行后消除.

电梯的运行规则:

当电梯处于上升模式时,只响应比电梯所在位置高的上楼请求信号和停站请求信号,由下而上逐个执行,直到最后一个上楼请求执行完毕;如果高层有下楼请求,则直接上升到有下楼请求的最高层,然后进入下降模式。

当电梯处于下降模式时则与上升模式相反。

四层电梯控制器的设计思路:

电梯控制器设计两个进程相互配合,状态机进程作为主要进程,信号灯控制进程作为辅助进程。

根据电梯的实际工作情况,可以为状态机设置十个状态,它们分别是“电梯停在一层"“开门”“关门”“开门等待第一秒"“开门等待第二秒"“开门等待第三秒”“开门等待第四秒"“上升”“下降”和“停止”。

由于电梯每秒上升或下降一层,则可以用周期为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———————-实体名称fourlift

port(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或下降0

fuplight,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;--分频后的电梯时钟和按键读取控制时钟

begin

clklift:

process(clk1)—-分频产生电梯控制时钟liftclk和按键读取控制时钟buttonclk

begin

if(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;

begin

ifreset=’1’then——异步复位,电梯的初始状态为一层开门状态

state〈=stop_on_1;

clr_up〈='0';

clr_dn<=’0';

else

ifliftclk'eventandliftclk=’1’then—-每个上升沿

casestateis

whenstop_on_1=>

doorlight〈=’1’;——开门

stair<=1;

position:

=1;

state〈=door_wait1;——电梯等待4s

whendoor_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"then

udsig<=’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;

else

udsig〈='0’;

state〈=down;

endif;

elsifstair=2then

iffuplight="0000"andfdnlight=”0000”andstoplight=”0000"then

udsig<=’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;

else

udsig<='0’;

state〈=down;

endif;

elsifstair=1then

iffuplight="0000”andfdnlight="0000"andstoplight="0000”then

udsig〈='1';

state〈=door_close;

elsifstoplight

(1)=’1’orfuplight

(1)='1'then

udsig〈='1’;

state〈=door_open;

else

udsig<=’1’;

state〈=up;

endif;

endif;

elsifudsig=’0'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"then

udsig〈=’0’;

state〈=door_close;

elsiffdnlight(3)=’1'orstoplight(3)='1'then

udsig<='0’;

state<=door_open;

elsiffdnlight="0000”andstoplight="0000”andfuplight="0100”then

udsig<='1';

state〈=door_open;

elsiffuplight

(1)='1’orstoplight

(1)='1'orfuplight

(2)=’1’orfdnlight

(2)='1’orstoplight

(2)='1'then--一层有停站请求或上升请求,则下降

udsig〈='0';

state<=down;

else

udsig<=’1';

state〈=up;

endif;

elsifstair=2then

iffuplight=”0000"andfdnlight="0000”andstoplight="0000”then

udsig〈=’0’;

state〈=door_close;

elsiffdnlight

(2)=’1’orstoplight

(2)=’1’then

udsig〈='0’;

state〈=door_open;

elsiffdnlight=”0000”andstoplight=”0000"andfuplight="0010”then

udsig<=’1’;

state〈=door_open;

elsiffuplight

(1)='1'orstoplight

(1)=’1'then-—一层有停站请求或上升请求,则下降

udsig<='0';

state〈=down;

else

udsig<=’1’;

state<=up;

endif;

elsifstair=1then

iffuplight="0000”andfdnlight="0000"andstoplight="0000”then

udsig〈=’1';

state〈=door_close;

elsifstoplight

(1)='1'orfuplight

(1)=’1’then

udsig<='1’;

state<=door_open;

else

udsig〈=’1';

state〈=up;

endif;

endif;

endif;

whenup=>-—电梯处于上升状态

stair〈=stair+1;——电梯楼层数加一

position:

=position+1;

ifposition<4and(stoplight(position)='1'orfuplight(position)='1')then

state<=stop;--电梯在123层,本层有停站或上升请求时,则停止

elsifposition=4and(stoplight(position)=’1’orfdnlight(position)=’1’)then

state〈=stop;--电梯处在4层,并且有4层停站或下降请求,则停止

else

state〈=door_close;

endif;

whendown=>-—电梯处在下降状态

stair〈=stair-1;—-电梯楼层数减一

position:

=position—1;

ifposition>1and(stoplight(position)='1'andfdnlight(position)='1')then

state〈=stop;

elsifposition=1and(stoplight(position)='1'orfuplight(position)='1')then

state〈=stop;

else

state〈=door_close;

endif;

whenstop=>

state<=door_open;

whendoor_open=>

doorlight〈='1’;

ifudsig=’1'then

ifstair〈4and(fuplight(position)=’1'orstoplight(position)=’1')then

clr_up<=’1’;-—清除当前层上升和停站请求

else

clr_up<=’1’;

clr_dn〈=’1’;

endif;

elsifudsig=’0’then

ifstair〉1and(fdnlight(position)='1'orstoplight(position)='1')then

clr_dn<=’1’;——清除当前层下降和停站请求

else

clr_up〈='1’;

clr_dn<=’1’;

endif;

endif;

state〈=door_wait1;

endcase;

endif;

endif;

endprocessstatelift;

ctrlight:

process(reset,buttonclk)--信号灯控制进程

begin

ifreset='1'then--复位,寄存信号清零

fuplight〈=”0000”;

fdnlight<=”0000";

stoplight〈=”0000";

else

ifbuttonclk’eventandbuttonclk=’1’then

iff1upbutton='1’then--记忆各层上升请求

fuplight

(1)〈=’1’;

endif;

iff2upbutton=’1'then

fuplight

(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’then

fdnlight(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’then

stoplight

(2)<='1';

endif;

ifstop3button='1’then

stoplight(3)〈='1’;

endif;

ifstop4button=’1'then

stoplight(4)<=’1’;

endif;

endif;

endif;

endprocessctrlight;

showlift:

process(stair,clk2)-—楼层显示进程

begin

s<="000”;

ifstair=1then

dout<="0110000”;

elsifstair=2then

dout〈="1101101";

elsifstair=3then

dout〈="1111001”;

elsifstair=4then

dout〈="0110011”;

endif;

endprocessshowlift;

endarchitecturechi;

四层电梯控制器的仿真:

在波形仿真中,根据实际,我们有必要做一些假设,即是:

外部请求上升的乘客,进入电梯后一定是按更高层的停站按钮;

外部请求下降的乘客,进入电梯后一定是按更低层的停站按钮;

如果有乘客进入电梯,则一定有停站请求;

同一时刻有很多人按键的概率很小,所以我们认为请求信号都有一定的先后顺序。

设定仿真时间长度为60s,liftclk信号为周期1s的时钟信号,buttonclk信号为周期0。

1s的时钟信号。

doorlight信号逻辑‘1’表示开门,逻辑‘0'表示关门.udsig信号为逻辑‘1’表示电梯处在上升模式,逻辑‘0’表示处在下降模式.fuplight,fdnlight,stoplight是四位二进制向量,波形图中

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1