石家庄经济学院
数字逻辑课程设计报告
题 目 电梯控制器的设计
姓 名 meng hao
学 号
班 号 3 班
指导老师
成 绩
2011年6月
目 录
1. 课程设计目的
2. 设计任务
3. 开发工具选择
3. 设计
方案
气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载
4. 模块描述
5. VHDL实现
6. 调试仿真
7. 课程设计回顾总结
参 考 文 献
1. 课程设计目的
1) 使学生更好地巩固和加深对基础知识的理解,学会设计中小型数字系统的方法,独立完成调试过程,增强学生理论联系实际的能力,提高学生电路设计和分析的能力。
2) 通过实践教学引导学生在理论指导下有所创新,为后继专业课的学习和日后工程实践奠定基础。
2、设计要求
1) 综合应用课程中学到的理论知识,独立完成一个设计任务。
2) 根据所要完成的设计任务,采用硬件描述语言 VHDL进行描述,依靠计算机,借助EDA开发工具,实现系统功能。
3) 整理设计报告及相关的文档(包括总体设计思想,设计说明,程序源代码,仿真结果图、设计总结等)。
3 . 设计任务
任务和要求:可使用拨键开关输入欲到达的楼层。要求有数码管显示当前楼层,目标楼层,并且可以输入三个目标楼层,按输入的顺序达到,达到时有开门指示灯。在电梯移动时,有相应的指示灯显示其方向。
注意:电梯经过一个楼层和在楼层停留应各自设定一个固定时间。
4.开发工具选择
quarters Ⅱ 5.1
5.设计方案
实验要求设计一个3层的电梯的梯控制器,采用状态机来实现,这样思路清晰,便于理解。可以分为10个状态,为“一楼”、“等待状态1”、 “等待状态2”、“等待状态3”、 “等待状态4”、 “开门”、“关门”、“上升”、“下降”、“停止”。各状态之间按需要转换。由状态机进程和信号指示灯进程一起控制。
输入由电梯外部的请求,电梯内部的请求,时钟信号组成。输出由指示灯和电梯位置组成。
6.模块描述
分为4各部分
人员输入模块为按键模块
电梯控制模块为电梯条件判断状态模块
信号灯指示模块为指示灯显示模块
电梯终端模块为电梯服务模块
7. VHDL实现
代码分为实体,结构体两大块;
结构体中又分为电梯进程和指示灯进程;
电梯进程为10个状态机之间转换的代码;
指示灯进程为内外部请求指示灯的代码。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity sandianti is
port(anclk:in std_logic; --按键时钟信号
ticlk:in std_logic; --电梯时钟信号
reset:in std_logic; --复位
fiup:in std_logic; --1楼外部上升请求
seup:in std_logic; --2楼外部上升请求
sedn:in std_logic; --2楼外部下降请求
thdn:in std_logic; --3楼外部下降请求
uplight:buffer std_logic_vector(3 downto 1);---上升请求指示灯
dnlight:buffer std_logic_vector(3 downto 1);---下降请求指示灯
yilou,erlou,sanlou:in std_logic;----停站请求
splight:buffer std_logic_vector(3 downto 1);--停站请求指示灯
weizhi:buffer integer range 1 to 3;---位置指示
door:out std_logic; ---门状态指示
updown:buffer std_logic);--上升下降状态指示
end sandianti;
architecture menghao of sandianti is
type lift_state is ----状态机
(lift1,dooropen,doorclose,wait1,wait2,wait3,wait4,up,down,stop);
signal meng:lift_state;
signal clearup:std_logic; ----清除上升状态
signal cleardn:std_logic; ----清除下降状态
begin
ctrlift:process(reset,ticlk)------电梯控制进程
variable hao:integer range 3 downto 1;----显示楼层 同weizh作用一样,但显示方便
begin
if reset='1' then
meng<=lift1;
clearup<='0';
cleardn<='0';
else
if ticlk'event and ticlk='1' then
case meng is
when lift1=>
door<='1';
weizhi<=1;hao:=1;
meng<=wait1;
when wait1=>
meng<=wait2;
when wait2=>
clearup<='0';
cleardn<='0';
meng<=wait3;
when wait3=>
meng<=wait4;
when wait4=>
meng<=doorclose;
when doorclose=>
door<='0';
if updown='0' then
if weizhi=3 then
if splight="000" and uplight="000" and dnlight="000" then
updown<='1';
meng<=doorclose;
else updown<='1';meng<=down;
end if;
elsif weizhi=2 then
if splight="000" and uplight="000" and dnlight="000" then
updown<='0';
meng<=doorclose;
elsif splight(3)='1' or (splight(3)='0' and dnlight(3)='1') then
updown<='0';
meng<=up;
else updown<='1';meng<=down;
end if;
elsif weizhi=1 then
if splight="000" and uplight="000" and dnlight="000" then
updown<='0';
meng<=doorclose;
else updown<='0';meng<=up;
end if;
end if;
elsif updown='1' then
if weizhi=1 then
if splight="000" and uplight="000" and dnlight="000" then
updown<='0';
meng<=doorclose;
else updown<='0'; meng<=up;
end if;
elsif weizhi=2 then
if splight="000" and uplight="000" and dnlight="000" then
updown<='1';
meng<=doorclose;
elsif splight(1)='1' or (splight(1)='0' and uplight(1)='1') then
updown<='1';
meng<=down;
else updown<='0';meng<=up;
end if;
elsif weizhi=3 then
if splight="000" and uplight="000" and dnlight="000" then
updown<='1';
meng<=doorclose;
else updown<='1';meng<=down;
end if;
end if;
end if;
when up=>
weizhi<=weizhi+1;
hao:=hao+1;
if hao<3 and (splight(hao)='1' or uplight(hao)='1') then
meng<=stop;
elsif hao=3 and (splight(hao)='1' or dnlight (hao)='1') then
meng<=stop;
else meng<=doorclose;
end if;
when down=>
weizhi<=weizhi-1;
hao:=hao-1;
if hao>1 and (splight(hao)='1' or dnlight(hao)='1')
then meng<=stop;
elsif hao=1 and (splight(hao)='1' or uplight(hao)='1')
then meng<=stop;
else meng<=doorclose;
end if;
when stop=>
meng<=dooropen;
when dooropen=>
door<='1';
if updown='0' then
if weizhi<=2 and (splight(weizhi)='1' or uplight(weizhi)='1') then
clearup<='1';
else clearup<='1'; cleardn<='1';
end if;
elsif updown='1' then
if weizhi>=2 and (splight(weizhi)='1' or dnlight(weizhi)='1') then
cleardn<='1';
else clearup<='1';cleardn<='1';
end if;
end if;
meng<=wait1;
end case;
end if;
end if;
end process ctrlift;
ctrlight:process(reset,anclk) -----指示灯进程
begin
if reset='1' then
splight<="000";uplight<="000";dnlight<="000";
else
if anclk'event and anclk='1' then
if clearup='1' then
splight(weizhi)<='0';uplight(weizhi)<='0';
else
if fiup='1' then uplight(1)<='1';
elsif seup='1' then uplight(2)<='1';
end if;
end if;
if cleardn='1' then
splight(weizhi)<='0';dnlight(weizhi)<='0';
else
if sedn='1' then dnlight(2)<='1';
elsif thdn='1' then dnlight(3)<='1';
end if;
end if;
if yilou='1' then splight(1)<='1';
elsif erlou='1' then splight(2)<='1';
elsif sanlou='1' then splight(3)<='1';
end if;
end if;
end if;
end process ctrlight;
end architecture menghao;
8. 调试仿真
1.电梯在2楼外部有上升请求,电梯从1楼升到2楼,开门,在电梯内部有3楼停站,电梯到达3楼,之后内外没有请求,电梯停在3楼。
2. 电梯在3楼外部有下降请求,电梯从1楼升到3楼,开门,在电梯内部有1楼停站,电梯到达1楼,之后内外没有请求,电梯停在1楼。
3.电梯在2楼外部有上升请求,电梯从1楼升到2楼,开门,在电梯内部有3楼停站,电梯到达3楼,开门,之后电梯在2楼外部有下降请求,电梯从3楼下到2楼,开门,在电梯内部有1楼停站,电梯到达1楼,开门,之后内外没有请求,电梯停在1楼。
4.电梯在1楼外部有上升请求,进入电梯,内部有3楼停站请求,在电梯上升过程中,在2楼外部有下降请求,不理会,电梯到达3楼,之后相应2楼外部下降请求,在2楼停止开门,之后内部有1楼停站请求,下降到1楼,之后内外没有请求,电梯停在1楼。
9. 课程设计回顾总结
在编程的过程中,由于考虑的情况不够全面,也出现了不少问题,例如代码出错了,所以当仿真的时候仿真波形和实际不符,经过改正之后可以了实现了。由于第一次写这种比较复杂的,情况这么多的代码,开始的初期有很大的障碍,之后经过查阅相关资料,还是实现了设计要求的功能,这个代码,功能还是有些不太全,有些缺陷,并不能和实际情况完全一样,还有很多的情况没有考虑进去,但是时间有限,只能这样了。通过这次的课程设计,把理论和实际结合了起来,让我更加理解了VHDL语言在日常生活中的应用。
参 考 文 献
《数字逻辑与数字系统》 --张兴忠等编著