FPGA实验报告交通灯控制器设计.docx
- 文档编号:6877281
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:20
- 大小:137.51KB
FPGA实验报告交通灯控制器设计.docx
《FPGA实验报告交通灯控制器设计.docx》由会员分享,可在线阅读,更多相关《FPGA实验报告交通灯控制器设计.docx(20页珍藏版)》请在冰豆网上搜索。
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:
inSTD_LOGIC;----50mhz时钟
reset:
inSTD_LOGIC:
='0';--复位
sensor:
instd_logic:
='0';---特殊情况时,两边都是红灯
up:
instd_logic:
='0';---有效时调整时间时增大时间
down:
instd_logic:
='0';---有效时调整时间时减少时间
choose:
instd_logic:
='0';---选择调整哪一个时间
control:
instd_logic:
='0';---有效时可以暂停,调整时间
LCD_RS:
outSTD_LOGIC;
LCD_RW:
outSTD_LOGIC;
LCD_EN:
outSTD_LOGIC;
redax,greenax,greenay:
outstd_logic;--主干道的红灯和两个绿灯,greenay为左转灯
redbx,greenbx,greenby:
outstd_logic;--支干道的红灯和两个绿灯,greenby为左转灯
data:
outSTD_LOGIC_VECTOR(3downto0));--Lcd显示
typeistateis(
write_instr,
write_dataup4,
write_datadown4,
set_addrup,
set_addrdown,
ret_homeup,
ret_homedown
);
signalstate:
istate;
signalt_clk,clk500:
std_logic;---分别为1hz,500hz
signalt:
integerrange0to15:
=0;
signaltnumh,cntnuml:
integerrange0to9;--输入到数码管的数字
signalcountnum:
integer;---计数器
signalreda,greena,greena1,redb,greenb,greenb1:
std_logic;--各交通灯对应的信?
signalt:
integerrange0to99;---要输入lcd中的数字
d)基本模块设计:
1)字符译码函数
functionputc(data:
character)returnstd_logic_vectoris
---字符译码函数,将字符显示在lcd上
variableresult:
std_logic_vector(7downto0);
begin
casedatais
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);
whenothers=>result:
=conv_std_logic_vector(32,8);
endcase;
returnresult;
endputc;
2)数字译码函数
functionputn(num:
inintegerrange0to9)returnstd_logic_vectoris
---数字译码函数,将数字显示在lcd上
variablefig:
std_logic_vector(7downto0);
begin
casenumis
when0=>fig:
="00110000";
when1=>fig:
="00110001";
when2=>fig:
="00110010";
when3=>fig:
="00110011";
when4=>fig:
="00110100";
when5=>fig:
="00110101";
when6=>fig:
="00110110";
when7=>fig:
="00110111";
when8=>fig:
="00111000";
when9=>fig:
="00111001";
endcase;
returnfig;
endputn;
3)分频,由50Mhz得到500hz,驱动lcd
process(LCD_Clk)
----分频,得到500hz时钟
variablen3:
integerrange0to49999;
begin
ifrising_edge(LCD_Clk)then
ifn3<49999then
n3:
=n3+1;
else
n3:
=0;
clk500<=notclk500;
endif;
endif;
endprocess;
4)分频,由500hz得到1hz,作为交通灯控制器输入
process(clk500)
----分频,得到1hz时钟
variablen:
integerrange0to249;
begin
ifrising_edge(clk500)then
ifn<249then
n:
=n+1;
else
n:
=0;
cnt_clk<=nott_clk;
endif;
endif;
endprocess;
5)主要功能实现:
process(cnt_clk,reset,choose,up,down,control,t)
---实现各种要求功能,包括倒计时显示,红绿灯(含左转灯)转换,以及转换时间调整
variablem:
integerrange0to4;---m表示转换的是哪一个时间(t0-t4中哪一个)
variablecount:
naturalrange0to99;---计数器,将正计数转换为倒计数
variablet0:
integerrange0to99:
=5;---绿灯闪烁时间
variablet1:
integerrange0to99:
=79;---主干道绿灯亮的时间
variablet2:
integerrange0to99:
=20;---主干道左转灯亮的时间
variablet3:
integerrange0to99:
=20;---支干道绿灯亮的时间
variablet4:
integerrange0to99:
=10;---支干道左转灯亮的时间
begin
ifreset='1'then--1
----复位,计数器清零,m,t0-t4赋初值
countnum<=0;
m:
=0;
t0:
=5;
t1:
=79;
t2:
=20;
t3:
=20;
t4:
=10;
elsifcontrol='1'then--可调节时间或暂停
ifrising_edge(cnt_clk)then--2
ifchoose='1'then–选择t0-t4中的哪一个3
ifm=4then--4
m:
=0;---m在0-4之间循环
else
m:
=m+1;
endif;--4
t<=m;--显示m
else--choose为0时调节所选时间3
ifup='1'then--tx增大--4
ifm=0then--调整t0,即闪烁时间,上限为7s,5
ift0=7then--6
t0:
=5;
else
t0:
=t0+1;
endif;--6
t<=t0;--显示t0
elsifm=1then--调整t1,上限99s
ift1=99then--6
t1:
=79;
else
t1:
=t1+1;
endif;--6
t<=t1;--显示t1
elsifm=2then--调整t2,上限为30s
ift2=30then--6
t2:
=20;
else
t2:
=t2+1;
endif;--6
t<=t2;--显示t2
elsifm=3then--调整t3,上限为30s
ift3=30then--6
t3:
=20;
else
t3:
=t3+1;
endif;--6
t<=t3;--显示t3
elsifm=4then--调整t4,上限为15s
ift4=15then--6
t4:
=10;
else
t4:
=t4+1;
endif;--6
t<=t4;--显示t4
endif;--5
elsifdown='1'then--tx减小4
ifm=0then----调整t0,即闪烁时间,下限为2s,5
ift0=2then--6
t0:
=5;
elset0:
=t0-1;
endif;--6
t<=t0;---显示t0
elsifm=1then----调整t1,下限为39秒
ift1=39then--6
t1:
=79;
elset1:
=t1-1;
endif;--6
t<=t1;--显示t1
elsifm=2then----调整t2,下限为10s
ift2=10then--6
t2:
=20;
elset2:
=t2-1;
endif;--6
t<=t2;---显示t2
elsifm=3then-----调整t3,下限10s
ift3=10then--6
t3:
=20;
elset3:
=t3-1;
endif;--6
t<=t3;---显示t3
elsifm=4then----调整t4,下限8s
ift4=8then--6
t4:
=10;
elset4:
=t4-1;
endif;--6
t<=t4;--显示t4
endif;--5
endif;--4
endif;--3
endif;--2
elsifrising_edge(cnt_clk)then--此时reset=0
ifcountnum=t1+t2+t3+t4then--2记数到整周期时,记数器清零
countnum<=0;
else
countnum<=countnum+1;---计数器小于整周期时,正常记数
endif;--2
ifsensor='1'then--2sensor信号有效期间,表示紧急情况两组路灯都为红灯
reda<='1';
redb<='1';
greena<='0';
greenb<='0';
greena1<='0';
greenb1<='0';
else
ifcountnum<=t1-t0then--3主干道绿灯亮且非闪烁,支干道红灯亮
reda<='0';
greena<='1';
greena1<='0';
redb<='1';
greenb<='0';
greenb1<='0';
elsifcountnum<=t1then--主干道绿灯亮且闪烁,支干道红灯亮
reda<='0';
greena<=notgreena;
greena1<='0';
redb<='1';
greenb<='0';
greenb1<='0';
elsifcountnum<=t1+t2-t0then--主干道左转绿灯亮且非闪烁,支干道红灯亮
reda<='0';
greena<='0';
greena1<='1';
redb<='1';
greenb<='0';
greenb1<='0';
elsif(countnum<=t1+t2)then--主干道左转绿灯亮且闪烁,支干道红亮
reda<='0';
greena<='0';
greena1<=notgreena1;
redb<='1';
greenb<='0';
greenb1<='0';
elsif(countnum<=t1+t2+t3-t0)then--支干道绿灯亮且非闪烁,主干道红灯亮
reda<='1';
greena<='0';
greena1<='0';
redb<='0';
greenb<='1';
greenb1<='0';
elsif(countnum<=t1+t2+t3)then--支干道绿灯亮且闪烁,主干道红灯亮
reda<='1';
greena<='0';
greena1<='0';
redb<='0';
greenb<=notgreenb;
greenb1<='0';
elsif(countnum<=t1+t2+t3+t4-t0)then--支干道左转绿灯亮且非闪烁,主干道红灯亮
reda<='1';
greena<='0';
greena1<='0';
redb<='0';
greenb<='0';
greenb1<='1';
elsif(countnum<=t1+t2+t3+t4)then--支干道左转绿灯亮且闪烁,主干道红灯亮
reda<='1';
greena<='0';
greena1<='0';
redb<='0';
greenb<='0';
greenb1<=notgreenb1;
endif;--3
endif;--2
----下面将正计数转换为倒计数-----
ifcountnum<=t1then--2
count:
=t1-countnum;---主干道绿灯亮,支干道红灯亮时倒计时
elsifcountnum<=t1+t2then---主干道左转绿灯亮,支干道红灯亮时倒计时
count:
=t1+t2-countnum;
elsifcountnum<=t1+t2+t3then----支干道绿灯亮,主干道红灯亮时倒计时
count:
=t1+t2+t3-countnum;
elsifcountnum<=t1+t2+t3+t4then---支干道左转绿灯亮,主干道红灯亮时倒计时
count:
=t1+t2+t3+t4-countnum;
endif;--2
----上面将正计数转换为倒计数----
t<=count;---显示count
endif;--1
-----以下代码为分位译码-----
ift>=90then--1
cntnumh<=9;
cntnuml<=t-90;
elsift>=80then
cntnumh<=8;
cntnuml<=t-80;
elsift>=70then
cntnumh<=7;
cntnuml<=t-70;
elsift>=60then
cntnumh<=6;
cntnuml<=t-60;
elsift>=50then
cntnumh<=5;
cntnuml<=t-50;
elsift>=40then
cntnumh<=4;
cntnuml<=t-40;
elsift>=30then
cntnumh<=3;
cntnuml<=t-30;
elsift>=20then
cntnumh<=2;
cntnuml<=t-20;
elsift>=10then
cntnumh<=1;
cntnuml<=t-10;
else
cntnumh<=0;
cntnuml<=t;
endif;--1
-----以上代码为分位译码-----
---各信号赋给各输出的交通灯
greenax<=greena;----主干绿灯
greenay<=greena1;---主干左转绿灯
greenbx<=greenb;---支干道绿灯
greenby<=greenb1;---支干道左转绿灯
redax<=reda;----主干红灯
redbx<=redb;--支干道绿灯
endprocess;
主要功能仿真如下:
a)、reset为1时,初始化。
为0时,会从79倒计时,主干道绿灯亮,支干道红灯亮,sensor为1时,主干道和支干道都为红灯亮:
b)默认情况下倒计时到最后5S时会闪烁显示,并切换到下一状态,继续倒计时:
c)如果reset=0且control为1时,暂停计数,此时若choose为1,则会在0-4之间循环计数,选择调节哪一个时间(t0-t4),若choose改为0,就会暂停计数:
d)此时(reset=0,control=1,choose=0)若选择down=1或up=1,则会减计数(默认值到最小值循环)或加计数(默认值到最大值循环)调整当前选中的时间t:
(当前选的t0,闪烁时间,最后调整为7s)
e)若将control置于0,则会接着倒计时,就像最初初始化时,但此时调整后的时间生效(这里闪烁时间改为7s):
6)显示
process(clk500,reset)
------lcd上显示数字和字符
begin
ifreset='1'then---复位时不显示
state<=write_instr;
LCD_RS<='0';
cnt<=0;
elsifrising_edge(clk500)then---显示数字或字符
casestateis
whenwrite_instr=>
LCD_RS<='0';
casetis
when0=>data<="0011";
when1=>data<="0011";
when2=>data<="0011";
when3=>data<="0010";
when4=>data<="0010";
when5=>data<="1000";
when6=>data<="0000";
when7=>data<="0110";
when8=>data<="0000";
when9=>data<="110
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- FPGA 实验 报告 交通灯 控制器 设计