
目录.........................................................................................................1
第一章 设计思路
1.1、设计内容及要求
1. 设计制作一块十字路口的交通信号灯的控制电路的专用芯片。
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方向的绿灯、黄灯和红灯。用Gb、Yb、Rb依次代表支干道B方向的绿灯、黄灯和红灯。根据A、B方向的车流量大小,令A方向绿灯亮30S,黄灯亮3s,红灯亮28S;B方向绿灯亮25S,黄灯3s,红灯33s。如图1-1,图中1代表点亮,0代表灭。
| A方向(主干道) | B方向(支干道) | ||||||
| 时间 | Ga | Ya | Ra | Gb | Yb | Rb | 时间 |
| 35S | 1 | 0 | 0 | 0 | 0 | 1 | 40S |
| 5S | 0 | 1 | 0 | 1 | 0 | 0 | 20S |
| 25S | 0 | 0 | 1 | 0 | 1 | 0 | 5S |
1.3、设计构思框图
图1-2 设计构思框图
如图所示,通过A、B方向控制器分别控制A和B方向各自的时间倒数模块以及时间显示。
第二章 单元模块设计与仿真
2.1、时钟分频模块
系统时钟计时模块需要1HZ的脉冲,与系统的动态扫描需要的脉冲不同。分频模块主要为系统提供所需的时钟计时脉冲。该模块将50MHZ的脉冲信号进行分频,产生1S的方波,作为系统时钟计时信号。
2.1.1、源程序:
--模块 FEN。它是分频 得到1HZ
library ieee;
use ieee.std_logic_11.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)
variable cnt:integer range 0 to 49999999
begin
if clk'event and clk='1'then
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_11.all;
use ieee.std_logic_unsigned.all;
entity chenliang5s is
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(clk'event 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_11.all;
use ieee.std_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 downto 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(clk'event 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
vcd10n<="0011";
elsif(en1='1')then
if(clk'event 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;
end process;
end t35_arc;
2.3.2、仿真图形:
2.4、25秒倒计时计数器模块
2.4.1、源程序:
library ieee;
use ieee.std_logic_11.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 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(clk'event 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
vcd10n<="0010";
elsif(en3='1')then
if(clk'event 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
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_11.all;
use ieee.std_logic_unsigned.all;
entity chenliang40s is
port(clk:in std_logic;
cr:in std_logic; 图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
if(cr='0') then
bcd1n<="0000";
elsif(en4='1')then
if(clk'event 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
if(clk'event 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_logic_11.all;
use ieee.std_logic_unsigned.all;
entity chenliang20s is
port(clk:in std_logic;
en5:in std_logic; 图2-7 20秒倒计时模块
end chenliang20s;
architecture t20_arc of chenliang20s is
signal bcd1n: std_logic_vector(3 downto 0);
signal vcd10n: std_logic_vector(3 downto 0);
begin
process(clk,cr)
begin
end process;
q1<=bcd1n;
y10<=vcd10n;
process(clk,cr)
begin
if(cr='0') then
vcd10n<="0010";
elsif(en5='1')then
if(clk'event and clk='1') then
end if;
end process;
process(bcd1n,vcd10n)
end process;
end t25_arc;
2.6.2、仿真图形:
2.7、A方向控制模块
2.7.1、源程序:
library ieee;
use ieee.std_logic_11.all;
entity chenliangc1 is
port( clk: in std_logic;
e图2-8 A方向控制模块
architecture c1_arc of chenliangc1 is
signal state:state_space;
begin
process(clk)
begin
end process;
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_11.all;
entity chenliangc2 is
port( clk: in std_logic;
reset:in std_logic );
end chenliangc2;
architecture c2_arc of chenliangc2 is
图2-9 B方向控制模块
process(clk)
begin
case state is
end process;
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_11.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);
clk:in std_logic; sg:out std_logic_vector(6 downto 0);
end chenliangdisp;
architecture disp_arc of chenliangdisp is
signal cn1 :integer range 0 to 2 ;图2-11 显示模块
begin
p1:process(cn)
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<=2;end if;
end process p1;
p2: process(a)
end process p2;
p3:process(clk)
end if;
end process p3;
end disp_arc;
2.10、顶层文件的编写
将以上各个单元模块仿真成功后,再进行顶层文件的编写。将各个单元模块的变量赋值给顶层文件,从而将各个单元模块连接起来,统一调配。得到顶层文件的实体模块:
2.10.1源程序:
library ieee;
use ieee.std_logic_11.all;
use ieee.std_logic_unsigned.all;
entity chenliangtop is
end;
architecture top_arc of chenliangtop is
c图 2-12 顶层实体
end component;
component chenliang35s
end component;
component chenliang5s
end component;
component chenliang25s
end component;
component chenliang403s
port(clk:in std_logic;
end component;
component chenliang20s
end component;
component chenliangc1
port( clk: in std_logic;
end component;
component chenliangc2
port( clk: in std_logic;
end component;
component chenliangdisp
port( b1,b2,b3,b4,b5,b6:in std_logic;
end component;
signal a,b,a1,a2,a3,d1,d2,d3,e1,e2,e3,f1,f2,f3,g1,g2,g3,h1,h2,h3:std_logic;
signal a4,a5,d4,e4,e5,f4,f5,g4,g5,h4:std_logic_vector(3 downto 0);
begin
u1: chenliang35s port map(clk=>a,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(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);
U10:chenliangfen port map(clk=>b,clk1=>a);
end top_arc;
2.11. 总电路图
第三章 调试
3.1、硬件实验
将程序进行编译后,把管脚绑定后把程序下载到实验箱上进行调试。
管脚绑定如下:
CLK0绑定时钟50MHZ;rest绑定DK4
Rb绑定LED6;--支干道红灯;Yb绑定LED7;--支干道黄灯
Gb绑定LED8;--支干道绿灯;Ra绑定LED1;--主干道红灯
Ya绑定LED2;--主干道黄灯;Ga绑定LED3;--主干道绿灯
S_G[0]绑定G8;S_G[1]绑定F8;S_G[2]绑定E8;
S_G[3]绑定D8;S_GG[4]绑定C8;S_G[5]绑定B8;S_G[6]绑定A8;
3.2、实验现象
主干道亮绿灯,支干道亮红灯,主干道数码管显示35S,支干道数码管显示40S,主干道倒计时结束,黄灯5S过渡到红灯,红灯时数码管显示25S,而支干道LED亮绿灯同时数码管显示20S,20S 后,同样 黄灯5S 过渡到红灯。当给DK8一个高电平时,回到初始状态即主干道绿灯,支干道红灯。
心得体会
两周的课程设计已经接近尾声。在这两周里通过老师的指导,以及和同学的讨论,自己的收获颇多,
在课程设计以前自己也在开始重新学习EDA这门课程,当老师安排选择设计题目时,就不假思索的选择了十字路口交通灯的设计,也是为了让自己进一步学习VHDL语言、EDA仿真软件的应用等知识,事实证明将理论知识和实际联系起来,让我学习的更系统、更透彻。
刚拿到题目的时候我和同组同学都不知从哪里寻找突破口,在老师的指导下,和同学一起查找资料,最终找到了设计思路。开始着手对各个模块进行程序编写,开始查找大量参考资料,但还是遇到了很多困难。有些模块的流程,想的很清楚,但却不知道该怎么用VHDL语言去实现,这就需要我重新对VHDL语言进行更深层次的学习。但在和同学积极的讨论下,互相学习,最后这些问题都得到了很好的解决。
在用QuartusII对各个模块进行时序仿真时也遇到了困难,开始时不知道如何去进行仿真,后来才找到原因是没有对各个模块建立工程才导致不能进行仿真。同时也遇到了诸如波形仿真中的仿真时间,周期,以及信号的输入等问题,在和同学的讨论下都得到了解决。最后在进行顶层文件的编写与硬件调试时都遇到了很多问题,但最后都得到了很好的解决。
这次的课程设计最大的收获是让我更加系统的学习了VHDL语言以及QuartuaII软件的使用。在精神层次方面,让我认识到了要成功的做好一件事需要锲而不舍的精神,在遇到问题时要找出问题所在处,继而找到解决问题的办法。这次课程设计也锻炼了自己的团队意识,对于一个即将面临角色转换的我在这两周的收获都有其价值所在。
参考文献
1. 康华光主编.电子技术基础(数字部分),高等教育出版社。
2. 阎石主编. 电子技术基础(数字部分),清华大学出版社。
3. 陈大钦主编,电子技术基础实验,高等教育出版社。
4. 彭介华主编,电子技术课程设计指导,高等教育出版社。
5. 张 原编著,可编程逻辑器件设计及应用,机械工业出版社。
6.荀殿栋,徐志军编著,数字电路设计实用手册,电子工业出版社。
7. MAX+PLUSⅡ入门
8.刘洪喜,陆颖编著. VHDL电路设计实用教程 清华大学出版社
电气与信息工程系课程设计评分表
| 项 目 | 评 价 |
| 设计方案的合理性与创造性 | |
| 硬件制作或软件编程完成情况* | |
| 硬件制作测试或软件调试结果* | |
| 设计说明书质量 | |
| 设计图纸质量 | |
| 答辩汇报的条理性和独特见解 | |
| 答辩中对所提问题的回答情况 | |
| 完成任务情况 | |
| 工作能力 | |
| 组织纪律性(出勤率) | |
| 综合评分 |
日 期:________________
注:表中标*号项目是硬件制作或软件编程类课题必填内容;
此表装订在课程设计说明书的最后一页。课程设计说明书装订顺序:封面、任务书、目录、正文、评分表、附件(非16K大小的图纸及程序清单)。
