十字路口交通灯控制器设计报告
- 格式:docx
- 大小:126.94 KB
- 文档页数:12
十字路口交通灯控制器设计报告
姓名:***
学号:************
班级:计122-2
指导教师:***
一、设计要求
在十字路口,每条道路上各有一组红、黄、绿灯和倒计时显示器,用以指挥车辆和行人有序的通行。
二、系统功能描述
1、在十字路口的两个方向上各设一组红黄绿灯。
2、每个方向上设计一组数码管,以倒计时的方式显示允许通行和禁止的时间。
可以自设时
间。
3、允许当特殊情况出现时,比如紧急状态,各方向上均是红灯亮,且数字在闪烁,或者模
拟夜间黄灯闪烁。
4、其他功能自加。
四、各模块具体设计
1、模块corner a与b即东西方向与南北方向道路主控制器,其中用type分别列举各个显示灯,并分配起始状态。
在每个灯的状态中分别用if语句写出灯亮时的时间高低位转换过程,当时间倒计时为零时,定义好下一个状态。
最后转化成的模块和仿真如下图所示:
clk r
g
y
l
timh[3..0]
timl[3..0] cornera
inst
clk r
g
y
l
timh[3..0]
timl[3..0] cornerb
inst1
2、模块sel如下图,该模块主要功能是产生对数码管的片选信号。
clk sell[2..0]
sel
inst
3、模块xuan主要是将不同数码管要显示的数据在与片选信号相同的时间送到端口。
sel[2..0] d0[3..0] d1[3..0] d2[3..0] d3[3..0]q[3..0]
xuan
inst
4、模块qiduan主要是将十进制数转换为七段数码管需要的数据。
d[3..0]q0
q1
q2
q3
q4
q5
q6
qiduan
inst1
5、整体仿真如下图所示:
6、包装好的模块如下图所示:
VCC clk1
INPUT VCC clk2INPUT VCC clk3
INPUT VCC
no
INPUT q0OUTPUT r2
OUTPUT
q1OUTPUT r1OUTPUT q2
OUTPUT
y 2OUTPUT q3
OUTPUT
g2OUTPUT q4OUTPUT y 1OUTPUT
q5OUTPUT g1
OUTPUT
q6
OUTPUT sel[1]OUTPUT sel[0]
OUTPUT
clk1clk2clk3no
sel[2..0]
q0r2q1r1q2y2q3g2q4y1q5g1q6
Block1
inst
sel[2..0]
P IN_13P IN_14P IN_15
P IN_16P IN_19P IN_20P IN_21P IN_69PIN_70P IN_71
P IN_56P IN_57P IN_63PIN_68P IN_6PIN_7P IN_9P IN_58P IN_61P IN_62
五、各个模块程序
1、分频fen
library ieee;
use ieee.std_logic_1164.all;
entity fen is
port(clk:in std_logic;
clk1:out std_logic);
end fen;
architecture fen_arc of fen is
begin
process(clk)
variable cnt:integer range 0 to 5;
begin
if clk'event and clk='1' then
if cnt=5 then
cnt:=0;
clk1<='1';
else
cnt:=cnt+1;
clk1<='0';
end if;
end if;
end process;
end fen_arc;
2、消抖xiaodou
library ieee;
use ieee.std_logic_1164.all;
entity xiaodou is
port(a,clk1:in std_logic;
b:out std_logic);
end xiaodou;
architecture xiao_arc of xiaodou is
signal tmp1:std_logic;
begin
process(clk1,a)
variable tmp3,tmp2:std_logic;
begin
if clk1'event and clk1='0' then
tmp1<=a;
tmp2:=tmp1;
end if;
b<=tmp1 and clk1;
end process;
end xiao_arc;
3、紧急按钮no
library ieee;
use ieee.std_logic_1164.all;
entity no is
port(a:in std_logic;
y:out std_logic);
end no;
architecture no_arc of no is
begin
process(a)
variable aa:std_logic;
begin
if a'event and a='1' then
aa:=not aa;
end if;
y<=aa;
end process;
end no_arc;
4、东西方向道路控制cornera
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity cornera is
port(clk:in std_logic;
r,g,y,l:out std_logic;
timh,timl:out std_logic_vector(3 downto 0));
end cornera;
architecture corn_arc of cornera is
type rgyl is(red,yellow,green,guai);
begin
process(clk)
variable a:std_logic;
variable th,tl:std_logic_vector(3 downto 0); variable state:rgyl;
begin
if clk'event and clk='1' then
case state is
when green=>if a='0' then
th:="0001";
tl:="1001";
a:='1';
g<='1';
r<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";
a:='0';
state:=yellow;
end if;
end if;
when red=>if a='0' then
th:="0010";
tl:="1001";
a:='1';
r<='1';
l<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
tl:="0000";
a:='0';
state:=green;
end if;
end if;
when yellow=>if a='0' then
th:="0000";
tl:="0100";
a:='1';
y<='1';
g<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";
a:='0';
state:=guai;
end if;
end if;
when guai=>if a='0' then
th:="0000";
tl:="0100";
a:='1';
l<='1';
y<='0';
else
if not(th="0000" and tl="0001") then
if tl="0000" then
tl:="1001";
th:=th-1;
else
tl:=tl-1;
end if;
else
th:="0000";
tl:="0000";
state:=red;
end if;
end if;
end case;
end if;
timh<=th;
timl<=tl;
end process;
end corn_arc;
5、南北方向与东西方向只是初始状态不同,东西初始状态为红灯,
南北初始状态为绿灯,其他都一样。
6、数码管片选信号sel
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity sel is
port(clk:in std_logic;
sell:out std_logic_vector(2 downto 0));
end sel;
architecture sel_arc of sel is
begin
process(clk)
variable tmp:std_logic_vector(2 downto 0);
begin
if clk'event and clk='1' then
if tmp="000" then
tmp:="001";
elsif tmp="001" then
tmp:="100";
elsif tmp="100" then
tmp:="101";
elsif tmp="101" then
tmp:="000";
end if;
end if;
sell<=tmp;
end process;
end sel_arc;
7、数码管显示数据与片选信号相同时间送到端口xuan
library ieee;
use ieee.std_logic_1164.all;
entity xuan is
port(sel:in std_logic_vector(2 downto 0);
d0,d1,d2,d3:in std_logic_vector(3 downto 0);
q:out std_logic_vector(3 downto 0));
end xuan;
architecture xua_arc of xuan is
begin
process(sel)
begin
case sel is
when "100"=>q<=d3;
when "101"=>q<=d2;
when "000"=>q<=d1;
when others=>q<=d0;
end case;
end process;
end xua_arc;
8、七段数码管显示qiduan
library ieee;
use ieee.std_logic_1164.all;
entity qiduan is
port(d:in std_logic_vector(3 downto 0);
q0,q1,q2,q3,q4,q5,q6:out std_logic);
end qiduan;
architecture qidua_arc of qiduan is
begin
process(d)
variable q:std_logic_vector(6 downto 0);
begin
case d is
when"0000"=>q:="0111111";
when"0001"=>q:="0000110";
when"0010"=>q:="1011011";
when"0011"=>q:="1001111";
when"0100"=>q:="1100110";
when"0101"=>q:="1101101";
when"0110"=>q:="1111101";
when"0111"=>q:="0100111";
when"1000"=>q:="1111111";
when others=>q:="1101111";
end case;
q0<=q(0);
q1<=q(1);
q2<=q(2);
q3<=q(3);
q4<=q(4);
q5<=q(5);
q6<=q(6);
end process;
end qidua_arc;
六、总结、心得
通过这次课程设计,我进一步加深了对数字电子技术的了解。
并进一步熟练了对QuartusII软件的操作。
在编写程序的过程中,遇到了很多问题,其中在红灯闪烁和紧急按钮的设计上想了很久,也遇到了许多问题,一直达不到我想要的结果,使我发现自己以前学习上存在的不足。
通过与同学探讨和请教老师,终于把问题都解决了,并加深了对十字路口交通灯原理和设计思路的了解。
同时也掌握了做课程设计的一般流程,为以后的设计积累了一定的经验。
做课程设计时,先查阅相关知识,把原理吃透,确定一个大的设计方向,在按照这个方向分模块的把要实现的功能用流程图的形式展示。
最后参照每个模块把输入和输出引脚设定,运用我们所学的VHDL语言进行编程。
通过这次设计,我对于VHDL有了更加深刻的理解,在一定程度上训练了自己的思考能力,也提高了实际操作能力。
感谢老师专业的辅导和同学的帮助,使我顺利完成课程设计。