基于VHDL的四层电梯控制器Word格式.docx

上传人:b****5 文档编号:21531803 上传时间:2023-01-31 格式:DOCX 页数:15 大小:39.71KB
下载 相关 举报
基于VHDL的四层电梯控制器Word格式.docx_第1页
第1页 / 共15页
基于VHDL的四层电梯控制器Word格式.docx_第2页
第2页 / 共15页
基于VHDL的四层电梯控制器Word格式.docx_第3页
第3页 / 共15页
基于VHDL的四层电梯控制器Word格式.docx_第4页
第4页 / 共15页
基于VHDL的四层电梯控制器Word格式.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

基于VHDL的四层电梯控制器Word格式.docx

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

基于VHDL的四层电梯控制器Word格式.docx

四层电梯控制器的设计主要是对实体和结构体的设计,它的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:

---------led_7数码管显示扫描时钟信号

reset:

---------异步复位端口

close:

----------关门请求

f1upbutton:

---------一层上升请求端口

f2upbutton:

---------二层上升请求端口

f2dnbutton:

----------二层下降请求端口

f3dnbutton:

---------三层下降请求端口

f3upbutton:

--------三层上升请求端口

f4dnbutton:

----------四层下降请求端口

stop1button:

-------------一层停站请求端口

stop2button:

----------二层停站请求端口

stop3button:

--三层停站请求端口

stop4button:

--四层停站请求端口

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:

--下降和停站请求清除信号

signalq:

std_logic_vector(3downto0);

---分频进程中需要的信号

signalbuttonclk,liftclk:

--分频后的电梯时钟和按键读取控制时钟

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;

ifreset='

then--异步复位,电梯的初始状态为一层开门状态

state<

=stop_on_1;

clr_up<

='

0'

clr_dn<

else

ifliftclk'

eventandliftclk='

then--每个上升沿

casestateis

whenstop_on_1=>

doorlight<

--开门

stair<

=1;

position:

=door_wait1;

--电梯等待4s

whendoor_wait1=>

if(close='

)thenstate<

=door_close;

--如果有关门信号,则转至关门状态

else

state<

=door_wait2;

---等待第二秒

endif;

whendoor_wait2=>

if(close='

=door_wait3;

等待第三秒

whendoor_wait3=>

if(close='

else

state<

=door_wait4;

等待第四秒

endif;

whendoor_wait4=>

whendoor_close=>

--关门,判定电梯下一个运行方式

ifudsig='

then--电梯处在上升模式

ifstair=4then

iffuplight="

andfdnlight="

andstoplight="

then--没有请求信号时,电梯停在当前层

udsig<

elsiffdnlight(4)='

orstoplight(4)='

then--本层有请求信号时,电梯开门

--转为下降

=door_open;

else--否则下降

=down;

endif;

elsifstair=3then

then

elsiffuplight(3)='

orstoplight(3)='

then--本层有上升或停站请求时,电梯开门

elsiffuplight="

0100"

then--只有3层有下降请求时,电梯开门

elsifstoplight(4)='

orfdnlight(4)='

then--4层有停站请求或下降请求,则上升

=up;

else

elsifstair=2then

elsiffuplight

(2)='

orstoplight

(2)='

0010"

then--只有2层有下降请求时,电梯开门

orfdnlight(3)='

orfuplight(3)='

elsifstair=1then

iffuplight="

elsifstoplight

(1)='

orfuplight

(1)='

then

elsifudsig='

then--电梯处在下降模式

elsiffdnlight(4)='

elsiffdnlight(3)='

elsiffdnlight="

andfuplight="

elsiffuplight

(1)='

orstoplight

(1)='

orfuplight

(2)='

orfdnlight

(2)='

then--一层有停站请求或上升请求,则下降

elsiffdnlight

(2)='

else

whenup=>

--电梯处于上升状态

=stair+1;

--电梯楼层数加一

=position+1;

ifposition<

4and(stoplight(position)='

orfuplight(position)='

)then

=stop;

--电梯在123层,本层有停站或上升请求时,则停止

elsifposition=4and(stoplight(position)='

orfdnlight(position)='

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

whendown=>

--电梯处在下降状态

=stair-1;

--电梯楼层数减一

=position-1;

ifposition>

1and(stoplight(position)='

andfdnlight(position)='

elsifposition=1and(stoplight(position)='

whenstop=>

whendoor_open=>

ifstair<

4and(fuplight(position)='

orstoplight(position)='

--清除当前层上升和停站请求

ifstair>

1and(fdnlight(position)='

--清除当前层下降和停站请求

endcase;

endif;

endprocessstatelift;

ctrlight:

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

then--复位,寄存信号清零

fuplight<

fdnlight<

stoplight<

ifbuttonclk'

eventandbuttonclk='

iff1upbutton='

then--记忆各层上升请求

fuplight

(1)<

iff2upbutton='

fuplight

(2)<

iff3upbutton='

fuplight(3)<

ifclr_up='

then--上升和停站请求清零

fuplight(stair)<

stoplight(stair)<

iff2dnbutton='

then--记忆各层下降请求

fdnlight

(2)<

iff3dnbutton='

fdnlight(3)<

iff4dnbutton='

fdnlight(4)<

ifclr_dn='

then--下降和停站请求清零

fdnlight(stair)<

ifstop1button='

then--记忆各层停站请求

stoplight

(1)<

ifstop2button='

stoplight

(2)<

ifstop3button='

stoplight(3)<

ifstop4button='

stoplight(4)<

endprocessctrlight;

showlift:

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

s<

000"

ifstair=1then

dout<

0110000"

elsifstair=2then

1101101"

elsifstair=3then

1111001"

elsifstair=4then

0110011"

endprocessshowlift;

endarchitecturechi;

四层电梯控制器的仿真:

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

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

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

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

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

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

doorlight信号逻辑‘1’表示开门,逻辑‘0’表示关门。

udsig信号为逻辑‘1’表示电梯处在上升模式,逻辑‘0’表示处在下降模式。

fuplight,fdnlight,stoplight是四位二进制向量,波形图中的0001表示一层有请求,0010表示二层有请求,0100表示三层有请求,1000表示四层有请求。

图1所示的波形是在一层有上升请求的仿真波形,在reset信号产生一个脉冲时,电梯回复初始状态,即stopon_1状态,然后等待4s,关门检测没有请求信号,于是电梯此时停在一层。

当电梯时钟上升沿检测到一层上升请求信号fuplight

(1)为‘1’时,电梯开门,fuplight

(1)清零,等待4s,关门检测到二层停站请求,于是电梯上升到二层停止,开门stoplight

(2)清零,stair信号由001变为010,电梯最终停在二层。

图1有上升请求的仿真波形

图2所示的波形是三层有下降请求的

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

当前位置:首页 > 初中教育

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

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