EDA交通灯课程设计实验报告 .doc
EDA交通灯课程设计 实验报告 学院:通信与信息工程学院 专业:电子信息工程 班级:0120902 目 录交通灯控制系统的设计11.设计要求11.1 实现基本要求及扩展11.2 附加要求12 设计思路13 状态机变化图23.1 状态机变化图24 设计步骤及程序34.1 主体程序代码34.2 分频程序代码54.3 计数器程序代码64.4 二选一数据选择器程序代码7when others=> seg<=b;dig<="11101110"8end case;8end process;8end;84.5 控制系统电路图85 硬件实现及调试结果85.1 硬件测试结构示意85.2 软件仿真结果96. 心得体会9交通灯控制系统的设计1.设计要求1.1 实现基本要求及扩展1.能显示十字路口东西、南北两个方向的红、黄、绿灯的指示状态,用两组红、黄、绿三色灯作为两个方向的红、黄、绿灯; 每次通行时间为15S,2.能实现正常的倒计时功能,用两组数码管作为东西、南北向的倒计时显示。其中,黄灯:3S。3.当出现一方出现红灯,另一方出现绿灯时,出现红灯的之路左转弯灯亮。4.能实现特殊状态的功能。按下Sw0键后,能实现以下特殊功能: (1) 四个数码管的显示都为0,(2)东西、南北路口均显示红灯状态; 5.用VHDL语言设计上述功能的交通灯控制器,并用含有四个状态的状态机; 1.2 附加要求1.时钟输入:clkin=1KHz;2.采用分频器分成:1Hz,然后提供给系统。2 设计思路交通灯控制器的电路控制原理框图如图1所示,主要包括分频器模块、计数器模块、主控制器模块和二选一数据选择器模块。计数器模块以秒为单位倒计时,当计数值依次加一,直至“1111”,再进行下次的计数循环。分频器模块将1000HZ的频率转化为1HZ。数据选择器模块完成数码管个位和十位的seg选择,从而完成两位数字的显示。核心部分是主控制模块。具体控制情况见表1。图1 电路控制原理框图状态干道1干道2时间/s10100001红灯与左转灯亮绿灯亮1200100010红灯亮黄灯亮301001100绿灯亮红灯与左转灯亮1200001010黄灯亮红灯亮3表1 交通灯控制表3 状态机变化图3.1 状态机变化图根据交通灯的流程图,可以得到如图2所示的控制状态转换图。从图2的状态转换可以看出,交通灯电路应该能够具有以下几个功能:计数功能、状态控制功能(实现交通信号灯的状态控制和计时器控制)、译码功能及二选一数据选择器(实现4位数码管的显示功能)。对于实现上述功能的交通信号灯控制器电路,需要设计以下各个电路单元。图2控制状态转换图4 设计步骤及程序4.1 主体程序代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity zhu isport(QI:in std_logic_vector(3 downto 0); clk,reset:in std_logic; segshi,segge:out std_logic_vector(7 downto 0); led:out std_logic_vector(7 downto 0);end;architecture zhuti of zhu issignal state,led1:std_logic_vector(7 downto 0);signal seg1:std_logic_vector(7 downto 0);beginshiwei:process(clk,QI,reset)variable seg2:std_logic_vector(7 downto 0);beginif reset='0' then seg2:="00111111" elseif QI="0000" then seg2:="00000110"end if;if QI="0011" then seg2:="00111111"end if;end if;segshi<=seg2;end process;gewei:process(clk,QI,reset)beginif reset='0' then seg1<="00111111" elseif (QI="0010" or QI="1100" or QI="1111") then seg1<="00111111"end if;-0if (QI="0001" or QI="1011" or QI="1110") then seg1<="00000110"end if;-1if (QI="0000" or QI="1010" or QI="1101") then seg1<="01011011"end if;-2if QI="1001" then seg1<="01001111"end if;-3if QI="1000" then seg1<="01100110"end if;-4if QI="0111" then seg1<="01101101"end if;-5if QI="0110" then seg1<="01111101"end if;-6if QI="0101" then seg1<="00000111"end if;-7if QI="0100" then seg1<="01111111"end if;-8if QI="0011" then seg1<="01101111"end if;-9end if;segge<=seg1;end process;ledy:process(clk,reset)beginif reset='0' then state<="10100001" elsif clk'event and clk='1' thencase state iswhen "10100001"=> led1<=state; if QI="1011" then state<="00100010"end if;when "00100010"=> led1<=state; if QI="1110" then state<="01001100"end if;when "01001100"=> led1<=state; if QI="1011" then state<="00001010"end if;when "00001010"=> led1<=state; if QI="1110" then state<="10100001"end if;WHEN OTHERS=>NULL;end case;end if;led<=led1;end process;end;4.2 分频程序代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity fen is port(clkin:in std_logic; clkout:out std_logic);end fen;architecture a of fen is signal outq:std_logic:='0' signal countq:std_logic_vector(9 downto 0):="0000000000"begin process(clkin) begin if clkin'event and clkin='1'then if countq/=499 then countq<=countq+1; else outq<=not outq; countq<=(others=>'0'); end if; end if; end process; clkout<=outq;end a; 4.3 计数器程序代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity tim isport (clk:in std_logic; QO:out std_logic_vector(3 downto 0);end ;architecture jishuy of tim is signal Q1:std_logic_vector(3 downto 0);begin process(clk) beginif clk'event and clk='1' then Q1<=Q1+1;end if; end process; QO<=Q1;end jishuy; 4.4 二选一数据选择器程序代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity xuan isport(a,b:in std_logic_vector(7 downto 0); clk:in std_logic; dig,seg:out std_logic_vector(7 downto 0);end;architecture fhi of xuan isbegin process(clk) Begincase clk is when '0'=> seg<=a;dig<="11011101"when others=> seg<=b;dig<="11101110"end case;end process;end;4.5 控制系统电路图根据以上代码,进行编译,后得到如图3的电路原理图,我们可以明显的看出,由分频器,数据选择器,计数器,主控器四个部分组成的电路原理图。图3电路原理图5 硬件实现及调试结果5.1 硬件测试结构示意在进行硬件测试时,按键k1对应复位端reset。EDA实验开发系统上的时钟clk1对应计数时钟CLK,数码管dig0、dig1对应东西走向的时钟显示,数码管dig4、dig5对应南北走向的时钟显示。LED灯LED0、LED1、LED2、LED7对应东西走向的绿灯、黄灯、红灯和左转灯,LED3、LED4、LED5、LED6对应南北走向的绿灯、黄灯、红灯和左转灯。5.2 软件仿真结果通过软件仿真图4,我们可以看出,此电路系统符合设计要求,而且能正常工作。图4 软件仿真图6. 心得体会通过在 Quartus软件中的模拟仿真,验证了该电路可以实现预定功能,方案正确,即两个主干道交替通行,各干道通行12秒。绿灯转换成红灯前,黄灯先亮3秒。如此一直循环往复,实现十字交叉路口的交通控制。另外还可以加入人工控制端,即当遇到需要进行交通管制等情形时,可以由交通警察来手工控制路口信号灯的转换。这次的交通控制灯的设计深深我感觉程序调试最重要,试验软件、硬件熟悉其次。我在编完各模块程序之后,编译查错最初有三十几个错误,有输入错误、语法错误。一遍一遍的变异查错,直到没有错误。必须注意工程名和实体名一致,不然一般会出错。在没有错误之后可以进行波型仿真。若与理想的不同,再查看程序,有无原理上的编辑错误或没有查出的输入错误。都通过可以进行管脚配对,把程序烧入芯片,在实物机上看结果,从显示中得出还需改正的地方,再去改程序。必须注意没改一次都要编译,重新烧入。就这样一次又一次的实验中,我明白了凡是都是一步一步来的,要不停的努力,才会有结果。