课程设计基于CPLD的交通灯设计_第1页
课程设计基于CPLD的交通灯设计_第2页
课程设计基于CPLD的交通灯设计_第3页
课程设计基于CPLD的交通灯设计_第4页
课程设计基于CPLD的交通灯设计_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第一章 绪论1.1 交通灯的介绍1918年诞生的第一盏交通灯只有红绿两色,它是圆形四面投影器,被安装在纽约市五号街的一座高塔上,它的诞生,使城市交通大为改善。1925年,留学美国的中国电机专家胡汝鼎提出在绿灯之后加个黄灯的设想被采纳,于是诞生了真正意义上的三色交通灯。传统的交通灯主要由单片机来控制,它主要由红黄绿三色灯组成。工作原理是设置好南北向和东西向的各色灯的亮灭顺序和持续时间来指挥车辆通行。交通灯的发明和使用极大地保障了人民的生命安全,但因此引起的交通事故却还是时有发生。究其原因有以下两点:(1)单片机稳定性不够高,长年累月的运行容易引起故障,使得交通信号混乱;(2)单片机控制的交通灯不

2、利于扩展,当交通灯功能扩充或更改的时候只能全部更换,不但浪费了资源,而带来了不便。因此,传统的交通灯能基本满足一般交通状况的需求。然而,对于交通繁忙、路况复杂的大都市来说就显得力不从心了。1.2 基于cpld的交通灯的优点基于cpld的交通灯改变了基于单片机的传统交通灯不稳定和不利于扩展的缺点。本文设计的基于cpld的交通信号控制电路,突破了单片机的种种限制,对传统的交通灯做了如下改进:(1)用三色箭头指示灯来替代传统的红黄绿三色灯,分别指示左转、直行和右转,改变了传统交通灯一灯三向的状态,使交通更趋规则。(2)增加了左弯待转指示灯,缓解了转弯时的拥堵状况。(3)增加了直行绿灯倒计时功能,以便

3、让司机控制过十字路口的车速,使交通更加安全有序。(4)增加了全红灯的紧急状态。尽管警车、救护车等公务车可以在绿灯的状态下任意前行,可繁忙的交通还是使得公务车“有路难行”。紧急状态彻底改变了这一状况,让十字路口各方向的车都让路给公务车,真正做到畅通无阻。本文设计的交通信号控制电路更趋于理性化和智能化,交通部门可以依据各路段各个时间点交通的繁忙状态和路况的复杂程度,利用cpld的可擦除性,根据时段或路段进行不同的设置,避免了资源浪费。而且,cpld的可扩展性也有利于交通部门在新的交通功能发明之后,在原有交通灯的基础上进行扩展,而不必重新设计,全部更换。1.3 eda简介eda技术是指以计算机为工作

4、平台,融合应用电子技术、计算机技术、信息处理及智能化技术的最新成果,进行电子产品的自动设计。 利用eda工具,电子设计师可以从概念、算法、协议等开始设计电子系统,大量工作可以通过计算机完成,并可以将电子产品从电路设计、性能分析到设计出ic版图或pcb版图的整个过程的计算机上自动处理完成。 现在对eda的概念或范畴用得很宽。包括在机械、电子、通信、航空航天、化工、矿产、生物、医学、军事等各个领域,都有eda的应用。目前eda技术已在各大公司、企事业单位和科研教学部门广泛使用。例如在飞机制造过程中,从设计、性能测试及特性分析直到飞行模拟,都可能涉及到eda技术。本文所指的eda技术,主要针对电子电

5、路设计、pcb设计和ic设计。 eda设计可分为系统级、电路级和物理实现级。1.4 quartus简介 quartus ii 是altera公司的综合性pld开发软件,支持原理图、vhdl、veriloghdl以及ahdl(altera hardware description language)等多种设计输入形式,内嵌自有的综合器以及仿真器,可以完成从设计输入到硬件配置的完整pld设计流程。 quartus ii可以在xp、linux以及unix上使用,除了可以使用tcl脚本完成设计流程外,提供了完善的用户图形界面设计方式。具有运行速度快,界面统一,功能集中,易学易用等特点。 quartus

6、 ii支持altera的ip核,包含了lpm/megafunction宏功能模块库,使用户可以充分利用成熟的模块,简化了设计的复杂性、加快了设计速度。对第三方eda工具的良好支持也使用户可以在设计流程的各个阶段使用熟悉的第三方eda工具。 此外,quartus ii 通过和dsp builder工具与matlab/simulink相结合,可以方便地实现各种dsp应用系统;支持altera的片上可编程系统(sopc)开发,集系统级设计、嵌入式软件开发、可编程逻辑设计于一体,是一种综合性的开发平台。 maxplus ii 作为altera的上一代pld设计软件,由于其出色的易用性而得到了广泛的应用

7、。目前altera已经停止了对maxplus ii 的更新支持,quartus ii 与之相比不仅仅是支持器件类型的丰富和图形界面的改变。altera在quartus ii 中包含了许多诸如signaltap ii、chip editor和rtl viewer的设计辅助工具,集成了sopc和hardcopy设计流程,并且继承了maxplus ii 友好的图形界面及简便的使用方法。altera quartus ii 作为一种可编程逻辑的设计环境, 由于其强大的设计能力和直观易用的接口,越来越受到数字系统设计者的欢迎。第二章 设计电路 2.1 设计内容要求2.1.1 设计制作一块十字路口的交通灯信

8、号灯的控制电路的专用芯片。2.1.1 a 方向和b方向各设置红(r)、黄(y)、绿(g)三盏灯,三盏灯按合理的顺序亮灭,并能将灯亮的时间以倒计时的方式显示出来。2.1.3、 两个方向各灯的时间可方便地进行设置和修改。假设a方向为主干道,车流量大,a方向通行时间比b方向长。设a方向每次至多通行t1秒,b方向每次至多通行t2秒,黄灯亮t秒。2.2 设计初步构思 a方向b方向g1y1r1g2y2r225秒10000130秒5秒01010015秒20秒0010105秒(各交通灯状态表)如图所示,g1、y1、r1、g2、y2、r2分别代表a、b方向的绿、黄、红灯。显然,交通量较大的a方向绿灯亮25秒,黄

9、灯红灯一次亮5秒和20秒,而交通量较小的b方向绿、黄、红灯分别亮15秒、5秒、30秒。同时图中1表示该交通灯处于点亮状态。2.3 设计总框图如图所示,其中分别用两个控制模块对各倒计时计数器进行控制,从而达到设计要求,显示模块用来显示时间,二极管代表交通灯。第三章 各模块设计原理及其仿真3.1 5秒倒计时计数器3.1.1 源代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity djs5 is port(clk:in std_logic; cr:in std_logic; en2:in s

10、td_logic; j2:out std_logic; q1:out std_logic_vector(3 downto 0);end djs5;architecture a of djs5 is signal bcd1n:std_logic_vector(3 downto 0);begin process(clk,cr) begin if(cr=0) then bcd1n=0101; elsif(en2=1)then if (clkevent and clk=1)then if(bcd1n=0)then bcd1n=0000; else bcd1n=bcd1n-1; end if; end

11、if; end if; end process;q1=bcd1n; process(bcd1n) begin j2=0; if(bcd1n=0)then j2=1; end if; end process;end;3.1.2 元件图(5秒倒计时计数器元件图)3.1.3 仿真图(5秒倒计时计数器仿真图)3.1.4 电路图(5秒倒计时计数器rtl电路图)3.1.5流程图开始定义参数清零端cr=0?y恢复初始值n使能端en2=1输入端信号bcd1n=bcd1n-1nbcd1n=0?yj2=1结束(5秒倒计时计数器的流程图)3.2 25秒倒计时计数器3.2.1 源代码library ieee;use

12、ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity djs25 is port(clk:in std_logic; cr:in std_logic; en1:in std_logic; j1:out std_logic; q1:out std_logic_vector(3 downto 0); y10:out std_logic_vector(3 downto 0); end djs25;architecture a of djs25 is signal bcd1n: std_logic_vector(3 downto

13、 0); signal vcd10n:std_logic_vector(3 downto 0); begin process(clk,cr) begin if(cr=0)then bcd1n=0101; elsif(en1=1)then if(clkevent and clk=1)then if(bcd1n=0 and vcd10n/=0)then bcd1n=1001; elsif(bcd1n=0 and vcd10n=0)then bcd1n=0000; else bcd1n=bcd1n-1; end if; end if; end if; end process; q1=bcd1n; y

14、10=vcd10n; process (clk,cr) begin if(cr=0)then vcd10n=0010; elsif (en1=1)then if(clkevent and clk=1)then if(bcd1n=0)then if(vcd10n=0)then vcd10n=0000; else vcd10n=vcd10n-1; end if; end if; end if; end if; end process; process(bcd1n,vcd10n) begin j1=0; if(bcd1n=0 and vcd10n=0)then j1=1; end if; end p

15、rocess; end;3.2.2 元件图(25秒倒计时计数器元件图)3.2.3 仿真图(25秒倒计时计数器仿真图)3.2.4 电路图(25秒倒计时计数器rtl电路图)3.3 20秒倒计时计数器3.3.1源代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all; entity djs20 is port(clk:in std_logic; cr: in std_logic; en3:in std_logic; j3:out std_logic; q1:out std_logic_vector(3 do

16、wnto 0); y10:out std_logic_vector(3 downto 0); end djs20; architecture a of djs20 is signal bcd1n:std_logic_vector(3 downto 0); signal vcd10n:std_logic_vector(3 downto 0); begin process(clk,cr) begin if(cr=0)then bcd1n=0000;-j1=1; elsif(en3=1)then if(clkevent and clk=1)then if(bcd1n=0 and vcd10n/=0)

17、then bcd1n=1001; elsif(bcd1n=0 and vcd10n=0)then bcd1n=0000; else bcd1n=bcd1n-1; end if; end if; end if; end process; q1=bcd1n; y10=vcd10n; process(clk,cr) begin if(cr=0)then vcd10n=0010; elsif (en3=1)then if(clkevent and clk=1)then if(bcd1n=0)then if(vcd10n=0)then vcd10n=0000; else vcd10n=vcd10n-1;

18、 end if; end if; end if; end if; end process; process(bcd1n,vcd10n) begin j3=0; if(bcd1n=0 and vcd10n=0)then j3=1; end if; end process;end;3.3.2 元件图(20秒倒计时计数器元件图)3.3.3仿真图(20s倒计时计数器仿真图)3.3.4 电路图(20秒倒计时计数器rtl电路图)3.4 30秒倒计时计数器3.4.1 源代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned

19、.all;entity djs30 is port(clk: in std_logic; cr:in std_logic; en4: in std_logic; j4:out std_logic; q1:out std_logic_vector(3 downto 0); y10:out std_logic_vector(3 downto 0);end djs30;architecture a of djs30 is signal bcd1n:std_logic_vector(3 downto 0); signal vcd10n:std_logic_vector(3 downto 0);begi

20、nprocess(clk,cr) begin if(cr=0)then bcd1n=0000;-j1=1; elsif(en4=1)then if(clkevent and clk=1)then if(bcd1n=0 and vcd10n/=0)then bcd1n=1001; elsif(bcd1n=0 and vcd10n=0)then bcd1n=0000; else bcd1n=bcd1n-1; end if; end if; end if;end process; q1=bcd1n; y10=vcd10n;process(clk,cr)begin if(cr=0)then vcd10

21、n=0011;-j1=1; elsif(en4=1)then if(clkevent and clk=1)then if(bcd1n=0)then if(vcd10n=0)then vcd10n=0000; else vcd10n=vcd10n-1; end if; end if; end if; end if;end process;process(bcd1n,vcd10n)begin j4=0; if(bcd1n=0 and vcd10n=0)then j4=1;end if;end process;end ;3.4.2 元件图(30秒倒计时计数器元件图)3.4.3 仿真图(30秒倒计时计

22、数器仿真图)3.4.4电路图(30秒倒计时计数器rtl电路图)3.5 15秒倒计时计数器3.5.1 源代码library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity djs15 is port (clk:in std_logic; cr:in std_logic; en5:in std_logic; j5:out std_logic; q1:out std_logic_vector(3 downto 0); y10:out std_logic_vector(3 downto 0);end djs

23、15;architecture a of djs15 is signal bcd1n:std_logic_vector(3 downto 0); signal vcd10n:std_logic_vector(3 downto 0);begin process(clk,cr) begin if(cr=0)then bcd1n=0101 ;-j1=1; elsif(en5=1)then if(clkevent and clk=1)then if(bcd1n=0 and vcd10n/=0)then bcd1n=1001; elsif(bcd1n=0 and vcd10n=0)then bcd1n=

24、0000; else bcd1n=bcd1n-1; end if; end if; end if; end process; q1=bcd1n; y10=vcd10n; process (clk,cr) begin if(cr=0)then vcd10n=0001; elsif(en5=1)thenif(clkevent and clk=1)then if(bcd1n=0)then if(vcd10n=0)then vcd10n=0000; else vcd10n=vcd10n-1; end if; end if; end if; end if; end process;process(bcd

25、1n,vcd10n) begin j5=0; if(bcd1n=0 and vcd10n=0)then j5=1; end if; end process; end;3.5.2 元件图(15秒倒计时计数器元件图)3.5.3 仿真图(15秒倒计时计数器仿真图)3.5.4电路图(15秒倒计时计数器rtl电路图)3.6 控制模块3.6.1 源代码alibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity kongzhi1 is port (c

26、lk:in std_logic; state_inputs: in std_logic_vector(0 to 1); c1,c2,c3,b1,b2,b3:out std_logic; w0,w1,w2:in std_logic; r1:out std_logic; y1:out std_logic; g1:out std_logic; reset:in std_logic); end kongzhi1; architecture a of kongzhi1 is type state_space is(s0,s1,s2); signal current_state,next_state:st

27、ate_space; begin process(clk) begin if reset=1thencurrent_stateg1=0;y1=1;r1=1; if w0=1then next_state=s1;-25s; end if; b1=0; if(w0=0) then b1g1=1;y1=0;r1=1; if w1=1 then next_state=s2;-5s end if; b2=0; if(w1=0)then b2g1=1;y1=1;r1=0; if w2=1then next_state=s0;-20s end if; b3=0; if(w2=0) then b3=1; en

28、d if; end case; end if; end process; c1=1 when next_state=s0 else 0; c2=1 when next_state=s1 else 0; c3=1 when next_state=s2 else 0;end;3.6.2 元件图(控制模块1的元件图)3.6.3 仿真图(控制模块1的仿真图)3.6.4 电路图3.6.5 源代码blibrary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;ent

29、ity kongzhi2 is port(state_inputs: in std_logic_vector(0 to 1); clk:in std_logic; c1,c2,c3,b1,b2,b3:out std_logic; w0,w1,w2:in std_logic; r2:out std_logic; y2:out std_logic; g2:out std_logic; reset:in std_logic);end kongzhi2;architecture a of kongzhi2 istype state_space is(s0,s1,s2);signal current_s

30、tate,next_state:state_space;beginprocess(clk)begin if reset=1then current_stateg2=1;y2=1;r2=0;if w0=1then next_state=s1;-30send if; b1=0; if(w0=0)then b1g2=0;y2=1;r2=1; if w1=1then next_state=s2;-15s end if; b2=0; if(w1=0)then b2 g2=1;y2=0;r2=1;if w2=1then next_state=s0;-5send if; b3=0;if(w2=0)then

31、b3=1;end if;end case;end if;end process;c1=1when next_state=s0 else 0;c2=1when next_state=s1 else0;c3=1when next_state=s2 else0;end;3.6.6 元件图(控制模块2的元件图)3.6.7 仿真图(控制模块2的仿真图)3.6.8 电路图(控制模块2的rtl电路图)3.6.9 流程图ystate=s1?开始定义参数state=s0?rest=1?系统变回零状态绿灯亮yynnstate=s2?红灯亮黄灯亮ynn结束(控制模块流程图)3.7 显示模块3.7.1 源代码libr

32、ary ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity xianshi is port( b1,b2,b3,b4,b5,b6:in std_logic; q0:in std_logic_vector(3 downto 0); q1:in std_logic_vector(3 downto 0); q2:in std_logic_vector(3 downto 0); q3:in std_logic_vector(3 downto 0); q4:in std_logic_vector(3 downto

33、 0); q5:in std_logic_vector(3 downto 0); q6:in std_logic_vector(3 downto 0); q7:in std_logic_vector(3 downto 0); q8:in std_logic_vector(3 downto 0); q9:in std_logic_vector(3 downto 0); clk:in std_logic; sg:out std_logic_vector(6 downto 0); bt:out std_logic_vector(7 downto 0);end;architecture one of

34、xianshi is signal cn:integer range 0 to 2; signal cn1:integer range 0 to 2; signal cnt2:std_logic_vector(1 downto 0); signal a:std_logic_vector(3 downto 0);beginp1:process(cn)beginif(b1=1)then cn=0;end if;if(b2=1)then cn=1;end if;if(b3=1)then cn=2;end if;if(b4=1)then cn1=0;end if;if(b5=1)then cn1=1;

35、end if;if(b6=1)then cn1 case cnt2 is when 00=bt=00000001;abt=00000010;anull; end case; when 1=bt=00000001;a case cnt2 is when 00=bt=00000001;abt=00000010;anull; end case; when others =null; end case; case cn1 is when 0= case cnt2 is when 00=bt=00000100;abt=00001000;anull; end case; when 1= case cnt2 is when 00=bt=00000100;ab

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论