EDA实验综合设计报告.docx
《EDA实验综合设计报告.docx》由会员分享,可在线阅读,更多相关《EDA实验综合设计报告.docx(17页珍藏版)》请在冰豆网上搜索。
EDA实验综合设计报告
EDA实验综合设计报告
十字路口交通信号控制系统设计
姓名:
学号指导老师:
年月日
一、概述
1、设计任务要求:
(1)东西(用A表示)、南北(用B表示)方向均有绿灯、黄灯、红灯指示,持续时间A、B方向分别各用一个2位十进制数进行预置,预置时个位和十位数字均用4位BCD码表示。
交通灯运行的切换示意图和时序图分别如图1和如图2所示,其中aredtime、agreentime、bredtime、bgreentime、yellowtime分别以35s、40s、45s、30s、5s为例。
图2交通控制系统时序图
(2)系统设有时钟,以倒计时方式显示每一路允许通行的时间。
(3)当东西或南北两路中任一路出现特殊情况时,系统可由交警手动控制立即进入特殊运行状态,即红灯全亮,时钟停止计时,东西、南北两路所有车辆停止通行;当特殊运行状态结束后,系统恢复工作,继续正常运行。
2、所用软件工具和硬件平台
(1)软件:
QuartusII9.0
QuartusII是Altera公司的综合性PLD/FPGA开发软件,原理图、VHDL、VerilogHDL以及AHDL(AlteraHardware支持DescriptionLanguage)等多种设计输入形式,内嵌自有的综合器以及仿真器,可以完成从设计输入到硬件配置的完整PLD设计流程。
(2)硬件平台:
台湾友晶科技DE0FPGA开发板
台湾友晶科技DE0FPGA开发板是一套轻薄型的开发板,参考设计和相关配件一应俱全,简单上手,非常适合初学者用来学习FPGA逻辑设计与计算机架构。
DE0FPGA开发板搭载了AlteraCycloneIII系列的EP3C16FPGA,可提供15408个逻辑单元(LE)以及346个用户I/O。
此外,DE0开发板还搭配了丰富的外部资源,非常适合于EDA实验类教学课程,并足够开发较复杂的数字系统。
二、实现原理
本系统主要由分频器、时序控制器、状态转移控制器、倒计时计数器、路口红绿灯状态显示器、倒计时显示器等电路组成。
分频器将晶体振送来的5MHz信号变为1Hz时钟信号;控制器控制系统的状态转移和红、黄、绿灯的信号输入;倒计时显示电路实现A路40、5、35秒以及B路45、30、5秒倒计时和显示功能。
整个系统的工作时序受控制器控制,它是系统的核心。
三、实现方法
1、本设计实现方案分析
整个系统的工作过程用状态机进行描述,其状态转移如图3所示,5种状态描述如下:
s0=A方向绿灯亮,B方向红灯亮,此状态持续为agreentime(40s);
s1=A方向黄灯亮,B方向红灯亮,此状态持续yellowtime(5s);
s2=A方向红灯亮,B方向绿灯亮,此状态持续bgreentime(30s);
s3:
A方向红灯亮,B方向黄灯亮,此状态持续yellowtime(5s);
s4:
紧急制动状态,A方向红灯亮,B方向红灯亮,当紧急制动信号有效时(hold=1)进入这种状态。
当紧急制动信号无效(hold=0)时,状态机按照s0—s1—s2—s3—s0循环;当紧急制动信号有效(hold=1)时,状态机立即转入s4两个方向红灯全亮;当紧急制动信号再次恢复无效(hold=0)时,状态机会回到初始状态s0继续执行。
状态机进入不同的状态,计数器从不同的初始值开始减法计数,当减到0时,切换到下一个状态。
计数器的计数值通过七段译码器模块译码后显示。
2、本设计实现转移图
图3交通控制系统状态转移图
四、实现过程
1、各模块具体实现
(1)分频器devide.vhd文件
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_arith.all;
useieee.std_logic_unsigned.all;
entitydevideis
generic(
sys_clk_fre_value:
integer:
=50000000;
div_clk_fre_value:
integer:
=1
);
port(
i_sys_clk:
instd_logic;
clk:
outstd_logic
);
endentitydevide;
architecturearcdivofdevideis
signalr_div_count:
std_logic_vector(31downto0);
signalr_div_clk:
std_logic;
begin
process(i_sys_clk,r_div_count)
begin
if(i_sys_clk'eventandi_sys_clk='1')then
if(r_div_count=sys_clk_fre_value/div_clk_fre_value/2-1)then
r_div_count<=x"00000000";
r_div_clk<=notr_div_clk;
else
r_div_count<=r_div_count+1;
endif;
endif;
endprocess;
clk<=r_div_clk;
endarchitecturearcdiv;
(2)主要部分traffic_light.vhd文件
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytraffic_lightis
port(
rst:
instd_logic;
clk:
instd_logic;
hold:
instd_logic;
ared,agreen,ayellow,bred,bgreen,byellow:
outstd_logic;
aseg7_h,aseg7_l:
outstd_logic_vector(6downto0);
bseg7_h,bseg7_l:
outstd_logic_vector(6downto0)
);
endtraffic_light;
architecturearcoftraffic_lightis
constantaredtime_h:
std_logic_vector(3downto0):
="0011";
constantaredtime_l:
std_logic_vector(3downto0):
="0101";--aredtime35s
constantagreentime_h:
std_logic_vector(3downto0):
="0100";
constantagreentime_l:
std_logic_vector(3downto0):
="0000";--agreentime40s
constantbredtime_h:
std_logic_vector(3downto0):
="0100";
constantbredtime_l:
std_logic_vector(3downto0):
="0101";--bredtime45s
constantbgreentime_h:
std_logic_vector(3downto0):
="0011";
constantbgreentime_l:
std_logic_vector(3downto0):
="0000";--bgreentime30s
constantyellowtime_h:
std_logic_vector(3downto0):
="0000";
constantyellowtime_l:
std_logic_vector(3downto0):
="0101";--yellowtime5s
signalacount_h,acount_l,bcount_h,bcount_l:
std_logic_vector(3downto0);
typestate_typeis(s0,s1,s2,s3,s4);
signalc_state,n_state:
state_type;
begin
process
begin
waituntilclk'eventandclk='1';
ifrst='1'then
c_state<=s0;
else
c_state<=n_state;
endif;
endprocess;
--statechange状态机的状态转移关系描述
process(hold,c_state,acount_h,acount_l,bcount_h,bcount_l)
begin
n_state<=c_state;
casec_stateis
whens0=>
ifhold='1'then
n_state<=s4;
elsifacount_h="0000"andacount_l="0000"then
n_state<=s1;
endif;
whens1=>
ifhold='1'then
n_state<=s4;
elsifacount_h="0000"andacount_l="0000"then
n_state<=s2;
endif;
whens2=>
ifhold='1'then
n_state<=s4;
elsifbcount_h="0000"andbcount_l="0000"then
n_state<=s3;
endif;
whens3=>
ifhold='1'then
n_state<=s4;
elsifacount_h="0000"andacount_l="0000"then
n_state<=s0;
endif;
whens4=>
ifhold='0'then
n_state<=s0;
endif;
endcase;
endprocess;
--count十进制倒计时计数器的描述
process
begin
waituntilclk'eventandclk='1';
ifc_state/=n_stateorrst='1'then
ifn_state=s0then
acount_h<=agreentime_h;
acount_l<=agreentime_l;
bcount_h<=bredtime_h;
bcount_l<=bredtime_l;
elsifn_state=s1then
acount_h<=yellowtime_h;
acount_l<=yellowtime_l;
bcount_h<=bredtime_h;
bcount_l<=bredtime_l;
elsifn_state=s2then
acount_h<=aredtime_h;
acount_l<=aredtime_l;
bcount_h<=bgreentime_h;
bcount_l<=bgreentime_l;
elsifn_state=s3then
acount_h<=aredtime_h;
acount_l<=aredtime_l;
bcount_h<=bgreentime_h;
bcount_l<=bgreentime_l;
endif;
else
ifacount_l="0000"then
acount_l<="1001";
acount_h<=acount_h-1;
else
acount_l<=acount_l-1;
endif;
ifbcount_l="0000"then
bcount_l<="1001";
bcount_h<=bcount_h-1;
else
bcount_l<=bcount_l-1;
endif;
endif;
endprocess;
--LEDtrafficlight每个状态下两个路口红绿灯的状态描述
process(c_state)
begin
casec_stateis
whens0=>
ared<='0';
agreen<='1';
ayellow<='0';
bred<='1';
bgreen<='0';
byellow<='0';
whens1=>
ared<='0';
agreen<='0';
ayellow<='1';
bred<='1';
bgreen<='0';
byellow<='0';
whens2=>
ared<='1';
agreen<='0';
ayellow<='0';
bred<='0';
bgreen<='1';
byellow<='0';
whens3=>
ared<='1';
agreen<='0';
ayellow<='0';
bred<='0';
bgreen<='0';
byellow<='1';
whens4=>
ared<='1';
agreen<='0';
ayellow<='0';
bred<='1';
bgreen<='0';
byellow<='0';
endcase;
endprocess;
--decodedisplaying倒计时计数器的显示译码
process(acount_h)
begin
caseacount_his
when"0000"=>aseg7_h<="0000001";
when"0001"=>aseg7_h<="1001111";
when"0010"=>aseg7_h<="0010010";
when"0011"=>aseg7_h<="0000110";
when"0100"=>aseg7_h<="1001100";
when"0101"=>aseg7_h<="0100100";
when"0110"=>aseg7_h<="0100000";
when"0111"=>aseg7_h<="0001111";
when"1000"=>aseg7_h<="0000000";
when"1001"=>aseg7_h<="0000100";
when"1010"=>aseg7_h<="0001000";
when"1011"=>aseg7_h<="1100000";
when"1100"=>aseg7_h<="0110001";
when"1101"=>aseg7_h<="1000010";
when"1110"=>aseg7_h<="0110000";
when"1111"=>aseg7_h<="0111000";
whenothers=>null;
endcase;
endprocess;
process(acount_l)
begin
caseacount_lis
when"0000"=>aseg7_l<="0000001";
when"0001"=>aseg7_l<="1001111";
when"0010"=>aseg7_l<="0010010";
when"0011"=>aseg7_l<="0000110";
when"0100"=>aseg7_l<="1001100";
when"0101"=>aseg7_l<="0100100";
when"0110"=>aseg7_l<="0100000";
when"0111"=>aseg7_l<="0001111";
when"1000"=>aseg7_l<="0000000";
when"1001"=>aseg7_l<="0000100";
when"1010"=>aseg7_l<="0001000";
when"1011"=>aseg7_l<="1100000";
when"1100"=>aseg7_l<="0110001";
when"1101"=>aseg7_l<="1000010";
when"1110"=>aseg7_l<="0110000";
when"1111"=>aseg7_l<="0111000";
whenothers=>null;
endcase;
endprocess;
process(bcount_h)
begin
casebcount_his
when"0000"=>bseg7_h<="0000001";
when"0001"=>bseg7_h<="1001111";
when"0010"=>bseg7_h<="0010010";
when"0011"=>bseg7_h<="0000110";
when"0100"=>bseg7_h<="1001100";
when"0101"=>bseg7_h<="0100100";
when"0110"=>bseg7_h<="0100000";
when"0111"=>bseg7_h<="0001111";
when"1000"=>bseg7_h<="0000000";
when"1001"=>bseg7_h<="0000100";
when"1010"=>bseg7_h<="0001000";
when"1011"=>bseg7_h<="1100000";
when"1100"=>bseg7_h<="0110001";
when"1101"=>bseg7_h<="1000010";
when"1110"=>bseg7_h<="0110000";
when"1111"=>bseg7_h<="0111000";
whenothers=>null;
endcase;
endprocess;
process(bcount_l)
begin
casebcount_lis
when"0000"=>bseg7_l<="0000001";
when"0001"=>bseg7_l<="1001111";
when"0010"=>bseg7_l<="0010010";
when"0011"=>bseg7_l<="0000110";
when"0100"=>bseg7_l<="1001100";
when"0101"=>bseg7_l<="0100100";
when"0110"=>bseg7_l<="0100000";
when"0111"=>bseg7_l<="0001111";
when"1000"=>bseg7_l<="0000000";
when"1001"=>bseg7_l<="0000100";
when"1010"=>bseg7_l<="0001000";
when"1011"=>bseg7_l<="1100000";
when"1100"=>bseg7_l<="0110001";
when"1101"=>bseg7_l<="1000010";
when"1110"=>bseg7_l<="0110000";
when"1111"=>bseg7_l<="0111000";
whenothers=>null;
endcase;
endprocess;
endarc;
2、仿真波形
(1)紧急制动
hold=1时,紧急制动,ared=bred=1。
(2)重置
rst=1时,重置,从s0开始运行。
(3)分频器
验证分频器功能,改为二分频。
波形为:
、
(4)整体运行波形
五、实现结果
达到预期效果,LED灯,倒计时计数器,rst、hold键工作正常。
六、结论
存在问题:
倒计时计数的波形不正常;
解决方法:
发现计数器环节有小的编写错误,将“acount_h<=acount_h+1;”
“acount_h<=acount_h+1;”两条语句中的“+”改成“-”,即“acount_h<=acount_h-1;”“acount_h<=acount_h-1;”。
收获:
第一次系统进行了数字系统设计,对QuartusII的使用有了自己的理解。
虽然已有知识还是很有限,但因为有了一次完整的设计体验,我相信这对以后的帮助是无穷的。
七、参考文献
【1】孙万蓉、任爱锋等,《数字电路与系统设计》,高等教育出版社,2015年4月
【2】任爱锋、袁晓光,《数字电路与EDA实验》,西安电子科技大学出版社,2017年3月
五、实现结果
达到部分预期效果,有些功能未实现。
六、结论
存在问题:
倒计时计数的波形不正常;
解决方法:
发现计数器环节有小的编写错误,将“acount_h<=acount_h+1;”
“acount_h<=acount_h+1;”两条语句中的“+”改成“-”,即“acount_h<=acount_h-1;”“acount_h<=acount_h-1;”。
收获:
第一次系统进行了数字系统设计,对QuartusII的使用有了自己的理解。
虽然已有知识还是很有限,但因为有了一次完整的设计体验,我相信这对以后的帮助是无穷的。
七、参考文献
【1】孙万蓉、任爱锋等,《数字电路与系统设计》,高等教育出版社,2015年4月
【2】任爱锋、袁晓光,《数字电路与EDA实验》,西安电子科技大学出版社,2017年3月
附录
devide.vhd文件和traffic_light.vhd文件已在正文中给出,下面给出顶层文件、原理图和管脚锁定。
1、顶层文件project_traffic_light.vhd:
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityproject_traffic_lightis
port(
i_sys_clk:
instd_logic;
rst:
instd_logic;
hold:
instd_logic;
ared,agreen,ayellow,bred,bg