课程设计-基于EDA的交通灯的设计.doc

上传人:西安人 文档编号:3292372 上传时间:2019-08-08 格式:DOC 页数:31 大小:730.92KB
返回 下载 相关 举报
课程设计-基于EDA的交通灯的设计.doc_第1页
第1页 / 共31页
课程设计-基于EDA的交通灯的设计.doc_第2页
第2页 / 共31页
课程设计-基于EDA的交通灯的设计.doc_第3页
第3页 / 共31页
课程设计-基于EDA的交通灯的设计.doc_第4页
第4页 / 共31页
课程设计-基于EDA的交通灯的设计.doc_第5页
第5页 / 共31页
点击查看更多>>
资源描述

《课程设计-基于EDA的交通灯的设计.doc》由会员分享,可在线阅读,更多相关《课程设计-基于EDA的交通灯的设计.doc(31页珍藏版)》请在三一文库上搜索。

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 cnt2=cnt2+1;end if;end process p3;end disp_arc;2.10、顶层文件的编写将以上各个单元模块仿真成功后,再进行顶层文件的编写。将各个单元模块的变量赋值给顶层文件,从而将各个单元模块连接起来,统一调配。得到顶层文件的实体模块:2.10.1源程序:library ieee;use ieee.std_logic_1164.all;us

32、e ieee.std_logic_unsigned.all;entity chenliangtop is port(clk0,rest:in std_logic; Ra,Ya,Ga,Rb,Yb,Gb:out std_logic; S_G:out std_logic_vector(6 downto 0); B_T:out std_logic_vector(7 downto 0);end;architecture top_arc of chenliangtop iscomponent chenliangfen 图 2-12 顶层实体 port(clk0:in std_logic; clk1:out std_logic);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 研究报告 > 信息产业


经营许可证编号:宁ICP备18001539号-1