资源描述
交通灯设计实验
班 级: 072093
组 员:许文祥20091003791
聂俊杰20091003886
史训意20091001965
指导老师: 王院生
2011 年 12 月 27 日
交通灯设计实验
一、实验目的
1、了解交通灯的亮灭规律。
2、了解交通灯控制器的工作原理。
3、进一步熟悉VHDL语言编程,了解实际设计中的优化方案。
二、实验原理及内容
实验原理
交通灯的显示有很多方式,如十字路口、丁字路口等,而对于同一个路口又有很多不同的显示要求,比如十字路口,车子如果只要东西和南北方向通行就很简单,而如果车子可以左右转弯的通行就比较复杂,本实验仅针对最简单的南北和东西直行的情况。
要完成本实验,首先必须了解交通路灯的亮灭规律。依人们的交通常规,“红灯停,绿灯行,黄灯提醒”。其交通灯的亮灭规律为:初始态是两个路口的红灯全亮,之后东西路口的绿灯亮,南北路口的红灯亮,东西方向通车,延时一段时间后,东西路口绿灯灭,黄灯开始闪烁。闪烁若干次后,东西路口红灯亮,而同时南北路口的绿灯亮,南北方向开始通车,延时一段时间后,南北路口的绿灯灭,黄灯开始闪烁。闪烁若干次后,再切换到东西路口方向,重复上述过程。
三.实验内容
1、用VHDL的方式编写一个简单的交通控制灯电路
2、对所编写的电路进行编译及正确的仿真。
程序:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity traffic is
port(clk,enb : in std_logic;
ared,agreen,ayellow,bred,bgreen,byellow : buffer std_logic;
acounth,acountl,bcounth,bcountl : buffer std_logic_vector(3 downto 0));
end traffic;
architecture one of traffic is
begin
process(clk,enb)
variable lightstatus : std_logic_vector(5 downto 0);
begin
if(clk'event and clk='1')then
lightstatus := ared&agreen&ayellow&bred&bgreen&byellow;
if((acounth="0000" and acountl="0000")or(bcounth="0000" and bcountl="0000"))then
Case lightstatus is
When "010100"=>
lightstatus:="001100";acountl<="0101";acounth<="0000";bcountl<="0101";bcounth<="0000";
When "001100"=>
if(enb='1')then
lightstatus:="100010";acountl<="0000";acounth<="0011";bcountl<="0101";bcounth<="0010";
else
lightstatus:="010100";acountl<="0101";acounth<="0100";bcountl<="0000";bcounth<="0101";
end if;
when "100010"=>
lightstatus:="100001";acountl<="0101";acounth<="0000";bcountl<="0101";bcounth<="0000";
when "100001"=>
lightstatus:="010100";acountl<="0101";acounth<="0100";bcountl<="0000";bcounth<="0101";
when others=>
lightstatus:="010100";acountl<="0101";acounth<="0100";bcountl<="0000";bcounth<="0101";
end case;
else
if(acountl="0000")then
acounth<=acounth-1;
acountl<="1001";
else
acountl<=acountl-1;
end if;
if(bcountl="0000")then
bcounth<=bcounth-1;
bcountl<="1001";
else
bcountl<=bcountl-1;
end if;
end if;
end if;
ared<=lightstatus(5);agreen<=lightstatus(4);ayellow<=lightstatus(3);
bred<=lightstatus(2);bgreen<=lightstatus(1);byellow<=lightstatus(0);
end process;
end one;
四、RTL图形
五、时序仿真及结果分析
分析:
这里a代表东西方向,b代表南北方向,acounth是表示东西方向五进制计数acountl是东西方向六进制计数,bcounth则表示南北方向五进制,bounthl则是南北方向六进制计数
东西方向为0时,东西方向红灯亮(ared=1)
东西方向在1~4之间,东西方向绿灯亮(即agreen=1)南北方向的红灯亮起(即bred=1)
六、实验总结
此设计问题可分为主控电路,译码驱动电路和扫描显示部分。
但是,这远远不能满足实际生活的需要,还应设置倒计时秒数,因此可在此电路基础上外加一个定时模块,这样才能使得设计更完善。
展开阅读全文