交通灯信号控制的设计.docx
《交通灯信号控制的设计.docx》由会员分享,可在线阅读,更多相关《交通灯信号控制的设计.docx(15页珍藏版)》请在冰点文库上搜索。
交通灯信号控制的设计
E
D
A
技
术
及
应
用
实
验
报
告
姓名:
XXX
班级:
XXX
学号:
XXX
湖南工业大学科技学院
实验/上机报告
课程名称:
EDA技术及应用
专业:
电气工程及其自动化
成绩:
指导教师:
XXX
姓名:
XXX
日期:
XXX
项目序号:
XXX
学号:
XXX
时间:
XXX
项目名称:
交通灯信号控制的设计
组号:
地点:
XXX
一、实验目的
1、通过一个简单交通信号灯控制器的设计,认识状态机的典型程序结构
2、掌握同步时序系统的VHDL设计方法
二、实验环境
QuartusII7.0开发系统。
三、实验内容
1、完成一个简单交通信号灯控制器的设计并实现功能仿真和硬件模拟运行
2、考虑一定安全性策略,在前者的基础上改进系统设计,并实现功能仿真和硬件模拟运行
四、实验过程
设计思想:
交通信号灯控制器工作原理如下:
假设主路(main)和支路(spur)的通行时间为Tm、Ts,过渡时间(interim)为Ti。
当主路为绿灯(maingreen)时通行Tm后,转到过渡阶段,点亮黄色(mainyellow)信号灯,在经过Ti后,主路红灯(mainred)点亮,支路绿灯(spurgreen)点亮,支路绿灯点亮的持续时间为Ts,然后点亮黄色(spuryellow)信号灯,在经过Ti后,支路红灯(spurred)点亮,主路绿灯(maingreen)点亮,重复上一次循环。
实验步骤:
根据交通信号灯工作原理,可以得到如下交通信号灯控制器的状态转换图:
由该状态转换图可以看出,交通信号灯控制器的状态转换条件是分别由Tm、Ti、Ts控制的,因此,需要设计Tm、Ti、Ts三个定时器。
另外,为了实现状态转换和信号灯控制信号,还需要设计状态控制电路和输出译码电路。
因此,可知该交通信号灯控制原理框图包括定时器、状态控制器和输出译码器三部分。
下面分别对各部分单元进行设计,然后再由这些单元构成整个交通信号灯控制器电路:
1、定时电路
根据定时时间的长短,设计相应的计数器,实现定时的功能,这里我们分别将主路、支路、过渡阶段的定时时间设置为45s、25s、5s,且这些定时电路都受状态定时控制电路的控制。
2、源程序如下:
灯控制器电路设计
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
ENTITYJTDKZIS
PORT(CLK,SM,SB:
INSTD_LOGIC;
MR,MY,MG,BR,BY,BG:
OUTSTD_LOGIC);
ENDENTITYJTDKZ;
ARCHITECTUREARTOFJTDKZIS
TYPESTATE_TYPEIS(A,B,C,D);
SIGNALSTATE:
STATE_TYPE;
BEGIN
CNT:
PROCESS(CLK)IS
VARIABLES:
INTEGERRANGE0TO45;
VARIABLECLR,EN:
BIT;
BEGIN
IF(CLK'EVENTANDCLK='1')THEN
IFCLR='0'THEN
S:
=0;
ELSIFEN='0'THEN
S:
=S;
ELSE
S:
=S+1;
ENDIF;
CASESTATEIS
WHENA=>MR<='0';MY<='0';MG<='1';
BR<='1';BY<='0';BG<='0';
IF(SBANDSM)='1'THEN
IFS=45THEN
STATE<=B;CLR:
='0';EN:
='0';
ELSE
STATE<=A;CLR:
='1';EN:
='1';
ENDIF;
ELSIF(SBAND(NOTSM))='1'THEN
STATE<=B;CLR:
='0';EN:
='0';
ELSE
STATE<=A;CLR:
='1';EN:
='1';
ENDIF;
WHENB=>MR<='0';MY<='1';MG<='0';
BR<='1';BY<='0';BG<='0';
IFS=5THEN
STATE<=C;CLR:
='0';EN:
='0';
ELSE
STATE<=B;CLR:
='1';EN:
='1';
ENDIF;
WHENC=>MR<='1';MY<='0';MG<='0';
BR<='0';BY<='0';BG<='1';
IF(SMANDSB)='1'THEN
IFS=25THEN
STATE<=D;CLR:
='0';EN:
='0';
ELSE
STATE<=C;CLR:
='1';EN:
='1';
ENDIF;
ELSIFSB='0'THEN
STATE<=D;CLR:
='0';EN:
='0';
ELSE
STATE<=C;CLR:
='1';EN:
='1';
ENDIF;
WHEND=>MR<='1';MY<='0';MG<='0';
BR<='0';BY<='1';BG<='0';
IFS=5THEN
STATE<=A;CLR:
='0';EN:
='0';
ELSE
STATE<=D;CLR:
='1';EN:
='1';
ENDIF;
ENDCASE;
ENDIF;
ENDPROCESSCNT;
ENDARCHITECTUREART;
计数器的设计
----CNT45S.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT45SIS
PORT
(SB,CLK,EN45:
INSTD_LOGIC;
DOUT45M,DOUT45B:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYCNT45S;
ARCHITECTUREARTOFCNT45SIS
SIGNALCNT6B:
STD_LOGIC_VECTOR(5DOWNTO0);
BEGIN
PROCESS(SB,CLK,EN45)IS
BEGIN
IFSB='0'THENCNT6B<=CNT6B-CNT6B-1;
ELSIF(CLK'EVENTANDCLK='1')THEN
IFEN45='1'THENCNT6B<=CNT6B+1;
ELSIFEN45='0'THENCNT6B<=CNT6B-CNT6B-1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CNT6B)IS
BEGIN
CASECNT6BIS
WHEN"000000"=>DOUT45M<="01000101";DOUT45B<="01010000";
WHEN"000001"=>DOUT45M<="01000100";DOUT45B<="01001011";
WHEN"000010"=>DOUT45M<="01000011";DOUT45B<="01001000";
WHEN"000011"=>DOUT45M<="01000010";DOUT45B<="01000111";
WHEN"000100"=>DOUT45M<="01000001";DOUT45B<="01000110";
WHEN"000101"=>DOUT45M<="01000000";DOUT45B<="01000101";
WHEN"000110"=>DOUT45M<="00111001";DOUT45B<="01000100";
WHEN"000111"=>DOUT45M<="00111000";DOUT45B<="01000011";
WHEN"001000"=>DOUT45M<="00110111";DOUT45B<="01000010";
WHEN"001001"=>DOUT45M<="00110110";DOUT45B<="01000001";
WHEN"001010"=>DOUT45M<="00110101";DOUT45B<="01000000";
WHEN"001011"=>DOUT45M<="00110100";DOUT45B<="01101001";
WHEN"001100"=>DOUT45M<="00110011";DOUT45B<="00111000";
WHEN"001101"=>DOUT45M<="00110010";DOUT45B<="00110111";
WHEN"001110"=>DOUT45M<="00110001";DOUT45B<="00110110";
WHEN"001111"=>DOUT45M<="00110000";DOUT45B<="00110101";
WHEN"010000"=>DOUT45M<="00101001";DOUT45B<="00110100";
WHEN"010001"=>DOUT45M<="00101000";DOUT45B<="00110011";
WHEN"010010"=>DOUT45M<="00100111";DOUT45B<="00110010";
WHEN"010011"=>DOUT45M<="00100110";DOUT45B<="00110001";
WHEN"010100"=>DOUT45M<="00100101";DOUT45B<="00110000";
WHEN"010101"=>DOUT45M<="00100100";DOUT45B<="00101001";
WHEN"010110"=>DOUT45M<="00100011";DOUT45B<="00101000";
WHEN"010111"=>DOUT45M<="00100010";DOUT45B<="00100111";
WHEN"011000"=>DOUT45M<="00100001";DOUT45B<="00100110";
WHEN"011001"=>DOUT45M<="00100000";DOUT45B<="00100101";
WHEN"011010"=>DOUT45M<="00011001";DOUT45B<="00100100";
WHEN"011011"=>DOUT45M<="00011000";DOUT45B<="00100011";
WHEN"011100"=>DOUT45M<="00010111";DOUT45B<="00100010";
WHEN"011101"=>DOUT45M<="00010110";DOUT45B<="00100001";
WHEN"011110"=>DOUT45M<="00010101";DOUT45B<="00100000";
WHEN"011111"=>DOUT45M<="00010100";DOUT45B<="00011001";
WHEN"100000"=>DOUT45M<="00010011";DOUT45B<="00011000";
WHEN"100001"=>DOUT45M<="00010010";DOUT45B<="00010111";
WHEN"100010"=>DOUT45M<="00010001";DOUT45B<="00010110";
WHEN"100011"=>DOUT45M<="00010000";DOUT45B<="00010101";
WHEN"100100"=>DOUT45M<="00001001";DOUT45B<="00010100";
WHEN"100101"=>DOUT45M<="00001000";DOUT45B<="00010011";
WHEN"100110"=>DOUT45M<="00000111";DOUT45B<="00010010";
WHEN"100111"=>DOUT45M<="00000110";DOUT45B<="00010001";
WHEN"101000"=>DOUT45M<="00000101";DOUT45B<="00010000";
WHEN"101001"=>DOUT45M<="00000100";DOUT45B<="00001001";
WHEN"101010"=>DOUT45M<="00000011";DOUT45B<="00001000";
WHEN"101011"=>DOUT45M<="00000010";DOUT45B<="00000111";
WHEN"101100"=>DOUT45M<="00000001";DOUT45B<="00000110";
WHENOTHERS=>DOUT45M<="00000000";DOUT45B<="00000000";
ENDCASE;
ENDPROCESS;
ENDARCHITECTUREART;
--CNT25S.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT25SIS
PORT(SB,SM,CLK,EN25:
INSTD_LOGIC;
DOUT25M,DOUT25B:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITY;
ARCHITECTUREARTOFCNT25SIS
SIGNALCNT5B:
STD_LOGIC_VECTOR(4DOWNTO0);
BEGIN
PROCESS(SB,SM,CLK,EN25)IS
BEGIN
IFSB='0'ORSM='0'THEN
CNT5B<=CNT5B-CNT5B-1;
ELSIF(CLK'EVENTANDCLK='1')THEN
IFEN25='1'THEN
CNT5B<=CNT5B+1;
ELSIFEN25='0'THEN
CNT5B<=CNT5B-CNT5B-1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CNT5B)IS
BEGIN
CASECNT5BIS
WHEN"00000"=>DOUT25B<="00100101";DOUT25M<="00110000";
WHEN"00001"=>DOUT25B<="00100100";DOUT25M<="00101001";
WHEN"00010"=>DOUT25B<="00100011";DOUT25M<="00101000";
WHEN"00011"=>DOUT25B<="00100010";DOUT25M<="00100111";
WHEN"00100"=>DOUT25B<="00100001";DOUT25M<="00100110";
WHEN"00101"=>DOUT25B<="00100000";DOUT25M<="00100101";
WHEN"00110"=>DOUT25B<="00011001";DOUT25M<="00100100";
WHEN"00111"=>DOUT25B<="00011000";DOUT25M<="00100011";
WHEN"01000"=>DOUT25B<="00010111";DOUT25M<="00100010";
WHEN"01001"=>DOUT25B<="00010110";DOUT25M<="00100001";
WHEN"01010"=>DOUT25B<="00010101";DOUT25M<="00100000";
WHEN"01011"=>DOUT25B<="00010100";DOUT25M<="00011001";
WHEN"01100"=>DOUT25B<="00010011";DOUT25M<="00011000";
WHEN"01101"=>DOUT25B<="00010010";DOUT25M<="00010111";
WHEN"01110"=>DOUT25B<="00010001";DOUT25M<="00010110";
WHEN"01111"=>DOUT25B<="00010000";DOUT25M<="00010101";
WHEN"10000"=>DOUT25B<="00001001";DOUT25M<="00010100";
WHEN"10001"=>DOUT25B<="00001001";DOUT25M<="00010100";
WHEN"10010"=>DOUT25B<="00001000";DOUT25M<="00010011";
WHEN"10011"=>DOUT25B<="00000110";DOUT25M<="00010001";
WHEN"10100"=>DOUT25B<="00000101";DOUT25M<="00010000";
WHEN"10101"=>DOUT25B<="00000100";DOUT25M<="00001001";
WHEN"10110"=>DOUT25B<="00000011";DOUT25M<="00001000";
WHEN"10111"=>DOUT25B<="00000010";DOUT25M<="00000111";
WHEN"11000"=>DOUT25B<="00000001";DOUT25M<="00000110";
WHENOTHERS=>DOUT25B<="00000000";DOUT25M<="00000000";
ENDCASE;
ENDPROCESS;
ENDARCHITECTUREART;
--CNT05S.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYCNT05SIS
PORT
(CLK,EN05M,EN05B:
INSTD_LOGIC;
DOUT5:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYCNT05S;
ARCHITECTUREARTOFCNT05SIS
SIGNALCNT3B:
STD_LOGIC_VECTOR(2DOWNTO0);
BEGIN
PROCESS(CLK,EN05M,EN05B)IS
BEGIN
IF(CLK'EVENTANDCLK='1')THEN
IFEN05M='1'THENCNT3B<=CNT3B+1;
ELSIFEN05B='1'THENCNT3B<=CNT3B+1;
ELSIFEN05B='0'THENCNT3B<=CNT3B-CNT3B-1;
ENDIF;
ENDIF;
ENDPROCESS;
PROCESS(CNT3B)IS
BEGIN
CASECNT3BIS
WHEN"000"=>DOUT5<="00000101";
WHEN"001"=>DOUT5<="00000100";
WHEN"010"=>DOUT5<="00000011";
WHEN"011"=>DOUT5<="00000010";
WHEN"100"=>DOUT5<="00000001";
WHENOTHERS=>DOUT5<="00000000";
ENDCASE;
ENDPROCESS;
ENDARCHITECTUREART;
显示控制部分设计
--XSKZ.VHD
LIBRARYIEEE;
USEIEEE.STD_LOGIC_1164.ALL;
USEIEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITYXSKZIS
PORT(EN45,EN25,EN05M,EN05B:
INSTD_LOGIC;
AIN45M,AIN45B:
INSTD_LOGIC_VECTOR(7DOWNTO0);
AIN25M,AIN25B,AIN05:
INSTD_LOGIC_VECTOR(7DOWNTO0);
DOUTM,DOUTB:
OUTSTD_LOGIC_VECTOR(7DOWNTO0));
ENDENTITYXSKZ;
ARCHITECTUREARTOFXSKZIS
BEGIN
PROCESS(EN45,EN25,EN05M,EN05B)IS
BEGIN
IFEN45='1'THEN
DOUTM<=AIN45M(7DOWNTO0);DOUTB<=AIN45B(7DOWNTO0);
ELSIFEN05M='1'THEN
DOUTM<=AIN05(7DOWNTO0);DOUTB<=AIN05(7DOWNTO0);
ELSIFEN25='1'THEN
DOUTM<=AIN25M(7DOWNTO0);DOUTB<=AIN25B(7DOWNTO0);
ELSIFEN05B='1'THEN
DOUTM<=AIN05(7DOWNTO0);DOUTB<=AIN05(7DOWNTO0);
ENDIF;
ENDPROCESS;
ENDARCHITECTUREART;
仿真图如下:
五、实验总结
在本次实验中,真正问题开始出现是在各部分单元都设计好之后,由于最开始我考虑的是通过一个主程序即将每个部分单元联系起来了,因此可以直接对主程序进行元件例化,然后通过对主程序元件进行编译、仿真、配置和下载。
这里。
由前面的交通信号灯控制器电路原理图可以看出,该电路是由每部分单元生成的元件构成的。
很显然,通过主程序进行元件例子化的思路即是错误的。
在具体的设计过程中,通过实际操作中发现的问题,可以发现很多在以前实验中不曾注意到得细节问题。
而根据出现的问题做出解决的措施,又可以掌握很多知识要点。
可见在实验过程中还是要出现问题,并且有勇气去解决出现的问题,才能够真正学到有用的知识。
而只有真正把学到的知识融会贯通,才能更灵活地运用到以后的设计中去。