FPGA实验报告-交通灯控制器设计
-
FPGA实验报告
--交通灯控制器设计
院系:电子与信息工程系
专业:通信工程
班级:
姓名:
学号:
指导教师:
一、实验任务 1、任务名称:交通灯控制器的设计
2、设计容与要求:
① 设计一个十字路口交通信号灯的定时控制电路。要求红、绿灯按一定的规律亮和灭,并在亮灯期间进行倒计时,并将运行时间用数码管/液晶显示出来。
② 绿灯亮时,为该车道允许通行信号,红灯亮时,为该车道禁止通行信号。要求主干道每次通行时间为99秒,支干道每次通行时间为30秒。每次变换运行车道前绿灯闪烁,持续时间为5秒。即车道要由主干道转换为支干道时,主干道在通行时间只剩下5秒钟时,绿灯闪烁显示,支干道仍为红灯,以便主干道上已过停车线的车继续通行,未过停车线的车停止通行。同理,当车道由支干道转换为主干道时,支干道绿灯闪烁显示5秒钟,主干道仍为红灯。
③ 对红、绿灯的运行时间要能比较方便的进行重新设置。 ④ 对器件进行在系统编程和实验验证。
⑤ 用VHDL 语言对设计进行描述,设计一个测试方案,通过ISE 对设计进行仿真验证。并能够下载到实验板上调试成功。
6 写出设计性实验报告,并打印各层次的源文件和仿真波形,然后作简要说明。
2、补充功能与要求:
1.在主干道和支干道添加左转向灯;
2.各灯亮的时间及最后闪烁时间可调节;
3.紧急路况时,主干道和支干道都为红灯。
二、实验环境
1、ISE 软件一套;
2、PC 机一台。
三、设计思路
1、根据题目要求,知道整个交通灯的运行过程是周期的,所以可以设计一个总的计数器,满周期则清零;
2、将灯闪烁时间、主干道绿灯亮的时间、主干道转向灯亮的时间、支干道绿灯亮的时
间、支干道转向灯亮的时间分别记为变量t0、t1、t2、t3、t4,通过调整它们,实现调节各灯亮的时间;
3、将所有需要显示的量由同一个信号表示并最终输出、显示在LCD上。
四、系统设计
a)系统框图
b)状态转换说明:主干道和支干道永远有且只有一个灯亮,紧急路况时两边红灯亮,其余时候有且只有一个红灯亮;主干道绿灯、主干道转向灯亮、支干道绿灯、支干道
转向灯依次亮,在最后t0S(默认为5S)闪烁。
c)输入输出及信号设计:
Port ( LCD_Clk : in STD_LOGIC;----50mhz时钟
reset : in STD_LOGIC:='0';--复位
sensor:in std_logic :='0';---特殊情况时,两边都是红灯
up:in std_logic :='0' ;---有效时调整时间时增大时间
down:in std_logic :='0';---有效时调整时间时减少时间
choose:in std_logic :='0';---选择调整哪一个时间
control:in std_logic :='0';---有效时可以暂停,调整时间
LCD_RS : out STD_LOGIC;
LCD_RW : out STD_LOGIC;
LCD_EN : out STD_LOGIC;
redax,greenax ,greenay:out std_logic;--主干道的红灯和两个绿灯,greenay为左转灯
redbx,greenbx ,greenby:out std_logic;--支干道的红灯和两个绿灯,greenby为
左转灯
data : out STD_LOGIC_VECTOR (3 downto 0)); --Lcd显示
type istate is(
write_instr,
write_dataup4,
write_datadown4,
set_addrup,
set_addrdown,
ret_homeup,
ret_homedown
);
signal state:istate;
signalt_clk,clk500:std_logic;---分别为1hz,500hz
signalt:integer range 0 to 15:=0;
signaltnumh,cntnuml:integer range 0 to 9;--输入到数码管的数字
signal countnum:integer ;---计数器
signal reda,greena,greena1,redb,greenb,greenb1:std_logic;--各交通灯对应的信? signal t:integer range 0 to 99;---要输入lcd中的数字
d)基本模块设计:
1)字符译码函数
function putc(data:character) return std_logic_vector is
---字符译码函数,将字符显示在lcd上
variable result:std_logic_vector(7 downto 0);
begin
case data is
when 'o'=> result:=conv_std_logic_vector(111,8);
when 'u'=> result:=conv_std_logic_vector(117,8);
when 'C'=> result:=conv_std_logic_vector(67,8);
when 'n'=> result:=conv_std_logic_vector(110,8);
when 't'=> result:=conv_std_logic_vector(116,8);
when 'e'=> result:=conv_std_logic_vector(101,8);
when 'r'=> result:=conv_std_logic_vector(114,8);
when ':'=> result:=conv_std_logic_vector(58,8);
when others => result:=conv_std_logic_vector(32,8);
end case;
return result;
end putc;
2)数字译码函数
function putn(num:in integer range 0 to 9) return std_logic_vector is
---数字译码函数,将数字显示在lcd上
variable fig:std_logic_vector(7 downto 0);
begin
case num is
when 0=> fig:="00110000";
when 1=> fig:="00110001";
when 2=> fig:="00110010";
when 3=> fig:="00110011";
when 4=> fig:="00110100";
when 5=> fig:="00110101";
when 6=> fig:="00110110";
when 7=> fig:="00110111";
when 8=> fig:="00111000";
when 9=> fig:="00111001";
end case;
return fig;
end putn;
3)分频,由50Mhz得到500hz,驱动lcd
process(LCD_Clk)
----分频,得到500hz时钟
variable n3:integer range 0 to 49999;
begin
if rising_edge(LCD_Clk) then
if n3<49999 then
n3:=n3+1;
else
n3:=0;
clk500<=not clk500;
end if;
end if;
end process;
4)分频,由500hz得到1hz,作为交通灯控制器输入
process(clk500)
----分频,得到1hz时钟
variable n:integer range 0 to 249;
begin
if rising_edge(clk500) then
if n<249 then
n:=n+1;
else
n:=0;
cnt_clk<=nott_clk;
end if;
end if;
end process;
5)主要功能实现:
process(cnt_clk,reset,choose,up,down,control,t)
---实现各种要求功能,包括倒计时显示,红绿灯(含左转灯)转换,以及转换时间调整
variable m:integer range 0 to 4 ;---m表示转换的是哪一个时间(t0-t4中哪一个)
variable count : natural range 0 to 99;---计数器,将正计数转换为倒计数variable t0:integer range 0 to 99 :=5;---绿灯闪烁时间
variable t1:integer range 0 to 99 :=79;---主干道绿灯亮的时间
variable t2:integer range 0 to 99 :=20;---主干道左转灯亮的时间
variable t3:integer range 0 to 99:=20;---支干道绿灯亮的时间
variable t4:integer range 0 to 99:=10;---支干道左转灯亮的时间
begin
if reset='1' then --1
----复位,计数器清零,m,t0-t4赋初值
countnum<=0;
m:=0;
t0:=5;
t1:=79;
t2:=20;
t3:=20;
t4:=10;
elsif control='1' then--可调节时间或暂停
if rising_edge(cnt_clk) then --2
if choose ='1' then –选择t0-t4中的哪一个 3
if m=4 then --4
m:=0;---m在0-4之间循环
else
m:=m+1;
end if; --4
t<=m;--显示m
else --choose为0时调节所选时间3
if up='1' then --tx增大--4