资源描述
厦 门 大 学 电子 工 程 系
FPGA生产实习报告
题 目 全自动电梯控制器
专 业 电子工程
班 级 04 电子
学生姓名 a ka
学生学号
指导教师 黄龙杨老师
2007年7月26日
目 录
第一部分 摘要
第二部分 设计要求
第三部分 方案论证与系统分析
第四部分 模块设计
第五部分 系统仿真
第六部分 总结
一、摘要:
本问从设计电梯控制器系统分析入手,并进行了电路设计、综合和仿真。主要分为5个模块,一是显示模块;一是门的开关控制模块;一个是电梯内部的楼层选择模块,一是外部的选择模块,还有一个总的控制模块。用于协调各部分的工作。
关键词:VHDL;控制器;FPGA;电梯
二、设计要求:(1)每层门外有上、下请求按钮(第一层只有上,第八层只有下),内有选择到达楼层按钮。有升、降以及正运行到哪层的指示。
(2)能记忆内外所有请求信号。按照运行规则逐个响应,执行完毕清除该请求信号。
(3)电梯运行规则:上升时,只响应电梯所在楼层以上的上楼请求,逐个响应完以后运行到下降请求的最高楼层,开始下降。下降时,只响应电梯所在楼层以下的下楼请求。逐个响应完以后运行到有上升请求的最低层。然后上升。执行完所有请求后停在最后响应的楼层。
(4)以外面光电传感器感应信号来判断电梯到达哪个楼层,到达某层数码管显示该层,一直等到到达新的层显示更新。如果要响应某层请求,到达该层1秒后开门,开门灯亮,默认开门10秒后关门,开门灯灭,然后继续运行。 如果内部提前按关门按钮则立即关门,若内部一直按开门按钮则直到松开该按钮再关门。
(5)开机时电梯停在一层,所有请求全清除。
三、方案论证与系统分析:
本实验可以采取多种方案,比如单片机实现,纯硬件打结等,但此次的方法-----采用可编程逻辑器件通过对器件内部的设计来实现系统功能,是一种基于芯片的设计方法.设计者可以根据需要定义器件内部逻辑和引出端,将电路板设计的大部分工作放在芯片的设计中进行,通过对芯片设计实现数字系统的逻辑功能.灵活的内部功能块组合,引出端定义等,可大大减轻电路设计和电路板设计和电路板设计的工作量和难度,有效的增强设计的灵活性,提高工作效率[1].同时采用可编程逻辑器件,设计人员在实验室可反复编程,修改错误,以期尽快开发开发产品,迅速占领市场。基于芯片的设计方法可以减少芯片的数量,缩小系统体积,降低能源消耗,提高系统的性能和可靠性。
现在分析一下该系统的特点。该设计采用方向优先控制方式方案,方向优先控制是指电梯运行到某一楼层时先考虑这一楼层是否有请求:有 ,则停止;无,则继续前进。停下来后再启动时的步骤:考虑前方——上方或下方是否有请求:有,则继续前进;无,则停止;检测后方是否有请求,有请求则转向运行,无请求则维持停止状态。
这种运作方式下,电梯对用户的请求响应率为100%,且响应的时间较短。电梯在维修停止状态的时候可以进入省电模式,又能节省大量电能。
电梯方向有限控制方式控制器系统方框图如图1所示,电路图如图2所示。 图1 电梯控制器系统方框图,图2 电梯控制器电路图。
图1
顶层原理图:
四、模块设计
1.电梯内部的楼层选择模块
module
floorselect( rst,n1,n2,n3,n4,n5,n6,n7,n8,clear1,clear2,clear3,clear4,clear5,clear6,clear7,clear8,floor,floorto,dup,ddown,start)
output[7:0] floorto,ddown,dup;
input rst,n1,n2,n3,n4,n5,n6,n7,n8,clear1,clear2,clear3,clear4,clear5,clear6,clear7,clear8,start;
input [7:0] floor;
reg[7:0] floorto,dup,ddown;
always @(rst or n1 or clear1)
begin if(!rst) floorto[0]=0; else if(n1) floorto[0]=1;else if(clear1==1&&start==0)floorto[0]=0;else ;end
always @(rst or n2 or clear2)
begin if(!rst) floorto[1]=0; else if(n2) floorto[1]=1;else if(clear2==1&&start==0)floorto[1]=0;else ;end
always @(rst or n3 or clear3)
begin if(!rst) floorto[2]=0; else if(n3) floorto[2]=1;else if(clear3==1&&start==0)floorto[2]=0;else ;end
always @(rst or n4 or clear4)
begin if(!rst) floorto[3]=0; else if(n4) floorto[3]=1;else if(clear4==1&&start==0)floorto[3]=0;else ;end
always @(rst or n5 or clear5)
begin if(!rst) floorto[4]=0; else if(n5) floorto[4]=1;else if(clear5==1&&start==0)floorto[4]=0;else ;end
always @(rst or n6 or clear6)
begin if(!rst) floorto[5]=0; else if(n6) floorto[5]=1;else if(clear6==1&&start==0)floorto[5]=0;else ;end
always @(rst or n7 or clear7)
begin if(!rst) floorto[6]=0; else if(n7) floorto[6]=1;else if(clear7==1&&start==0)floorto[6]=0;else ;end
always @(rst or n8 or clear8)
begin if(!rst) floorto[7]=0; else if(n8) floorto[7]=1;else if(clear8==1&&start==0)floorto[7]=0;else ;end
always @(floorto)
begin
case(floor)
8'b00000001: begin dup=8'b11111110&floorto; ddown=8'b00000000&floorto;end
8'b00000010: begin dup=8'b11111100&floorto; ddown=8'b00000001&floorto;end
8'b00000100: begin dup=8'b11111000&floorto; ddown=8'b00000011&floorto;end
8'b00001000: begin dup=8'b11110000&floorto; ddown=8'b00000111&floorto;end
8'b00010000: begin dup=8'b11100000&floorto; ddown=8'b00001111&floorto;end
8'b00100000: begin dup=8'b11000000&floorto; ddown=8'b00011111&floorto;end
8'b01000000: begin dup=8'b10000000&floorto; ddown=8'b00111111&floorto;end
8'b10000000: begin dup=8'b00000000&floorto;ddown=8'b01111111&floorto;end
default:;
endcase end
endmodule
2.电梯外部的选择模块
module slavec(up,down,up_1,up_2,up_3,up_4,up_5,up_6,up_7,down_2,down_3,down_4,down_5,down_6,down_7,down_8,upclear1,upclear2,upclear3,upclear4,upclear5,upclear6,upclear7
,downclear7,downclear2,downclear3,downclear4,downclear5,downclear6,downclear8,rest,start);
input up_1,up_2,up_3,up_4,up_5,up_6,up_7,down_2,down_3,down_4,down_5,down_6,down_7,down_8,upclear1,upclear2,upclear3,upclear4,upclear5,upclear6,upclear7,downclear7,downclear2,downclear3,downclear4,downclear5,downclear6,downclear8,rest,start;
output[7:0] up,down;
reg[7:0] up,down;
always @(rest)
begin up[7]=0;down[0]=0;end
always @(up_1 or upclear1 or rest)
begin if(rest)begin if(up_1)up[0]=1;else if(start==0&&upclear1==1) up[0]=0;end
else up[0]=0;end
always @(up_2 or upclear2 or rest)
begin if(rest)begin if(up_2)up[1]=1;else if(start==0&&upclear2==1) up[1]=0;end
else up[1]=0;end
always @(up_3 or upclear3 or rest)
begin if(rest)begin if(up_3)up[2]=1;else if(start==0&&upclear3==1) up[2]=0;end
else up[2]=0;end
always @(up_4 or upclear4 or rest)
begin if(rest)begin if(up_4)up[3]=1;else if(start==0&&upclear4==1) up[3]=0;end
else up[3]=0;end
always @(up_5 or upclear5 or rest)
begin if(rest)begin if(up_5)up[4]=1;else if(start==0&&upclear5==1) up[4]=0;end
else up[4]=0;end
always @(up_6 or upclear6 or rest)
begin if(rest)begin if(up_6)up[5]=1;else if(start==0&&upclear6==1) up[5]=0;end
else up[5]=0;end
always @(up_7 or upclear7 or rest)
begin if(rest)begin if(up_7)up[6]=1;else if(start==0&&upclear7==1) up[6]=0;end
else up[6]=0;end
always @(down_2 or downclear2 or rest)
begin if(rest)begin if(down_2)down[1]=1;else if(downclear2==1&&start==0)down[1]=0;else ;end
else down[1]=0;end
always @(down_3 or downclear3 or rest)
begin if(rest)begin if(down_3)down[2]=1;else if(downclear3==1&&start==0)down[2]=0;else ;end
else down[2]=0;end
always @(down_4 or downclear4 or rest)
begin if(rest)begin if(down_4)down[3]=1;else if(downclear4==1&&start==0)down[3]=0;else ;end
else down[3]=0;end
always @(down_5 or downclear5 or rest)
begin if(rest)begin if(down_5)down[4]=1;else if(downclear5==1&&start==0)down[4]=0;else ;end
else down[4]=0;end
always @(down_6 or downclear6 or rest)
begin if(rest)begin if(down_6)down[5]=1;else if(downclear6==1&&start==0)down[5]=0;else ;end
else down[5]=0;end
always @(down_7 or downclear7 or rest)
begin if(rest)begin if(down_7)down[6]=1;else if(downclear7==1&&start==0)down[6]=0;else ;end
else down[6]=0;end
always @(down_8 or downclear8 or rest)
begin if(rest)begin if(down_8)down[7]=1;else if(downclear8==1&&start==0)down[7]=0;else ;end
else down[7]=0;end
endmodule
3.显示模块:电梯内和电梯外的有关当前所在楼层和电梯上升或下降的显示
module dis(floor,direc,stop,disfloor,down,up);
input[7:0] floor; input direc,stop;
output[6:0] disfloor; output down,up;
reg[6:0] disfloor; reg down,up;
always @(floor)
begin disfloor=7'b0000000;
case(floor)
8'b00000001:disfloor=7'b0110000; 8'b00000010:disfloor=7'b1101101;
8'b00000100:disfloor=7'b1111001;
8'b00001000:disfloor=7'b0110011;
8'b00010000:disfloor=7'b1011011; 8'b00100000:disfloor=7'b1011111;
8'b01000000:disfloor=7'b1110000; 8'b10000000:disfloor=7'b1111111;
default: disfloor=7'b0000000;
endcase end
always @(direc or stop) begin if(stop==1)begin down=0; up=0; end
else if(direc==1) begin up=1;down=0; end
else begin down=1; up=0;end
end
endmodule
4.门控制模块;
module door(start,autoclose,clk,stop,enclose,enopen,rst);
output autoclose,start;
input clk,enclose,stop,enopen,rst;
reg autoclose,start,stop1;
reg[1:0] tcount;
reg[7:0] count;
always @(posedge rst or posedge stop or posedge clk)
begin
if(rst==1)begin start<=0;count<=7'd0;stop1<=1;end
else begin
if(stop==1)stop1<=1;else if(count>7'd5)stop1<=0;else ;
if(stop1==1) begin count<=count+1;
if(count<=7'd2)begin autoclose<=1;start<=0;end
else if(count<=7'd5)
begin autoclose<=0;start<=0;if(enopen) count<=7'd4;else if(enclose) count<=7'd4; end
else begin if(stop==0)begin autoclose<=1;start<=1;end else begin autoclose<=1;start<=0;end end
end
else begin autoclose<=1;count<=7'd0;start<=1;end end end endmodule
5.主控制模块
module main(dir,stop,clear,clearup,cleardown,rst,floor,up_s,down_s,up_f,down_f);
input rst;
input[7:0] floor,up_s,down_s,up_f,down_f;
output stop,dir;
output[7:0] clearup,cleardown,clear;
reg stop,dir;
reg[7:0] clear,up,down,testup,testdown,clearup,cleardown;
always @(up_s or up_f or down_s or down_f or floor or rst)
begin up=(up_s|up_f);down=(down_s|down_f);testup=up&floor;testdown=down&floor;end
always @(floor or rst or up or down)
begin
if(!rst)begin stop=0;dir=1;clear=8'b00000000;clearup=8'b00000000;cleardown=8'b00000000;end
else begin if(up!=0||down!=0)begin if(dir)if(up==0)dir=0;else if(down==0)dir=1;else ;
if(up!=0&&dir==1) begin case(floor)
8'b00000001:if(testup[0]==0)begin stop=0;clearup[0]=0;end else begin stop=1;clearup[0]=1;end
8'b00000010:if(testup[1]==0)begin stop=0;clearup[1]=0;end else begin stop=1;clearup[1]=1;end
8'b00000100:if(testup[2]==0)begin stop=0;clearup[2]=0;end else begin stop=1;clearup[2]=1;end
8'b00001000:if(testup[3]==0)begin stop=0;clearup[3]=0;end else begin stop=1;clearup[3]=1;end
8'b00010000:if(testup[4]==0)begin stop=0;clearup[4]=0;end else begin stop=1;clearup[4]=1;end
8'b00100000:if(testup[5]==0)begin stop=0;clearup[5]=0;end else begin stop=1;clearup[5]=1;end
8'b01000000:if(testup[6]==0)begin stop=0;clearup[6]=0;end else begin stop=1;clearup[6]=1;end
8'b10000000:if(testup[7]==0)begin stop=0;clearup[7]=0;end else begin stop=1;clearup[7]=1;end
default:begin clearup=8'b00000000;stop=0;end endcase end
else if(down!=0&&dir==0)begin case(floor)
8'b00000001:if(testdown[0]==0)begin stop=0;cleardown[0]=0;end
else begin stop=1;cleardown[0]=1;end
8'b00000010:if(testdown[1]==0)begin stop=0;cleardown[1]=0;end
else begin stop=1;cleardown[1]=1;end
8'b00000100:if(testdown[2]==0)begin stop=0;cleardown[2]=0;end
else begin stop=1;cleardown[2]=1;end
8'b00001000:if(testdown[3]==0)begin stop=0;cleardown[3]=0;end
else begin stop=1;cleardown[3]=1;end
8'b00010000:if(testdown[4]==0)begin stop=0;cleardown[4]=0;end
else begin stop=1;cleardown[4]=1;end
8'b00100000:if(testdown[5]==0)begin stop=0;cleardown[5]=0;end
else begin stop=1;cleardown[5]=1;end
8'b01000000:if(testdown[6]==0)begin stop=0;cleardown[6]=0;end
else begin stop=1;cleardown[6]=1;end
8'b10000000:if(testdown[7]==0)begin stop=0;cleardown[7]=0;end
else begin stop=1;cleardown[7]=1;end
default:begin cleardown=8'b00000000;stop=0;end endcase end
else stop=0;
clear=(cleardown|clearup);
end
else stop=1; end end
endmodule
五、系统仿真:
显示某块仿真:
内部楼层选择仿真:
电梯外部选择仿真:
门控制仿真:
主控制模块仿真:
总系统仿真:
六、总结
通过对这个程序的编写,使我进对FPGA语言有了更进一步的了解。也更叫熟练的掌握了起语言的特点。为以后的程序编写工作打下了良好的基础。
编写的过程中遇到了许多的问题,通过问同学,查资料来解决问题,加深了自己的印象。此次设计中另外一个重要的收获就是学会通过分析波形来发现程序的错误,来查看程序实现的功能,来检测跟踪某个变量学会组织设计思路和通过分析波形来检验设计结果是我本次最大的收获。。
参考文献:
1 黄智伟 FPGA系统设计与实践 北京:电子工业出版社2005.1
2 王振红 VHDL数字电路设计与应用实践教程 北京:机械工业出版社2003.6
3 付家才 EDA原理与应用 北京:化学工业出版社2001.5
11
展开阅读全文