基于VHDL的交通灯设计与实现
- 格式:doc
- 大小:498.54 KB
- 文档页数:22
EDA课程设计实验报告交通信号控制器的VHDL的设计一、设计任务及要求:设计任务:模拟十字路口交通信号灯的工作过程,利用实验板上的两组红、黄、绿LED作为交通信号灯,设计一个交通信号灯控制器。
要求:(1)交通灯从绿变红时,有4秒黄灯亮的间隔时间;(2)交通灯红变绿是直接进行的,没有间隔时间;(3)主干道上的绿灯时间为40秒,支干道的绿灯时间为20秒;(4)在任意时间,显示每个状态到该状态结束所需的时间。
支干道主干道图1 路口交通管理示意图表1 交通信号灯的4种状态设计要求:(1)采用VHDL语言编写程序,并在QUARTUSII工具平台中进行仿真,下载到EDA实验箱进行验证。
(2)编写设计报告,要求包括方案选择、程序清单、调试过程、测试结果及心得体会。
二设计原理1、设计目的:学习DEA开发软件和QuartusII的使用方法,熟悉可编程逻辑器件的使用。
通过制作来了解交通灯控制系统,交通灯控制系统主要是实现城市十字交叉路口红绿灯的控制2’设计说明(1)第一模块:clk时钟秒脉冲发生电路在红绿灯交通信号系统中,大多数情况是通过自动控制的方式指挥交通的。
因此为了避免意外事件的发生,电路必须给一个稳定的时钟(clock)才能让系统正常运作。
模块说明:系统输入信号:Clk: 由外接信号发生器提供256的时钟信号;系统输出信号:full:产生每秒一个脉冲的信号;(2)第二模块:计数秒数选择电路计数电路最主要的功能就是记数负责显示倒数的计数值,对下一个模块提供状态转换信号。
模块说明:系统输入:full: 接收由clk电路的提供的1hz的时钟脉冲信号;系统输出信号:tm:产生显示电路状态转换信号tl:倒计数值秒数个位变化控制信号th:倒计数值秒数十位变化控制信号(3)第三模块:红绿灯状态转换电路本电路负责红绿灯的转换。
模块说明:系统输入信号:full: 接收由clk电路的提供的1hz的时钟脉冲信号;tm: 接收计数秒数选择电路状态转换信号;系统输出信号:comb_out: 负责红绿灯的状态显示。
基于VHDL 的交通灯控制器设计翟殿棠,方 敏,厉光伟(济南大学控制科学与工程学院 山东济南 250022)摘 要:传统的交通灯控制器多数由单片机或PLC 实现,本文介绍基于EDA 技术设计交通灯控制器的一种方案。
EDA 技术的一个重要特征就是使用硬件描述语言(HDL)来完成系统的设计文件,这在电子设计领域已得到设计者的广泛采用。
给出了交通灯控制器的VH DL 源程序和仿真结果。
仿真结果表明该系统的设计方案正确。
展示了VH DL 语言的强大功能和优秀特性。
关键词:交通灯控制器;电子设计自动化;硬件描述语言;可编程器件中图分类号:T N702 文献标识码:B 文章编号:1004373X(2007)0318702Design of Traffic Light Controller Based on VHDLZH AI Diantang,FANG Min,LI Guangwei(School of Cont rol Sci ence and Engineering,Ji nan Universi t y,Ji c nan,250022,China)A bstra ct :Tr affic light controller is usually developed by micr oprocessor or PLC.This paper introduces the design of t raffic light controller base on EDA,one im portant character istic of the EDA is that the design documents should be complet ed by the HDL,and it is widely used by electr onic designer now.The VH DL source progr ammer and simulating r esults of traffic light cont roller are given.T he simulating r esults show that the design met hod is corr ect,it shows the powerful function and excel 2lent char acter of the VHDL.Keywords :traff ic light controller;EDA;HDL;PLD收稿日期:20060706应用VH DL 语言设计数字系统,大部分设计工作可在计算机上完成,从而缩短系统开发时间,提高工作效率。
生物医学工程王春雨基于VHDL的交通灯控制器设计应用VHDL语言设计数字系统,大部分设计工作可在计算机上完成,从而缩短系统开发时间,提高工作效率。
下面介绍基于VHDL设计交通灯控制器的一种方案,并给出源程序和仿真结果。
1 系统功能与要求实现交通繁忙的主路和偶有车行的小路交会路口的交通管理。
要求:1、交通灯控制器控制主干道和小路交叉路口的交通。
2、小路口来车,主线路口绿灯切换到黄灯5秒钟后变为红灯。
3、红灯燃亮20秒后,自动切换为绿灯。
4、指示左转弯的绿灯亮12 s,绿灯变至红灯时,黄灯亮3 s。
5、主路的交通管制重新切换到绿灯后5分钟内不理睬小路上的车况,即使又有车辆驶入小路路口。
上述主路上的灯光显示,小路口的灯信号与之逻辑配合。
2 程序设计根据交通灯控制器的功能与要求,将其总体电路分为分频器、信号控制器两个模块。
外部脉冲振荡器的频率选为32768 kHz,经分频器分频得1 Hz的信号,1 Hz信号用做信号控制器的计数脉冲,用VHDL设计组成交通灯控制器的分频器、信号控制器两个模块,在M AX+plus Ⅱ平台上,编译VHDL程序,然后用原理图输入法形成总体框图。
实验程序:Library IEEE;Use IEEE.Std_Logic_1164.All;Use IEEE.STd_Logic_Unsigned.All;Entity Frequency10Hz IsPort(Clk20M: In Std_Logic;Clk10Hz:Out Std_Logic);End;Architecture Count Of Frequency10Hz Is Signal Tout:Integer Range 0 to ;Signal Clk:Std_Logic;BeginProcess(Clk20M)BeginIf rising_edge(Clk20M) thenIf Tout= thenTout<=0;Clk<=Not Clk;Else Tout<=Tout+1;End If;End If;End Process;Clk10Hz<=Clk;End;Library IEEE;Use IEEE.Std_Logic_1164.All;Use IEEE.STd_Logic_Unsigned.All; Entity Frequency IsPort(Clk10Hz: In Std_Logic;Clk1Hz:Out Std_Logic);End;Architecture Count Of Frequency Is Signal Tout:Integer Range 0 to 4;Signal Clk:Std_Logic;BeginProcess(Clk10Hz)BeginIf rising_edge(Clk10Hz) thenIf Tout=4 thenTout<=0;Clk<=Not Clk;Else Tout<=Tout+1;End If;End If;End Process;Clk1Hz<=Clk;End;Library IEEE;Use IEEE.Std_Logic_1164.All;Use IEEE.Std_Logic_Unsigned.All;Entity Controller IsPort(Clock:In Std_Logic;Hold:In Std_Logic;CountNum:IN Integer RANgE 0 TO 49;Flash:Out Std_Logic;NumA,NumB:Out Integer Range 0 To 25;RedA,GreenA,YellowA:Out Std_Logic;RedB,GreenB,YellowB:Out Std_Logic);End;ARCHITECTURE Behavior OF Controller IS BEGINPROCESS(CLOCK)BeginIf falling_edge(Clock) thenIf Hold='1' thenRedA<='1';RedB<='1';GreenA<='0';GreenB<='0';YellowA<='0';YellowB<='0';Flash<='1';ElseFlash<='0';If CountNum<=19 thenNumA<=20-CountNum;RedA<='0';GreenA<='1';YellowA<='0';Elsif (CountNum<=24) thenNumA<=25-CountNum;RedA<='0';GreenA<='0';YellowA<='1';ElseNumA<=50-CountNum;RedA<='1';GreenA<='0';YellowA<='0';End If;If CountNum<=24 thenNumB<=25-CountNum;RedB<='1';GreenB<='0';YellowB<='0';Elsif CountNum<=44 thenNumB<=45-CountNum;RedB<='0';GreenB<='1';YellowB<='0';ElseNumB<=50-CountNum;RedB<='0';GreenB<='0';YellowB<='1';End If;End If;End If;End Process;End;LIBRARY IEEE;USE IEEE.Std_logic_1164.all;Use IEEE.Std_Logic_Unsigned.All; ENTITY Counter ISPORT(Clock:IN Std_logic;Reset:IN Std_logic;Hold:IN Std_logic;CountNum:BUFFER Integer RANGE 0 TO 49 );END;ARCHITECTURE Behavior OF Counter IS BEGINPROCESS(Reset,Clock)BEGINIF Reset='1'THENCountNum<=0;ELSIF rising_edge(Clock) THENIF Hold='1'THENCountNum<=CountNum;ELSEIF CountNum=49 THENCountNum<=0;ELSECountNum<=CountNum+1;END IF;END IF;END IF;END PROCESS;END Behavior;Library IEEE;Use IEEE.Std_Logic_1164.All;Use IEEE.Std_Logic_Unsigned.All;Entity Display IsPort( Clock:In Std_Logic;Flash:In Std_Logic;Qin:In Std_Logic_Vector(3 Downto 0); Display:Out Std_Logic_Vector(0 to 6)); End;Architecture Light Of Display IsSignal Timeout:Integer Range 0 To 11;BeginProcess(Clock)BeginIf rising_edge(Clock) thenIf (Flash='0') thenTimeout<=0;ElseIf (Timeout=11) thenTimeout<=0;ElseTimeout<=Timeout+1;End If;End If;If (Timeout<=6) thenCase Qin IsWhen "0000"=>Display<="";When "0001"=>Display<="";When "0010"=>Display<="";When "0011"=>Display<="";When "0100"=>Display<="";When "0101"=>Display<="";When "0110"=>Display<="";When "0111"=>Display<="";When "1000"=>Display<="";When "1001"=>Display<="";When Others=>Display<="";End Case;ElseDisplay<="";End If;End If;End Process;End;Library IEEE;Use IEEE.Std_Logic_1164.All;Use IEEE.Std_Logic_Unsigned.All; Entity Fenwei IsPort(Numin:In Integer Range 0 To 25;NumA,NumB:Out Integer Range 0 To 9 );End;Architecture Fen Of Fenwei IsBeginProcess(Numin)BeginIf Numin>=20 thenNumA<=2;NumB<=Numin-20;Elsif Numin>=10 thenNumA<=1;NumB<=Numin-10;ElseNumA<=0;NumB<=Numin;End If;End Process;End;顶层框图:3.仿真结果。
本科毕业论文(设计)( 2013届)题目:基于VHDL的交通灯控制器设计与仿真学院:机电与信息工程学院专业:电子信息工程学生姓名:杨洋学号:20906022071 指导教师:官鸣俊职称(学位):副教授合作导师:职称(学位):完成时间:2013 年 5 月22 日成绩:黄山学院教务处制学位论文原创性声明兹呈交的学位论文,是本人在指导老师指导下独立完成的研究成果。
本人在论文写作中参考的其他个人或集体的研究成果,均在文中以明确方式标明。
本人依法享有和承担由此论文而产生的权利和责任。
声明人(签名):年月目录摘要 ..................................................................................................... 错误!未定义书签。
英文摘要 ............................................................................................. 错误!未定义书签。
1 引言 (3)2 EDA设计技术综述 (3)2.1 EDA技术 (3)2.1.1 EDA简介 (3)2.1.2 EDA设计流程 (4)2.1.3 EDA技术优势 (4)2.2 Max+plusII设计平台 (5)2.2.1 Max+plusII简介 (5)2.2.2 Max+plusII设计流程 (5)2.3 VHDL硬件描述语言 (5)2.3.1 VHDL简介 (5)2.3.2 VHDL硬件描述语言的主要优点 (5)2.3.3 VHDL设计流程 (6)3 交通灯控制器功能描述与组成结构 (6)3.1 交通灯控制器功能描述 (6)3.2 交通灯控制器组成结构 (7)4 交通灯控制器的VHDL设计 (7)4.1 交通灯控制器主要模块设计与仿真 (7)4.1.1 分频器设计与仿真 (7)4.1.2 状态机设计与仿真 (10)4.2 交通灯控制器顶层文件设计与仿真 (12)5 结束语 (15)参考文献 (16)致谢 (17)附录:交通灯控制器各模块VHDL程序描述和顶层文件VHDL程序描述 (18)基于VHDL的交通灯控制器设计与仿真机电与信息工程学院电子信息工程杨洋(20906022071)指导老师:官鸣俊(副教授)摘要:与传统的电子系统设计方案相比较,传统的交通灯控制系统都是基于单片机或者PLC 的设计方案来实现,而对于复杂电路的设计运用EDA技术则会使之变得比较简单。
华中科技大学基于xilinx FPGA的VHDL交通灯控制器的设计--基于Spartan3E开发板专业:电子信息工程一. 任务设计要求①设计一个十字路口交通信号灯的定时控制电路。
要求红、绿灯按一定的规律亮和灭,并在亮灯期间进行倒计时,并将运行时间用数码管/液晶显示出来。
②绿灯亮时,为该车道允许通行信号,红灯亮时,为该车道禁止通行信号。
要求主干道每次通行时间为99秒,支干道每次通行时间为30秒。
每次变换运行车道前绿灯闪烁,持续时间为5秒。
即车道要由主干道转换为支干道时,主干道在通行时间只剩下5秒钟时,绿灯闪烁显示,支干道仍为红灯,以便主干道上已过停车线的车继续通行,未过停车线的车停止通行。
同理,当车道由支干道转换为主干道时,支干道绿灯闪烁显示5秒钟,主干道仍为红灯。
③对红、绿灯的运行时间要能比较方便的进行重新设置。
④对器件进行在系统编程和实验验证。
⑤用VHDL语言对设计进行描述,设计一个测试方案,通过ISE对设计进行仿真验证。
并能够下载到实验板上调试成功。
任务扩展:在原设计的基础上加入指示方向的功能。
二. 系统设计1.系统原理图与说明由系统设计原理图,我以清楚地将系统分为六个模块:分频模块,时间设置模块,状态转换模块,时间计算模块,LED流水灯模块,LCD显示模块。
1)分频模块分频模块其作用为:由于Spartan3E板上提供的时钟信号为50MHz,而设计所需时钟信号为1Hz,故使用分频模块将50MHz信号分频为1Hz信号。
2)时间置数模块由于任务设计要求可以对主干道,支干道上左转、绿灯运行的时间进行重新设置调整,所以要对系统进行参数化设计。
首先引入一组参数,main_gh,main_gl,main_lh,main_ll,branch_gh,branch_gl,branch_lh,branch_ll(下划线后面的字母分别取green,left,high,low首字母).需要置数时,首先选择对主干道还是支干道时间置数,这里设置一个main_or_branch参数,当main_or_branch为高时设置支干道时间,为低时设置主干道时间。
基于VHDL语言的交通灯控制器设计2009年06 月18 日星期四20:38设计要求1、显示一个方向的绿、黄、红的指示状态。
2、特殊情况按键能实现特殊的功能,计数器停止计数并保持在原来的状态,显示红灯状态。
特殊后能继续计数.3、复位按键实现总体计数清零功能。
4、实现正常的倒计时功能. 用数码管作为倒计时显示, 显示时间为绿灯17s, 黄灯3s 红灯20s。
| ---------- >|--->| ------------ >|| 绿灯| 黄灯| 红灯|设计思想首先由晶振产生出发信号,由控制器处理成1HZ的时钟,利用此时钟进行计数,通过判断控制交通灯的亮灭。
通过每种灯亮的时间总数与计数值比较得到数码管应该显示的数值,利用分位分成十位和个位。
通过译码电路来实现数码管的显示。
本实验所使用的芯片为EPM7128SLS84-,6 实体逻辑单元为64 点,结构体逻辑单元为128 小型芯片。
软件本实验使用MAX+plus II 10 来进行程序的编写,编译,仿真以及下载。
在实验中发现其用,但仍有地方需要改进,不支持MOD取余运算。
(源程序)* 在MAX+plus II 中,汉字很容易出现乱码,建议大家用英文,这里为了考虑到读者的习惯写论文时都译成中文Library IEEE;Use IEEE.std_logic_1164.all;Entity redgreen isPort(clock_in:in std_logichold_state:instd_logic;reset_state:instd_logic,led_green ,led_yellow:out std_logic;led_redselect_en:buffer std_logic; select_display:out std_logic_vector(0 to 6)); end;Architecture half of redgreen isconstant loop_hz:integer:=800000; -- 一根据晶振实际频率算出来signal count_time:integer range 0 to loop_hz;signal clock_buffer:std_logic;signal clock_out:std_logic;signal count_num:integer range 0 to 40;signal display_num:integer range 0 to 20;signal display_shi:integer range 0 to 9;signal display_ge:integer range 0 to 9;constant loop_time:integer:=40; 个循环周期的时间constant red_time:integer:=20; -- 红灯的时间constant green_time:integer:=17; -- 绿灯的时间constant yellow_time:integer:=3; -- 黄灯的时间beginprocess(clock_in) -- 分频进程beginif rising_edge(clock_in) thenif count_time=loop_hz then count_time<=0; clock_buffer<=notclock_buffer;else count_time<=count_time+1;end if;end if; clock_out<=clock_buffer;-- 输入1HZ 的频率end process;process(reset_state ,clock_out) -- 计数进程beginif reset_state=1 then -- 重启后计数归零count_num<=0;elsif rising_edge(clock_out) thenif hold_state=1 then -- 紧急时计数占停count_num<=count_num;elseif count_num=loop_time-1 then count_num<=0;else count_num<=count_num+1;end if;end if;end if;end process;process(clock_out) -- 交通灯显示count countbeginnumnumif falling_edge(clock_in) thenif hold_state=1 then --led_red<=1;led_green<=0;led_yellow<=0;elseifelsifelseendif;占停时红灯亮display_num<=green_time-count_num;led_red<=0;led_green<=1;led_yellow<=0;display_num<=green_time+yellow_time-led_red<=0;led_green<=0;led_yellow<=1;display_num<=loop_time-count_num;led_red<=1;led_green<=0;led_yellow<=0;endif; end if;end process;process(display_num) -- 分位进程beginif display_num>=20 then display_shi<=2;display_ge<=display_num-20;elsif display_num>=10 thendisplay_shi<=1;display_ge<=display_num-10;elsedisplay_shi<=0;display_ge<=display_num;end if;end process;process(clock_in) -- 数码管显示beginif falling_edge(clock_in) thenselect_en<=1; -- 因为我们的实验箱采用数码管并联方式,所以显示case display_shi iswhen 0=>select_display<=1111110; when1=>select_display<=0110000; when 2=>select_display<=1101101; whenothers=>select_display<=0000000; end case;if select_en=1 then select_en<=0; case display_ge is when0=>select_display<=1111110; when 1=>select_display<=0110000; when2=>select_display<=1101101; when 3=>select_display<=1111001; when4=>select_display<=0110011; when 5=>select_display<=1011011; when6=>select_display<=1011111; when 7=>select_display<=1110000; when8=>select_display<=1111111; when 9=>select_display<=1110011; whenothers=>select_display<=0000000; end case;end if;end if;end process;end;-- 由于时间和硬件限制,这个程序仅仅实现了一路交通灯,用类似的方法可以写出两路交通灯的程library ieee;use ieee.std_logic_1164.all;entity redgreen isPort( clock_in:in std_logic; hold_state:in std_logic;reset_state:in std_logic;led_red,led_green,led_yellow:out std_logic; select_en:buffer std_logic; select_display:out std_logic_vector(0 to 6));end;architecture half of redgreen isbeginsignal count_time:integer range 0 to 800000;signal clock_buffer:std_logic;signal clock_out:std_logic;signal count_num:integer range 0 to 40;signal display_num:integer range 0 to 20; signal display_shi:integer range 0 to 9; signal display_ge:integer range 0 to 9; constantloop_time:integer:=50;constant red_time:integer:=25;constant green_time:integer:=20; constant yellow_time:integer:=5;begin process(clock_in)beginif rising_edge(clock_in)count_time<=0;clock_buffer<=not clock_buffer;count_time<=count_time+1;end if;end if;clock_out<=clock_buffer;end process;process(reset_state,clock_out)beginif reset_state=1then count_num<=0;elsif rising_edge(clock_out)then if hold_state=1then count_num<=count_num;else if count_num=loop_time-1then count_num<=0;else count_num<=count_num+1;end if;end if;thenif count_time=loop_hz then elseend if;end process;process(clock_out)beginif falling_edge(clock_in)then if hold_state=1thenled_red<=1;led_green<=0; led_yellow<=0;elseif count_numdisplay_num<=green_time-count_num;led_red<=0;led_green<=1;led_yellow<=0;elsif count_numdisplay_num<=green_time+yellow_time-count_num; led_red<=0;led_green<=0;led_yellow<=1;elsedisplay_num<=loop_time-count_num;led_red<=1;led_green<=0;led_yellow<=0;end if;end if;end if;end process;process(display_num)beginif display_num>=20then display_shi<=2;display_ge<=display_num-20;elsif display_num>=10then display_shi<=1;display_ge<=display_num-10;else display_shi<=0;display_ge<=display_num;end if;end process;process(clock_in)beginif falling_edge(clock_in)then select_en<=1;case display_shi iswhen 0=>select_display<=1111110;when 1=>select_display<=0110000;when 2=>select_display<=1101101;when others=>select_display<=0000000; end case;if select_en=1then select_en<=0;case display_ge iswhen 0=>select_display<=1111110;when 1=>select_display<=0110000;when 2=>select_display<=1101101;when 3=>select_display<=1111001;when 4=>select_display<=0110011;when 5=>select_display<=1011011;when 6=>select_display<=1011111;when 7=>select_display<=1110000;when 8=>select_display<=1111111;when 9=>select_display<=1110011;when others=>select_display<=0000000;end case; end if; end if;end process; end;end half;。
基于vhdl交通灯课程设计一、课程目标知识目标:1. 学生能理解并掌握VHDL语言的基本结构及其在交通灯控制系统中的应用;2. 学生能运用VHDL语言编写交通灯控制程序,实现对交通灯红、黄、绿灯亮灭时间的控制;3. 学生了解交通灯控制系统的工作原理,理解数字电路在实际应用中的重要性。
技能目标:1. 学生能够独立进行VHDL代码的编写,具备初步的编程能力;2. 学生通过课程设计实践,培养解决实际问题的能力,提高动手操作能力;3. 学生能够运用所学知识对交通灯控制系统进行调试和优化。
情感态度价值观目标:1. 学生在课程学习中,培养对电子信息技术专业的兴趣,激发学习热情;2. 学生通过团队合作完成课程设计,提高沟通与协作能力,增强团队意识;3. 学生认识到电子技术在现实生活中的应用,增强社会责任感和创新意识。
课程性质:本课程为电子信息技术专业高年级的专业课程设计,旨在通过实际操作,让学生将所学理论知识运用到实际项目中。
学生特点:学生已经掌握了VHDL语言的基本知识,具有一定的编程基础,对实际项目具有一定的兴趣和热情。
教学要求:结合学生特点和课程性质,注重实践操作,提高学生的动手能力和解决实际问题的能力。
在教学过程中,注重启发式教学,引导学生主动探索,培养学生的创新意识。
同时,关注学生的情感态度价值观培养,提高学生的综合素质。
通过分解课程目标,为后续教学设计和评估提供依据。
二、教学内容1. 交通灯控制系统原理介绍:讲解交通灯控制系统的工作原理,分析各个模块的功能及相互关系,使学生对交通灯控制系统有整体的认识。
相关教材章节:第三章 数字电路设计基础,第四节 交通灯控制系统原理。
2. VHDL语言基础回顾:回顾VHDL语言的基本结构、语法和常用语句,为后续编程打下基础。
相关教材章节:第二章 VHDL语言基础,全章。
3. 交通灯控制程序设计:详细讲解如何使用VHDL语言编写交通灯控制程序,包括红、黄、绿灯亮灭时间的设置。
基于VHDL语言的交通灯控制器设计与实现摘要 VHDL是Very High Speed Integrated Circuit Hardware Description Language 的缩写,意思是超高速集成电路硬件描述语言。
对于复杂的数字系统的设计,它有独特的作用。
它的硬件描述能力强,能轻易的描述出硬件的结构和功能。
这种语言的应用至少意味着两种重大的改变:电路的设计可以通过文字描述的方式完成;电子电路可以当作文件一样来存储。
随着现代技术的发展,这种语言的效益与作用日益明显,每年均能够以超过30%的速度快速成长。
交通灯控制系统通常要实现自动控制红绿灯的变化,基于FPGA设计的交通灯控制系统电路简单、可靠性好。
本系统可控制2个路口的红、黄、绿三盏交通灯。
对于Max+PlusⅡ开发工具,它是美国Altera公司自行设计的一种CAE软件工具。
他具有全面的逻辑设计能力,设计者可以自由组合文本、图形和波形输入法,建立起层次化的单器件或多器件设计。
利用该工具配备的编辑、编译、仿真、综合、芯片编程等功能,将设计的电路图或电路描述程序变成基本的逻辑单元写入到可编程芯片中(如CPLD、FPGA),做成ASIC芯片。
仿真实验结果表明了该编解码器的正确性和合理性。
关键词:交通灯;控制器;VHDL;MAX+PlusⅡAbstract VHDL is the Very Hight Speed Integrated Circuit Hardware Description Language acronym,meaning that high-speed integrated circuit hardware description language.For complex digital system design,it has a unique role.Its hardware descirption ability,can easily describe the structure and funtion of the hardware.The application of this language implies that at least two kinds of major changes:the design of the circuit can actually be completed by the manner described in the text;electronic circuits can be used as to store the same files.With modern technology,the benefits and role of this language has become more obvious every year to more than 30% of the rate of rapid growth.Traffic light control system is usually to achieve the automatic trafffic light changes,FPGA-based design of a traffic light control system circuit is simplem,and good reliability.The system can control two junctions of red,yellow,green,three traffic lights.For theMax-Plus II development tool,it is United States Altera’s own design of a CAE software tools.It has a comprehensive logic design capabilities,designers can freely mix text,graphics,and waveform input method,set up hierarchical design of a single device or multiple devices.The use of the tool is equipped with the editing,compiling,simulation,synthesis,chip programming features such as the design of the circuit or circuit described procedure into the basic logic unit is written into the programmable chip(eg,CPLD,FPGA),made of ASIC chips.The simulation results show that the correct codec and rationality.Keywords:traffic light;controller,VHDL,MAX+PlusII目录1 引言 (1)2 课题背景及相关技术 (2)2.1 Max+plusII简介 (2)2.2 VHDL语言简介 (3)2.3 VHDL设计的优点与设计方法 (5)3交通灯控制器分析 (7)3.1 分频器 (7)3.2 状态机 (8)4交通灯控制器的VHDL设计 (9)4.1程序流程图 (9)4.2交通灯顶层文件和管脚分配 (10)4.3分频器和状态机的图示符号 (11)4.4仿真波形图 (12)附录 (13)结束语 (17)参考文献 (18)1引言在交通发达的当代,交通灯控制器无疑是最实用的的工具。
华中科技大学基于xilinx FPGA的VHDL交通灯控制器的设计--基于Spartan3E开发板专业:电子信息工程一.任务设计要求①设计一个十字路口交通信号灯的定时控制电路。
要求红、绿灯按一定的规律亮和灭,并在亮灯期间进行倒计时,并将运行时间用数码管/液晶显示出来。
②绿灯亮时,为该车道允许通行信号,红灯亮时,为该车道禁止通行信号。
要求主干道每次通行时间为99秒,支干道每次通行时间为30秒。
每次变换运行车道前绿灯闪烁,持续时间为5秒。
即车道要由主干道转换为支干道时,主干道在通行时间只剩下5秒钟时,绿灯闪烁显示,支干道仍为红灯,以便主干道上已过停车线的车继续通行,未过停车线的车停止通行。
同理,当车道由支干道转换为主干道时,支干道绿灯闪烁显示5秒钟,主干道仍为红灯。
③对红、绿灯的运行时间要能比较方便的进行重新设置。
④对器件进行在系统编程和实验验证。
⑤用VHDL语言对设计进行描述,设计一个测试方案,通过ISE对设计进行仿真验证。
并能够下载到实验板上调试成功。
任务扩展:在原设计的基础上加入指示方向的功能。
二.系统设计1.系统原理图与说明由系统设计原理图,我以清楚地将系统分为六个模块:分频模块,时间设置模块,状态转换模块,时间计算模块,LED流水灯模块,LCD显示模块。
1)分频模块分频模块其作用为:由于Spartan3E板上提供的时钟信号为50MHz,而设计所需时钟信号为1Hz,故使用分频模块将50MHz信号分频为1Hz信号。
2)时间置数模块由于任务设计要求可以对主干道,支干道上左转、绿灯运行的时间进行重新设置调整,所以要对系统进行参数化设计。
首先引入一组参数,main_gh,main_gl,main_lh,main_ll,branch_gh,branch_gl,branch_lh,branch_ll(下划线后面的字母分别取green,left,high,low首字母).需要置数时,首先选择对主干道还是支干道时间置数,这里设置一个main_or_branch参数,当main_or_branch为高时设置支干道时间,为低时设置主干道时间。
置数时,通过s_set_button,l_set_button对时间进行设置,具体方法参见代码。
为了置数方便,引入一个add_or_decent参数,低电平时按下button可以增计数,高电平时按下可以减计数。
3)状态转换模块状态转化模块是整个系统的核心模块它控制整个交通灯系统的状态变化,整个过程划分为四个基本状态:主干道绿灯、主干道左转、支干道绿灯、支干道左转,用state、s_or_l为00、01、10、11来代表。
每当一个状态的计数器为00时,state、s_or_l发生改变,以实现状态间的转换,进而控制交通灯的变化。
4)时间计算模块这次设计中扩展了左转向的功能,因此红灯时间不仅仅是另一干道的直行时间,而是直行时间和左转时间之和。
5)LCD显示模块Spartan3E板上只有LCD显示模块,所以采用此模块显示当前亮灯的剩余时间和设置时间模块的时间显示。
通过输入counterplay_1l,counterplay_1h,counterplay_2l,counterplay_2h四位二进制数,加上0011显示成十进制数,分别代表两位数的低位和高位6)LED显示模块由输入信号state、s_or_l、flash,分别取000,001,010,011,100,101,110,111所得到的main_green,main_left,main_red,branch_left, branch_green,branch_red的不同值,来控制主干道,支干道红绿左转灯的亮灭。
其中 1表示亮,0表示灭。
如表3-1 所示。
由上表可得到:main_green <= NOT(state) AND NOT(s_or_l) AND (NOT((flash AND clk))); main_left <= NOT(state) AND s_or_l AND (NOT((flash AND clk))); main_red <= state;branch_green <= state AND NOT(s_or_l) AND (NOT((flash AND clk))); branch_left <= state AND s_or_l AND (NOT((flash AND clk))); branch_red <= NOT(state);2.输入输出设计任务设计开发板基于Spartan3E 板,具体输入输出设定如下:1)输入:开关:main_or_branch :设置主干道还是支干道EN : 使能信号run_or_set : 设置运行模式还是时间设置模式 add_or_decent : 置数模式:增加或者减少按键:s_set_button : 直行时间设置按键l_set_button : 左转时间设置按钮时钟:clk2)输出:LCD 显示屏:分别显示当前亮灯的剩余秒数LED 灯:main_green,main_red,main_leftbranch_left,branch_green,branch_red3、状态转换图S0状态:主干道绿灯、支干道红灯S1状态:主干道左转、支干道红灯S2状态:支干道绿灯、主干道红灯S3状态:支干道左转、主干道红灯 S0时间为0?S1YN 时间为0?NY S2时间为0?时间为0?Y S3Y NN三.各模块代码以及仿真波形◆分频模块代码因为1HZ波形太长,不易仿真,故仿真波形采用100HZ的输入clk :50MHZ输出clk1:100HZ◆时间设置模块部分代码以上是直行时间设置代码。
左转设置类似,在此不再复制仿真设置输入:clkmain_or_branch 设置为0add_or_decent 设置为0s_set_button 设置为周期为1周期的信号l_set_button 设置为低电平波形如下时间计算模块代码波形仿真输入输出与预期相符合。
状态转换模块波形仿真分别给主干道,支干道个颜色灯持续时间赋值,再给定,当前亮灯的剩余时间,然后又进行仿真,结果符合预期LED模块代码波形仿真分别给予输入不同周期的高低点评,相互叠加的结果符合预期。
LCD模块代码library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity LCD isport( clk : in STD_LOGIC;rst_n : in STD_LOGIC;counter_play1h, counter_play1l : in STD_LOGIC_VECTOR(3 downto 0); counter_play2h, counter_play2l : in STD_LOGIC_VECTOR(3 downto 0);--degree1, degree2 : in STD_LOGIC_VECTOR(3 downto 0);SF_D : out STD_LOGIC_VECTOR(3 downto 0);LCD_E, LCD_RS, LCD_RW: out STD_LOGIC);end LCD;architecture behavior of LCD istype tx_sequence is (high_setup, high_hold, oneus, low_setup, low_hold, fortyus, done);signal tx_state : tx_sequence := done;signal tx_byte : std_logic_vector(7 downto 0);signal tx_init : std_logic := '0';type init_sequence is (idle, fifteenms, one, two, three, four, five, six, seven, eight, done);signal init_state : init_sequence := idle;signal init_init, init_done : std_logic := '0';signal i : integer range 0 to 750000 := 0;signal i2 : integer range 0 to 2000 := 0;signal i3 : integer range 0 to 82000 := 0;signal SF_D0, SF_D1 : std_logic_vector(3 downto 0);signal LCD_E0, LCD_E1 : std_logic;signal mux : std_logic;--????type display_state is (init, function_set, entry_set, set_display, clr_display, pause, set_addr,max_degree_1,max_degree_2,temperature_1,temperature_2,degree_1,degree_2 ,blank1,blank2,blank3);signal cur_state : display_state := init;begin--LED <= tx_byte; --for diagnostic purposes--SF_CE0 <= '1'; --disable intel strataflashLCD_RW <= '0'; --write only--The following "with" statements simplify the process of adding and removing states.--when to transmit a mand/data and when not towith cur_state selecttx_init <= '0' when init | pause ,'1' when others;--control the buswith cur_state selectmux <= '1' when init,'0' when others;--control the initialization sequencewith cur_state selectinit_init <= '1' when init,'0' when others;--register selectwith cur_state selectLCD_RS <= '0' when function_set|entry_set|set_display|clr_display|set_addr,'1' when others;--what byte to transmit to lcd--refer to datasheet for an explanation of these valueswith cur_state selecttx_byte <= "00101000" when function_set, -- ???????"00000110" when entry_set,"00001100" when set_display,"00000001" when clr_display,"10000000" when set_addr,"0011"&counter_play1h when max_degree_1,"0011"&counter_play1l when max_degree_2,"00100000" when blank1,"0011"&counter_play2h when temperature_1,"0011"&counter_play2l when temperature_2,"00100000" when blank2,"00100000" when degree_1,"00100000" when degree_2,"00100000" when blank3,"00100000" when others;--main state machinedisplay: process(clk, rst_n)beginif(rst_n='0') thencur_state <= function_set;elsif(clk='1' and clk'event) thencase cur_state is--refer to intialize state machine belowwhen init =>if(init_done = '1') thencur_state <= function_set;elsecur_state <= init;end if;--every other state but pause uses the transmit state machine when function_set =>if(i2 = 2000) thencur_state <= entry_set;elsecur_state <= function_set;end if;when entry_set =>if(i2 = 2000) thencur_state <= set_display;elsecur_state <= entry_set;end if;when set_display =>if(i2 = 2000) thencur_state <= clr_display;elsecur_state <= set_display;end if;when clr_display =>i3 <= 0;if(i2 = 2000) thencur_state <= pause;elsecur_state <= clr_display;end if;when pause =>if(i3 = 82000) thencur_state <= set_addr;i3 <= 0;elsecur_state <= pause;i3 <= i3 + 1;end if;when set_addr =>if(i2 = 2000) thencur_state <= max_degree_1;elsecur_state <= set_addr;end if;when max_degree_1 =>if(i2 = 2000) thencur_state <= max_degree_2;elsecur_state <= max_degree_1;end if;when max_degree_2 =>if(i2 = 2000) thencur_state <= blank1;elsecur_state <= max_degree_2;end if;when blank1 =>if(i2 = 2000) thencur_state <= temperature_1;elsecur_state <= blank1;end if;when temperature_1 =>if(i2 = 2000) thencur_state <= temperature_2;elsecur_state <= temperature_1;end if;when temperature_2 =>if(i2 = 2000) thencur_state <= blank2;elsecur_state <= temperature_2;end if;when blank2 =>if(i2 = 2000) thencur_state <= degree_1;elsecur_state <= blank2;end if;when degree_1 =>if(i2 = 2000) thencur_state <= degree_2;elsecur_state <= degree_1;end if;when degree_2 =>if(i2 = 2000) thencur_state <= blank3;elsecur_state <= degree_2;end if;when blank3 =>if(i2 = 2000) thencur_state <=set_addr ;elsecur_state <= blank3;end if;end case;end if;end process display;with mux selectSF_D <= SF_D0 when '0', --transmitSF_D1 when others; --initialize with mux selectLCD_E <= LCD_E0 when '0', --transmitLCD_E1 when others; --initialize --specified by datasheettransmit : process(clk, rst_n, tx_init)beginif(rst_n='0') thentx_state <= done;elsif(clk='1' and clk'event) thencase tx_state iswhen high_setup => --40nsLCD_E0 <= '0';SF_D0 <= tx_byte(7 downto 4);if(i2 = 2) thentx_state <= high_hold;i2 <= 0;elsetx_state <= high_setup;i2 <= i2 + 1;end if;when high_hold => --230nsLCD_E0 <= '1';SF_D0 <= tx_byte(7 downto 4);if(i2 = 12) thentx_state <= oneus;i2 <= 0;elsetx_state <= high_hold;i2 <= i2 + 1;end if;when oneus =>LCD_E0 <= '0';if(i2 = 50) thentx_state <= low_setup;i2 <= 0;elsetx_state <= oneus;i2 <= i2 + 1;end if;when low_setup =>LCD_E0 <= '0';SF_D0 <= tx_byte(3 downto 0);if(i2 = 2) thentx_state <= low_hold;i2 <= 0;elsetx_state <= low_setup;i2 <= i2 + 1;end if;when low_hold =>LCD_E0 <= '1';SF_D0 <= tx_byte(3 downto 0);if(i2 = 12) thentx_state <= fortyus;i2 <= 0;elsetx_state <= low_hold;i2 <= i2 + 1;end if;when fortyus =>LCD_E0 <= '0';if(i2 = 2000) thentx_state <= done;i2 <= 0;elsetx_state <= fortyus;i2 <= i2 + 1;end if;when done =>LCD_E0 <= '0';if(tx_init = '1') thentx_state <= high_setup;i2 <= 0;elsetx_state <= done;i2 <= 0;end if;end case;end if;end process transmit;--specified by datasheetpower_on_initialize: process(clk, rst_n, init_init) --power on initialization sequencebeginif(rst_n='0') theninit_state <= idle;init_done <= '0';elsif(clk='1' and clk'event) thencase init_state iswhen idle =>init_done <= '0';if(init_init = '1') theninit_state <= fifteenms;i <= 0;elseinit_state <= idle;i <= i + 1;end if;when fifteenms =>init_done <= '0';if(i = 750000) theninit_state <= one;i <= 0;elseinit_state <= fifteenms;i <= i + 1;end if;when one =>SF_D1 <= "0011";LCD_E1 <= '1';init_done <= '0';if(i = 11) theninit_state<=two;i <= 0;elseinit_state<=one;i <= i + 1;end if;when two =>LCD_E1 <= '0';init_done <= '0';if(i = 205000) theninit_state<=three;i <= 0;elseinit_state<=two;i <= i + 1;end if;when three =>SF_D1 <= "0011";LCD_E1 <= '1';init_done <= '0';if(i = 11) theninit_state<=four;i <= 0;elseinit_state<=three;i <= i + 1;end if;when four =>LCD_E1 <= '0';init_done <= '0';if(i = 5000) theninit_state<=five;i <= 0;elseinit_state<=four;i <= i + 1;end if;when five =>SF_D1 <= "0011";LCD_E1 <= '1';init_done <= '0';if(i = 11) theninit_state<=six;i <= 0;elseinit_state<=five;i <= i + 1;end if;when six =>LCD_E1 <= '0';init_done <= '0';if(i = 2000) theninit_state<=seven;i <= 0;elseinit_state<=six;i <= i + 1;end if;when seven =>SF_D1 <= "0010";LCD_E1 <= '1';init_done <= '0';if(i = 11) theninit_state<=eight;i <= 0;elseinit_state<=seven;i <= i + 1;end if;when eight =>LCD_E1 <= '0';init_done <= '0';if(i = 2000) theninit_state<=done;i <= 0;elseinit_state<=eight;i <= i + 1;end if;when done =>init_state <= done;init_done <= '1';end case;end if;end process power_on_initialize;end behavior;因为LCD模块无法仿真,故在此不做仿真四、实验总结1、心得体会此次设计实验是对本课程的一次总结,通过此次实验大大提高了自己的动手能力,对VHDL这门语言以及对FPGA的开发油了更加深入的了解在动手设计实验的过程中,也遇到了很多问题,比如计数器工作不正常,LED 灯非正常闪烁,也用了了很大的功夫才把BUG解决。