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

下载本文档

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

文档简介

1、 目 录 目录.1第一章 设计思路21.1、设计内容及要求21.2、设计构思21.3、设计构思框图3第二章 单元模块设计与仿真42.1、时钟分频模块42.2、5秒倒计时计数器模块52.3、35秒倒数计时计数器模块82.4、25秒倒计时计数器模块102.5、40秒倒计时计数器模块122.6、20秒倒计时计数器模块142.7、a方向控制模块162.8、b方向控制模块172.9、显示模块192.10、顶层文件的编写222.11. 总电路图25第三章 调试273.1、硬件实验273.2、实验现象28心得体会29参考文献30第一章 设计思路1.1、设计内容及要求1. 设计制作一块十字路口的交通信号灯的控

2、制电路的专用芯片。2. a方向和b方向各设置红(r)、黄(y)、绿(g)三盏灯,三盏灯按合理的顺序亮灭,并能将灯亮的时间以倒计时的方式显示出来。3. 两个方向各灯的时间可方便地进行设置和修改。假设a方向为主干道,车流量大,a方向通行时间比b方向长。设a方向每次至少通行t1秒,b方向每次至多通行t2秒,黄灯亮t秒。1.2、设计构思 为了方便a、b方向的车流不堵塞,默认a方向先亮绿灯,同时b方向亮红灯,时间以倒数显示出来,在绿灯时间到达时,通过3秒黄灯,过渡到红灯,使得行驶过程中的车辆有足够的时间停下来。所以,红灯的时间是另一方向的绿灯时间加上黄灯的时间。用ga、ya、ra依次代表主干道a方向的绿

3、灯、黄灯和红灯。用gb、yb、rb依次代表支干道b方向的绿灯、黄灯和红灯。根据a、b方向的车流量大小,令a方向绿灯亮30s,黄灯亮3s,红灯亮28s;b方向绿灯亮25s,黄灯3s,红灯33s。如图1-1,图中1代表点亮,0代表灭。 a方向(主干道)b方向(支干道)时间gayaragbybrb时间35s10000140s5s01010020s25s0010105s图1-1 交通灯亮灭时间安排1.3、设计构思框图图1-2 设计构思框图 如图所示,通过a、b方向控制器分别控制a和b方向各自的时间倒数模块以及时间显示。第2章 单元模块设计与仿真2.1、时钟分频模块 系统时钟计时模块需要1hz的脉冲,与

4、系统的动态扫描需要的脉冲不同。分频模块主要为系统提供所需的时钟计时脉冲。该模块将50mhz的脉冲信号进行分频,产生1s的方波,作为系统时钟计时信号。2.1.1、源程序: -模块 fen。它是分频 得到1hz library ieee; use ieee.std_logic_1164.all; entity chenliangfen is port(clk:in std_logic; 图2-1 分频模块 clk1s:out std_logic); end chenliangfen; architecture fen_arc of chenliangfen is begin process(clk

5、) variable cnt:integer range 0 to 49999999 begin if clkevent and clk=1then if cnt=49999999 then clk1s=1; else cnt:=cnt+1 clk1s=0; end if; end if; end process; end fen_arc;2.1.2、仿真图形:2.2、5秒倒计时计数器模块2.2.1、源程序: library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity chenliang5s i

6、s port(clk:in std_logic; cr:in std_logic; 图2-2 5s倒计时模块 en2:in std_logic; j2:out std_logic; q1:out std_logic_vector(3 downto 0) );end chenliang5s;architecture t5_arc of chenliang5s 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(

7、clkevent and clk=1) then if(bcd1n=0) then bcd1n=0000; else bcd1n=bcd1n-1; end if; end if; end if;end process; q1=bcd1n;process(bcd1n) begin j2=0; if(bcd1n=0) then j2=1;end if;end process;end t5_arc;2.2.2、仿真图形: 图2-3 5s倒计时流程图2.3、35秒倒数计时计数器模块2.3.1、源程序:library ieee;use ieee.std_logic_1164.all;use ieee.s

8、td_logic_unsigned.all;entity chenliang35s 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 chenliang35s; 图2-4 35s倒计时模块architecture t35_arc of chenliang35s is signal bcd1n: std_logic_vector(3 d

9、ownto 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=

10、bcd1n; y10=vcd10n;process(clk,cr)begin if(cr=0) then vcd10n=0011; 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=0and vcd10n=0) then j1=1; end if;en

11、d process;end t35_arc;2.3.2、仿真图形:2.4、25秒倒计时计数器模块2.4.1、源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity chenliang25s is port(clk:in std_logic; cr:in std_logic; en3:in std_logic; j3:out std_logic; q1:out std_logic_vector(3 downto 0); y10:out std_logic_vector(3 downto

12、 0);end chenliang25s; 图2-5 25秒倒计时模块architecture t25_arc of chenliang25s 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; elsif(en3=1)then if(clkevent and clk=1) then if(bcd1n=0 and vcd10n/=0) then bcd1n=1

13、001; 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; end if; end

14、 if; end if;end if;end process;process(bcd1n,vcd10n) begin j3=0; if(bcd1n=0and vcd10n=0) then j3=1; end if;end process;end t25_arc;2.4.2、仿真波形:2.5、40秒倒计时计数器模块2.5.1、源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity chenliang40s is port(clk:in std_logic; cr:in std_logi

15、c; 图2-6 40秒倒计时模块 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 chenliang40s;architecture t40_arc of chenliang40s is signal bcd1n: std_logic_vector(3 downto 0); signal vcd10n: std_logic_vector(3 downto 0);begin process(clk,cr) begin

16、if(cr=0) then bcd1n=0000; 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) the vcd10n=0100; elsif(en4=1)then

17、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=0and vcd10n=0) then j4=1; end if;end process;end t40_arc;2.5.2、仿真图形:2.6、20秒倒计时计数器模块2.6.1、源程序:library ieee;use ieee.std

18、_logic_1164.all;use ieee.std_logic_unsigned.all;entity chenliang20s is port(clk:in std_logic; cr:in std_logic; en5:in std_logic; 图2-7 20秒倒计时模块 j5:out std_logic; q1:out std_logic_vector(3 downto 0); y10:out std_logic_vector(3 downto 0);end chenliang20s;architecture t20_arc of chenliang20s is signal b

19、cd1n: 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; 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=0000; else bcd1n=bcd1n-1; end if; end i

20、f; end if;end process; q1=bcd1n; y10=vcd10n;process(clk,cr)begin if(cr=0) then vcd10n=0010; elsif(en5=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 j5=0; if(bcd1n=0 and vcd

21、10n=0) then j5=1; end if;end process;end t25_arc;2.6.2、仿真图形: 2.7、a方向控制模块2.7.1、源程序:library ieee;use ieee.std_logic_1164.all;entity chenliangc1 is port( clk: in std_logic; c1,c2,c3,b1,b2,b3:out std_logic; w0,w1,w2:in std_logic; ra:out std_logic; ya:out std_logic; ga:out std_logic; reset:in std_logic )

22、;end chenliangc1; 图2-8 a方向控制模块architecture c1_arc of chenliangc1 is type state_space is (s0,s1,s2); signal state:state_space;begin process(clk) begin if reset=1 then statega=1;ya=0;ra=0;if w0=0then state=s1;-35s end if; b1=0;if(w0=0)then b1ga=0;ya=1;ra=0;if w1=1then state=s2;-5s end if; b2=0;if(w1=0

23、)then b2ga=0;ya=0;ra=1;if w2=1then state=s0;-25s end if; b3=0;if(w2=0)then b3=1;end if; end case; end if;end process;c1=1 when state=s0 else 0; c2=1 when state=s1 else 0; c3=1 when state=s2 else 0;end c1_arc;2.7.2、仿真波形:2.8、b方向控制模块2.8.1、源程序:library ieee;use ieee.std_logic_1164.all;entity chenliangc2

24、is port( clk: in std_logic; c1,c2,c3,b1,b2,b3:out std_logic; w0,w1,w2:in std_logic; rb:out std_logic; yb:out std_logic; gb:out std_logic; reset:in std_logic ); end chenliangc2;architecture c2_arc of chenliangc2 is type state_space is (s0,s1,s2); signal state:state_space; 图2-9 b方向控制模块begin process(cl

25、k) begin if reset=1 then stategb=0;yb=0;rb=1;if w0=0then state=s1;-40s end if; b1=0;if(w0=0)then b1gb=1;yb=0;rb=0;if w1=1then state=s2;-20s end if; b2=0;if(w1=0)then b2gb=0;yb=1;rb=0;if w2=1then state=s0;-5s end if; b3=0;if(w2=0)then b3=1;end if; end case; end if;end process;c1=1 when state=s0 else

26、0; c2=1 when state=s1 else 0; c3=1 when state=s2 else 0;end c2_arc;2.8.2、仿真波形:图2-10 控制模块流程图2.9、显示模块2.9.1、源程序:library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity chenliangdisp is port( b1,b2,b3,b4,b5,b6:in std_logic; q0:in std_logic_vector(3 downto 0); q1:in std_logic_vect

27、or(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 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

28、0); clk:in std_logic; sg:out std_logic_vector(6 downto 0); bt:out std_logic_vector(7 downto 0);end chenliangdisp;architecture disp_arc of chenliangdisp is signal cn :integer range 0 to 2; signal cn1 :integer range 0 to 2 ;图2-11 显示模块 signal cnt2:std_logic_vector (1 downto 0); signal a :std_logic_vect

29、or(3 downto 0); beginp1:process(cn) begin if(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;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=0

30、0000001;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;abt=00001000;anull; end case; when 2=bt=00000100;a null; end case;end process p1;p2: process(a) begin case a

31、is when 0000=sgsgsgsgsgsgsgsgsgsgnull; end case; end process p2;p3:process(clk) begin if(clkevent and clk=1)then cnt2a,cr=a1,en1=a2,j1=a3,q1=a4,y10=a5);u2: chenliang5s port map(clk=a,cr=d1,en2=d2,j2=d3,q1=d4);u3: chenliang25s port map(clk=a,cr=e1,en3=e2,j3=e3,q1=e4,y10=e5);u4: chenliang40s port map(

32、clk=a,cr=f1,en4=f2,j4=f3,q1=f4,y10=f5);u5: chenliang20s port map(clk=a,cr=g1,en5=g2,j5=g3,q1=g4,y10=g5);u6:chenliang5s port map(clk=a,cr=h1,en2=h2,j2=h3,q1=h4);u7: chenliangc1 port map(clk=a,w0=a3,w1=d3,w2=e3,reset=rest,c1=a2,c2=d2,c3=e2,b1=a1,b2=d1,b3=e1,ra=ra,ya=ya,ga=ga);u8: chenliangc2 port map(

33、clk=a,w0=f3,w1=g3,w2=h3,reset=rest,c1=f2,c2=g2,c3=h2,b1=f1,b2=g1,b3=h1, rb=rb,yb=yb,gb=gb);u9: chenliangdisp port map(b1=a2,b2=d2,b3=e2,b4=f2,b5=g2,b6=h2,q0=a4,q1=a5,q2=d4,q3=e4,q4=e5, q5=f4,q6=f5,q7=g4,q8=g5,q9=h4,clk=clk0,sg=s_g,bt=b_t);u10:chenliangfen port map(clk=b,clk1=a);end top_arc; 2.11. 总电路图第三章 调试3.1、硬件实验将程序进行编译后,把管脚绑定后把程序下载到实验箱上进行调试。管脚绑定如下:clk0绑定时钟50mhz;rest绑定dk4rb绑定led6;-支干道红灯;yb绑定led7;-支干道黄灯gb绑定led8;-支干道绿灯;ra绑定led1;-主干道红灯ya绑定led2;-主干道黄灯;ga绑定led3;-主干道绿灯s_g0绑定g8;s_g1绑定f8;s_g2绑定e8;s_g3绑定d8

温馨提示

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

评论

0/150

提交评论