收藏 分销(赏)

EDA交通灯课程设计带有测试平台testbench精讲.doc

上传人:w****g 文档编号:2935412 上传时间:2024-06-11 格式:DOC 页数:22 大小:1.67MB 下载积分:10 金币
下载 相关 举报
EDA交通灯课程设计带有测试平台testbench精讲.doc_第1页
第1页 / 共22页
EDA交通灯课程设计带有测试平台testbench精讲.doc_第2页
第2页 / 共22页


点击查看更多>>
资源描述
EDA技术课程设计 十字路口交通灯控制器设计 学 院 电气与信息工程 专 业 电子信息工程 班  级 0934111 课程名称 EDA技术 学号 0934111** 姓名 *俊豪 指导教师 *** 成绩评定· 一、指导教师评语(根据学生设计报告质量、答辩情况及其平时表现综合评定)。 二、评分 评分项目 设计报告评分 答辩评分 平时表现评分 合 计 (100分) 任务完成 情 况 (20分) 课程设计 报告质量 (40分) 表达情况 (10分) 回答问题 情 况 (10分) 工作态度与纪律 (10分) 独立工作 能力 (10分) 得分 课程设计成绩评定 班级 0934111 姓名 学号 0934111 成绩: 分(折合等级 ) 指导教师签字 年 月 日 、 目录 一、设计题目 1 二、设计任务和要求 1 三、EDA设计 2 3.1、明确系统的功能,并进行逻辑抽象 2 3.2、模块功能说明 3 3.3、波形仿真及分析 3 3.3.1、代码 3 3.3.2、各模块rtl电路及功能仿真和时序仿真 4 四、硬件测试 7 五、实验困难问题及解决措施 7 参考文献 9 附录 10 前 言 伴随着社会的发展以及人类生活水平的提高, EDA技术在电子信息、通信、自动、控制及计算机应用等领域的重要性日益突出。随着技术市场与人才市场对DEA需求的不断增加,交通的问题日益突出,单单依靠人力来指挥交通已经不可行了,所以设计交通灯来完成这个需求就显的越加迫切了。为了确保十字路口的行人和车辆顺利、畅通地通过,往往采用电子控制的交通信号来进行指挥。以下就是运用数字电子设计出的交通灯:其中红灯亮,表示该条路禁止通行;黄灯亮表示停车;绿灯亮表示允许通行。 一、设计题目 十字路口交通灯控制器设计。 二、设计任务和要求 用EDA技术设计一个十字路口的交通信号灯控制器,控制A、B两条交叉道路上的车辆通行,具体要求如下: 设计一个十字路口交通信号管理控制器。对于每个路口,可实现直行、停止、左转指示,并显示当前状态剩余时间 1. 每个方向有直行红灯、直行绿灯、停行黄灯和左转绿灯共4个LED指示灯组成; 2. 每个方向用两位数码管显示当前状态剩余时间; 3. 系统复位后进入东西直行,南北禁行状态; 4. 直行状态最后3秒内,绿灯闪烁状态; 三、EDA设计 由于本设计实验的功能较多,所以就采用模块化设计。整个程序设计基于8种状态,如下表所示: 交通灯状态转换表 状态S S1 S2 S3 S4 S5 S6 S7 S0 A方向 左拐a1 黄灯ay 绿灯ag 黄灯ay 红灯ar 红灯ar 红灯ar 红灯ar 亮灯时间 10s 4s 20s 4s 33 B方向 红灯br 红灯br 红灯br 红灯br 左拐b1 黄灯by 绿灯bg 黄灯by 亮灯时间 38s 10s 4s 15s 4s 注释:系统复位后进入A方向直行绿灯,B方向直行红灯的状态即S3。 A 方 向 B方向 监督 图1 A、B方向示意图 顶层模块 控制模块 分频模块 计数模块 显示模块 译码模块 图2 整体模块示意图 3.1、明确系统的功能,并进行逻辑抽象 如图1本方案可实现在确定时刻,倒计数数字显示能够及时变化,红黄绿灯能准确变化,考虑到实际应用,加入人工监督功能,通过改变频率来控制交通灯亮灭的时间的长短。本设计采用模块化设计,图2为本设计十字路口交通等系统的层次结构框图。 3.2、模块功能说明 1.主控制模块(kongzhi):控制系统输入输出之间联系。 2.显示模块(xianshi):显示倒计时时间和工作状。其输出用来驱动4位共阴数码管,并显示倒计时时间(动态扫描)。 3.分频模块(fenpin):本系统动态扫描需要1KHZ的脉冲而系统时钟需要1HZ的脉冲,分频器主要为系统提供所需要的时钟脉冲。该模块将1KHZ的脉冲信号进行分频,产生周期为1hz的方波,作为系统时钟信号的倒计时闪烁信号。 4.译码模块(yima):根据控制信号,驱动交通灯即LED的显示。 5.计数模块(jishu):用来设定A方向和B方向计时器的初值,并为显示模块提供倒计时时间。 6.顶层模块jiaotongdeng,连接各模块设计,使之成为一个有机体。 前5个模块分别进行仿真测试,成功后把所有.vhdl文件包含在工程jiaotongdeng,实现模块化设计。 3.3、波形仿真及分析 3.3.1、代码 见附录一。 3.3.2、各模块rtl电路及功能仿真和时序仿真 各模块分别建立工程文件,并进行功能仿真、时序仿真,前六个模块成功编译,得到正确仿真结果后,建立顶层模块。 模块一:控制模块(kongzhi) 图3 控制模块(kongzhi)rtl图 图4 控制模块(kongzhi)仿真图 模块二:计时模块(jishi) 图5 计时模块(jishi)rtl图 图6 计时模块(jishi)仿真图 模块三:显示模块(xianshi) 图7 显示模块(xianshi)rtl图 图8 显示模块(xianshi)仿真图 模块四:译码模块(yima) 图9 译码模块(yima)rtl图 图10 译码模块(yima)仿真图 模块五:分频模块(fenpin) 图11 分频模块(fenpin)rtl图 图12 分频模块(fenpin)仿真图 模块六:顶层模块 图13 本设计整体rtl图 四、硬件测试 编程下载和硬件测试的步骤如下: 1、 打开下载窗口。选择菜单“Tool“项的”programmer“,便可打开下载窗口。 2、 设置下载电缆。将ByteBlaster电缆的一端与微机的并行口相连,另一端10针插头与装有目标器件的PCB板上的插座相连。并在”Hardware Setup”中设置下载电缆。 3、设置JTAG链。Altera器件基本都支持JTAG在系统编程方式,这种方式简单易行,不需要专门的编程器。 4、选用模式NO.5,分配引脚,并编译后,把生成*.sof文件下载到基于Cyclone型GW48系列FPGA实验箱开发板上,成功查看结果,CLK时钟频率用1Hz,可通过实验箱上“键7”控制Reset全局复位。 五、实验困难问题及解决措施 在实验的过程中,编写主程序的时候,也遇到调试不成功的问题,主要问题如下:①在编写xianshi模块时,最后给输出信号赋值时,使用了进程语句,但是由于敏感列表不全,导致在仿真时其输出信号的值产生错误。解决措施就是通过逐个查看内部信号,由于敏感列表不全,致使有些时刻,最后赋值的进程语句没有启动,从而造成输出结果不全。②在实现绿灯剩余时间小于三秒时开始闪烁功能时,遇到问题。具体表现在yima模块中。开始为了在绿灯状态,使绿灯在高、地电平间变换,所以就尝试使用时钟信号clk的上升沿和下降沿,其中上升沿时,绿灯高电平即亮,下降沿时绿灯熄灭。虽然这种方案在modelsim中仿真成功,但是在quartus进行综合出现错误,该综合软件综合不出此寄存器。经过多次试验,使用了clk高低电平触发,不再使用其上升下降沿。③在整个程序中有时在使用IF语句时,会因为考虑不完整造成实验结果出错。因为在IF语句中如果过没有ELSE语句,那么输出将默认保持前一个状态,这样很容易产生错误。 总之经过查阅各种资料,成功的把程序调试了出来。在查阅试验箱说明书的情况下,完成了引脚的选定,并把程序下载到了试验箱里面,完成了实物的演示。 参考文献 [1]邹彦编.EDA技术与数字系统设计.北京:电子工业出版社.2007. [2]潘松,黄继业编.EDA技术与VHDL(第二版).北京:清华大学出版社.2007. [3]王锁萍编.电子设计自动化教程.成都:电子科技大学出版社.2000. [4]徐志军,徐光辉编.CPLD/FPGA的开发与应用.北京:电子工业出版社.2002 . [5]杨旭,刘盾等编.EDA技术基础与实验教程.北京:清华大学出版社.2010. 七、附录 附录一: 本系统采用用硬件描述语言VHDL描述。分为五个模块,分别为控制模块、计时模块、显示模块、译码模块和分频模块,下面针对每个模块给出相应的程序: 模块一: /*************************控制部分**********************/ /***********定义输入输出端口***********/ library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity kongzhi is --实体部分; port ( clk,clr : in std_logic; at,bt : in std_logic_vector(7 downto 0); s : out std_logic_vector(2 downto 0) ); end kongzhi; architecture rtl of kongzhi is --结构体部分; signal q :std_logic_vector(2 downto 0); begin -- main logic process (clk,clr,at,bt) begin if clr='1' then q<="011"; --系统复位后,系统的状态是A干道绿灯; B干道红灯; elsif (clk'event and clk ='1') then if (at=x"01") or (bt=x"01") then --倒计时结束时,状态发生改变; q<=q+1; else q<=q; end if; end if; end process; s <= q; end rtl; 模块二: /*************************计时部分**********************/ /***********为A,B方向设置初值 ***********/ library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity jishi is --实体部分 port ( clk, clr : in std_logic; s :in std_logic_vector(2 downto 0); at,bt :out std_logic_vector(7 downto 0) ); end jishi; architecture rtl of jishi is --结构体 signal ati,bti :std_logic_vector(7 downto 0);--中间信号 signal art,agt,alt,abyt:std_logic_vector(7 downto 0); signal brt,bgt,blt:std_logic_vector(7 downto 0); begin -- main logic --每个状态的总时间分别赋给相应的信号; art<=x"33"; --A方向直行红灯总时间为33s; agt<=x"20"; --A方向直行绿灯总时间为20s; alt<=x"10"; --A方向左拐绿灯总时间为4s; abyt<=x"04"; --黄灯总时间为4s; brt<=x"38"; --B方向直行红灯总时间为38s; bgt<=x"15"; --B方向直行绿灯总时间为15s; blt<=x"04"; --B方向左拐绿灯总时间为4s; process (clk,clr,s) begin if clr='1' then ati<=x"33";bti<=x"24"; --系统复位后A方向直行绿灯剩余时间为33s,B方向直行红灯剩余时间为24s; elsif (clk'event and clk ='1') then if(ati=x"01") or (bti=x"01") then case s is --在每个状态,赋给相应初始时间; when "000"=>ati<=alt;bti<=brt; when "001"=>ati<=abyt; when "010"=>ati<=agt; when "011"=>ati<=abyt; when "100"=>ati<=art;bti<=blt; when "101"=>bti<=abyt; when "110"=>bti<=bgt; when "111"=>bti<=abyt; when others=>ati<=ati;bti<=bti; end case; end if; if ati/=x"01" then --当前时间大于1s时,则相应位进行减一; if ati(3 downto 0)="0000" then ati(3 downto 0)<="1001";--因为总时间使用的是十六进制 ati(7 downto 4)<=ati(7 downto 4)-1; else ati(3 downto 0)<=ati(3 downto 0)-1; ati(7 downto 4)<=ati(7 downto 4); end if; end if; if bti/=x"01" then --当前时间大于1s时,则相应位进行减一; if bti(3 downto 0)="0000" then bti(3 downto 0)<="1001"; bti(7 downto 4)<=bti(7 downto 4)-1; else bti(3 downto 0)<=bti(3 downto 0)-1; bti(7 downto 4)<=bti(7 downto 4); end if; end if; end if; end process; at<= ati; --最后给输出信号赋值; bt<=bti; end rtl; 模块三: /*************************显示部分**********************/ /***********显示倒计时时间和系统工作状态 ***********/ library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity xianshi is --实体部分; port ( clk1k,clr ,clk : in std_logic; at,bt:in std_logic_vector(7 downto 0); led : out std_logic_vector(6 downto 0); sel: out std_logic_vector(3 downto 0) ); end xianshi; architecture rtl of xianshi is --结构体部分; signal ou : std_logic_vector(3 downto 0) ; signal dis,ds : std_logic_vector(7 downto 0); signal sl : std_logic_vector(2 downto 0):="000"; signal sq : std_logic_vector(3 downto 0):="0000"; begin -- main logic sl1:process (clk1k,clr) begin if clr='1' then sl<="000"; elsif (clk1k'event and clk1k ='1')then if sl="011" then sl <="000"; else sl <=sl+1; end if; end if; end process; sq1: process(sl) --产生位选信号 begin case sl is when "000"=>sq<="0001"; when "001"=>sq<="0010"; when "010"=>sq<="0100"; when "011"=>sq<="1000"; when others=>null; end case; end process; ou1:process(sl) --显示时间与位选信号一一对应; begin case sl is when "000"=>ou<=bt(3 downto 0); -- when "001"=>ou<=bt(7 downto 4); when "010"=>ou<=at(3 downto 0); when "011"=>ou<=at(7 downto 4); when others =>ou<=x"0"; end case; end process; ds1:process(ou) begin --将显示时间转换成数码管显示; case ou is when x"0"=>ds<=x"3F"; when x"1"=>ds<=x"06"; when x"2"=>ds<=x"5b"; when x"3"=>ds<=x"4f"; when x"4"=>ds<=x"66"; when x"5"=>ds<=x"6d"; when x"6"=>ds<=x"7d"; when x"7"=>ds<=x"07"; when x"8"=>ds<=x"7f"; when x"9"=>ds<=x"6F"; when others =>ds<=x"00"; end case; end process; saomiao:process(clk,ds,clr,sl) –-给输出信号赋值; begin if clr='1' then dis<=ds; elsif sl<"101" then if clk='0' then dis<=ds;--低电平数码管显示时间; else dis<=x"00"; --高电平数码管全关闭; end if; else dis<=ds; end if; end process; led<=dis(6 downto 0); sel <=sq; end rtl; 模块四: /*************************译码部分**********************/ /***********驱动交通灯的显示***********/ library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity yima is --实体部分; port ( clr,clk : in std_logic; at,bt : in std_logic_vector(7 downto 0); s : in std_logic_vector(2 downto 0); abl :out std_logic_vector(7 downto 0) ); end yima; architecture rtl of yima is --结构体部分; signal lt :std_logic_vector(7 downto 0); signal a :std_logic_vector(7 downto 0); signal b :std_logic_vector(7 downto 0); begin -- main logic process (clr,s,clk) --状态S控制着每个方向的LED灯; begin if clr='1' then lt<="00100001"; end if; case s is when "000" =>lt<="00010100"; when "001" =>lt<="10000001"; when "010" =>lt<="01000001"; when "011" =>lt<=a; when "100" =>lt<="01000001"; when "101" =>lt<="00011000"; when "110" =>lt<="00010100"; when "111" =>lt<=b; when others=>lt<=lt; end case; end process; process(clk,at,bt,s) –绿灯时间小于4秒时,绿灯开始闪烁; begin if(s="011") then if at<x"04" then if clk='1' then a<="00000001"; elsif clk='0' then a<="00100001"; end if; else a<="00100001"; end if; else a<="00100001"; end if; if (s="111") then if bt<x"04" then if clk = '1' then b<="00010000"; elsif clk='0' then b<="00010010"; end if; else b<="00010010"; end if; else b<="00010010"; end if; end process; abl <= lt; end rtl; 模块五: /*************************分频部分**********************/ /***********为系统提供所需要的时钟脉冲 ***********/ library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity fenpin is --实体部分; port ( clk1k : in std_logic; clk : out std_logic ); end fenpin; architecture rtl of fenpin is --结构体部分; signal fp :std_logic_vector(9 downto 0):="0000000000"; begin -- main logic process (clk1k) begin if (clk1k'event and clk1k ='1') then fp <= fp+1; --计数 end if; end process; clk <= fp(9); --29个clk1k周期产生半个周期的clk信号; end rtl; 顶层文件模块程序: library ieee; use ieee.std_logic_1164.all; entity jiaotongdeng is --实体部分; port ( clk1k, clr : in std_logic; shuma : out std_logic_vector(6 downto 0); sel : out std_logic_vector(3 downto 0); led1 : out std_logic_vector(7 downto 0) ); end jiaotongdeng; architecture rtl of jiaotongdeng is --结构体部分; component fenpin is --调用fenpin模块声明; port ( clk1k : in std_logic; clk : out std_logic ); end component; component jishi is --调用jishi模块声明; port ( clk, clr : in std_logic; s : in std_logic_vector(2 downto 0); at,bt :out std_logic_vector(7 downto 0) ); end component; component kongzhi is --调用kongzhi模块声明; port ( clk,clr : in std_logic; at,bt : in std_logic_vector(7 downto 0); s : out std_logic_vector(2 downto 0) ); end component; component xianshi is –调用xianshi模块声明; port ( clk1k,clk, clr : in std_logic; at,bt : in std_logic_vector(7 downto 0); led : out std_logic_vector(6 downto 0); sel : out std_logic_vector(3 downto 0) ); end component; component yima is --调用yima模块声明; port ( clr,clk : in std_logic; at,bt : in std_logic_vector(7 downto 0); s : in std_logic_vector(2 downto 0); abl : out std_logic_vector(7 downto 0) ); end component; signal s1,s2,s3 ,s14,s15,s16: std_logic ;--定义中间信号; signal s8,s7 :std_logic_vector(2 downto 0); signal s5,s6,s9,s10,s11 :std_logic_vector(7 downto 0); signal s12 :std_logic_vector(6 downto 0); signal s13 :std_logic_vector(3 downto 0); begin u1: fenpin port map(clk1k=>s1,clk=>s2);--元件端口映射; u2: kongzhi port map(clk=>s2,clr=>s3,at=>s9,bt=>s10,s=>s7); u3: jishi port map(clk=>s2,clr=>s3,s=>s7,at=>s9,bt=>s10); u4: yima port map(clr=> s3,s=>s7,abl=>s11,at=>s9,bt=>s10,clk=>s2); u5: xianshi port map (clk=>s2,clk1k=>s1,clr=>s3,at=>s9,bt=>s10,led=>s12,sel=>s13); s1<=clk1k; s3<=clr; shuma<=s12; sel<=s13; led1<=s11; end rtl; 附录二: /*************************测试平台程序**********************/ library ieee; use ieee.std_logic_1164.all; entity test is end test; architecture behaviour of test is signal sig_clk1k : std_logic := '0'; signal sig_clr : std_logic := '1'; signal sig_shuma : std_logic_vector(6 downto 0); signal sig_sel :std_logic_vector(3 downto 0); signal sig_led1 :std_logic_vector(7 downto 0); constant period : time :=0.5 ms; constant period1 : time :=0.25 ms; component jiaotongdeng is --调用jiaotongdeng模块; port ( clk1k, clr : in std_logic; shuma : out std_logic_vector(6 downto 0); sel : out std_logic_vector(3 downto 0); led1 :out std_logic_vector(7 downto 0) ); end component; begin -- instance u_jiaotongdeng : jiaotongdeng port map ( --端口映射; clk1k => sig_clk1k, clr => sig_clr, led1 =>sig_led1, shuma => sig_shuma, sel =>sig_sel ); process begin sig_clk1k <='0';wait for period; sig_clk1k <='1'; wait for period; end process; sig_clr <= '1', '0' after 3 sec, '1' after 10 sec,'0' after 11 sec; end behaviour; 附
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服