基于VHDL的交通灯设计与实现.docx

上传人:b****5 文档编号:7435051 上传时间:2023-01-23 格式:DOCX 页数:27 大小:326.03KB
下载 相关 举报
基于VHDL的交通灯设计与实现.docx_第1页
第1页 / 共27页
基于VHDL的交通灯设计与实现.docx_第2页
第2页 / 共27页
基于VHDL的交通灯设计与实现.docx_第3页
第3页 / 共27页
基于VHDL的交通灯设计与实现.docx_第4页
第4页 / 共27页
基于VHDL的交通灯设计与实现.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

基于VHDL的交通灯设计与实现.docx

《基于VHDL的交通灯设计与实现.docx》由会员分享,可在线阅读,更多相关《基于VHDL的交通灯设计与实现.docx(27页珍藏版)》请在冰豆网上搜索。

基于VHDL的交通灯设计与实现.docx

基于VHDL的交通灯设计与实现

华中科技大学

基于xilinxFPGA的VHDL交通灯操纵器的设计

--基于Spartan3E开发板

专业:

电子信息工程

 

一.任务设计要求

  ①设计一个十字路口交通信号灯的按时操纵电路。

要求红、绿灯按必然的规律亮和灭,并在亮灯期间进行倒计时,并将运行时刻用数码管/液晶显示出来。

  ②绿灯亮时,为该车道许诺通行信号,红灯亮时,为该车道禁止通行信号。

要求骨干道每次通行时刻为99秒,支干道每次通行时刻为30秒。

每次变换运行车道前绿灯闪烁,持续时刻为5秒。

即车道要由骨干道转换为支干道时,骨干道在通行时刻只剩下5秒钟时,绿灯闪烁显示,支干道仍为红灯,以便骨干道上已过停车线的车继续通行,未过停车线的车停止通行。

同理,当车道由支干道转换为骨干道时,支干道绿灯闪烁显示5秒钟,骨干道仍为红灯。

③对红、绿灯的运行时刻要能比较方便的进行从头设置。

④对器件进行在系统编程和实验验证。

⑤用VHDL语言对设计进行描述,设计一个测试方案,通过ISE对设计进行仿真验证。

并能够下载到实验板上调试成功。

任务扩展:

在原设计的基础上加入指示方向的功能。

二.系统设计

1.系统原理图与说明

由系统设计原理图,我以清楚地将系统分为六个模块:

分频模块,时刻设置模块,状态转换模块,时刻计算模块,LED流水灯模块,LCD显示模块。

1)分频模块

分频模块其作用为:

由于Spartan3E板上提供的时钟信号为50MHz,而设计所需时钟信号为1Hz,故利用分频模块将50MHz信号分频为1Hz信号。

2)时刻置数模块

由于任务设计要求能够对骨干道,支干道上左转、绿灯运行的时刻进行从头设置调整,因此要对系统进行参数化设计。

第一引入一组参数,main_gh,main_gl,main_lh,main_ll,branch_gh,branch_gl,branch_lh,branch_ll(下划线后面的字母别离取green,left,high,low首字母).需要置数时,第一选择对骨干道仍是支干道时刻置数,那个地址设置一个main_or_branch参数,当main_or_branch为高时设置支干道时刻,为低时设置骨干道时刻。

置数时,通过s_set_button,l_set_button对时刻进行设置,具体方式参见代码。

为了置数方便,引入一个add_or_decent参数,低电平常按下button能够增计数,高电平常按下能够减计数。

3)状态转换模块

状态转化模块是整个系统的核心模块它操纵整个交通灯系统的状态转变,整个进程划分为四个大体状态:

骨干道绿灯、骨干道左转、支干道绿灯、支干道左转,用state、s_or_l为00、0一、10、11来代表。

每当一个状态的计数器为00时,state、s_or_l发生改变,以实现状态间的转换,进而操纵交通灯的转变。

4)时刻计算模块

这次设计中扩展了左转向的功能,因此红灯时刻不单单是另一干道的直行时刻,而是直行时刻和左转时刻之和。

5)LCD显示模块

Spartan3E板上只有LCD显示模块,因此采纳此模块显示当前亮灯的剩余时刻和设置时刻模块的时刻显示。

通过输入counterplay_1l,counterplay_1h,counterplay_2l,counterplay_2h四位二进制数,加上0011显示成十进制数,别离代表两位数的低位和高位

6)LED显示模块

由输入信号state、s_or_l、flash,别离取000,001,010,011,100,101,110,111所取得的main_green,main_left,main_red,branch_left,

branch_green,branch_red的不同值,来操纵骨干道,支干道红绿左转灯的亮灭。

其中1表示亮,0表示灭。

如表3-1所示。

由上表可取得:

main_green<=NOT(state)ANDNOT(s_or_l)AND(NOT((flashANDclk)));

main_left<=NOT(state)ANDs_or_lAND(NOT((flashANDclk)));

main_red<=state;

branch_green<=stateANDNOT(s_or_l)AND(NOT((flashANDclk)));

branch_left<=stateANDs_or_lAND(NOT((flashANDclk)));

branch_red<=NOT(state);

2.输入输出设计

任务设计开发板基于Spartan3E板,具体输入输出设定如下:

1)输入:

开关:

main_or_branch:

设置骨干道仍是支干道

EN:

使能信号

run_or_set:

设置运行模式还是时间设置模式

add_or_decent:

置数模式:

增加或者减少

按键:

s_set_button:

直行时间设置按键

l_set_button:

左转时间设置按钮

时钟:

clk

2)输出:

LCD显示屏:

别离显示当前亮灯的剩余秒数

LED灯:

main_green,main_red,main_left

branch_left,branch_green,branch_red

3、状态转换图

S0状态:

骨干道绿灯、支干道红灯

S1状态:

骨干道左转、支干道红灯

S2状态:

支干道绿灯、骨干道红灯

S3状态:

支干道左转、骨干道红灯

 

三.各模块代码和仿真波形

◆分频模块代码

因为1HZ波形太长,不易仿真,故仿真波形采纳100HZ的

输入clk:

50MHZ

输出clk1:

100HZ

◆时刻设置模块部份代码

以上是直行时刻设置代码。

左转设置类似,在此再也不复制

仿真设置

输入:

clk

main_or_branch设置为0

add_or_decent设置为0

s_set_button设置为周期为1周期的信号

l_set_button设置为低电平

波形如下

◆时刻计算模块代码

波形仿真

输入输出与预期相符合。

◆状态转换模块

波形仿真

别离给骨干道,支干道个颜色灯持续时刻赋值,再给定,当前亮灯的剩余时刻,然后又进行仿真,结果符合预期

◆LED模块代码

波形仿真

别离给予输入不同周期的高低点评,彼此叠加的结果符合预期。

◆LCD模块代码

libraryIEEE;

useLCDis

port(clk:

inSTD_LOGIC;

rst_n:

inSTD_LOGIC;

counter_play1h,counter_play1l:

inSTD_LOGIC_VECTOR(3downto0);counter_play2h,counter_play2l:

inSTD_LOGIC_VECTOR(3downto0);

--degree1,degree2:

inSTD_LOGIC_VECTOR(3downto0);

SF_D:

outSTD_LOGIC_VECTOR(3downto0);

LCD_E,LCD_RS,LCD_RW:

outSTD_LOGIC

);

endLCD;

architecturebehaviorofLCDis

typetx_sequenceis(high_setup,high_hold,oneus,low_setup,low_hold,fortyus,done);

signaltx_state:

tx_sequence:

=done;

signaltx_byte:

std_logic_vector(7downto0);

signaltx_init:

std_logic:

='0';

typeinit_sequenceis(idle,fifteenms,one,two,three,four,five,six,seven,eight,done);

signalinit_state:

init_sequence:

=idle;

signalinit_init,init_done:

std_logic:

='0';

signali:

integerrange0to750000:

=0;

signali2:

integerrange0to2000:

=0;

signali3:

integerrange0to82000:

=0;

signalSF_D0,SF_D1:

std_logic_vector(3downto0);

signalLCD_E0,LCD_E1:

std_logic;

signalmux:

std_logic;--?

?

?

?

typedisplay_stateis(init,function_set,entry_set,set_display,clr_display,pause,set_addr,

max_degree_1,max_degree_2,temperature_1,temperature_2,degree_1,degree_2,blank1,blank2,blank3);

signalcur_state:

display_state:

=init;

begin

--LED<=tx_byte;--fordiagnosticpurposes

--SF_CE0<='1';--disableintelstrataflash

LCD_RW<='0';--writeonly

--Thefollowing"with"statementssimplifytheprocessofaddingandremovingstates.

--whentotransmitacommand/dataandwhennotto

withcur_stateselect

tx_init<='0'wheninit|pause,

'1'whenothers;

--controlthebus

withcur_stateselect

mux<='1'wheninit,

'0'whenothers;

--controltheinitializationsequence

withcur_stateselect

init_init<='1'wheninit,

'0'whenothers;

--registerselect

withcur_stateselect

LCD_RS<='0'whenfunction_set|entry_set|set_display|clr_display|set_addr,

'1'whenothers;

--whatbytetotransmittolcd

--refertodatasheetforanexplanationofthesevalues

withcur_stateselect

tx_byte<="00101000"whenfunction_set,--?

?

?

?

?

?

?

"00000110"whenentry_set,

"00001100"whenset_display,

"00000001"whenclr_display,

""whenset_addr,

"0011"&counter_play1hwhenmax_degree_1,

"0011"&counter_play1lwhenmax_degree_2,

"00100000"whenblank1,

"0011"&counter_play2hwhentemperature_1,

"0011"&counter_play2lwhentemperature_2,

"00100000"whenblank2,

"00100000"whendegree_1,

"00100000"whendegree_2,

"00100000"whenblank3,

"00100000"whenothers;

--mainstatemachine

display:

process(clk,rst_n)

begin

if(rst_n='0')then

cur_state<=function_set;

elsif(clk='1'andclk'event)then

casecur_stateis

--refertointializestatemachinebelow

wheninit=>

if(init_done='1')then

cur_state<=function_set;

else

cur_state<=init;

endif;

--everyotherstatebutpauseusesthetransmitstatemachine

whenfunction_set=>

if(i2=2000)then

cur_state<=entry_set;

else

cur_state<=function_set;

endif;

whenentry_set=>

if(i2=2000)then

cur_state<=set_display;

else

cur_state<=entry_set;

endif;

whenset_display=>

if(i2=2000)then

cur_state<=clr_display;

else

cur_state<=set_display;

endif;

whenclr_display=>

i3<=0;

if(i2=2000)then

cur_state<=pause;

else

cur_state<=clr_display;

endif;

whenpause=>

if(i3=82000)then

cur_state<=set_addr;

i3<=0;

else

cur_state<=pause;

i3<=i3+1;

endif;

whenset_addr=>

if(i2=2000)then

cur_state<=max_degree_1;

else

cur_state<=set_addr;

endif;

whenmax_degree_1=>

if(i2=2000)then

cur_state<=max_degree_2;

else

cur_state<=max_degree_1;

endif;

whenmax_degree_2=>

if(i2=2000)then

cur_state<=blank1;

else

cur_state<=max_degree_2;

endif;

whenblank1=>

if(i2=2000)then

cur_state<=temperature_1;

else

cur_state<=blank1;

endif;

whentemperature_1=>

if(i2=2000)then

cur_state<=temperature_2;

else

cur_state<=temperature_1;

endif;

whentemperature_2=>

if(i2=2000)then

cur_state<=blank2;

else

cur_state<=temperature_2;

endif;

whenblank2=>

if(i2=2000)then

cur_state<=degree_1;

else

cur_state<=blank2;

endif;

whendegree_1=>

if(i2=2000)then

cur_state<=degree_2;

else

cur_state<=degree_1;

endif;

whendegree_2=>

if(i2=2000)then

cur_state<=blank3;

else

cur_state<=degree_2;

endif;

whenblank3=>

if(i2=2000)then

cur_state<=set_addr;

else

cur_state<=blank3;

endif;

endcase;

endif;

endprocessdisplay;

withmuxselect

SF_D<=SF_D0when'0',--transmit

SF_D1whenothers;--initialize

withmuxselect

LCD_E<=LCD_E0when'0',--transmit

LCD_E1whenothers;--initialize

--specifiedbydatasheet

transmit:

process(clk,rst_n,tx_init)

begin

if(rst_n='0')then

tx_state<=done;

elsif(clk='1'andclk'event)then

casetx_stateis

whenhigh_setup=>--40ns

LCD_E0<='0';

SF_D0<=tx_byte(7downto4);

if(i2=2)then

tx_state<=high_hold;

i2<=0;

else

tx_state<=high_setup;

i2<=i2+1;

endif;

whenhigh_hold=>--230ns

LCD_E0<='1';

SF_D0<=tx_byte(7downto4);

if(i2=12)then

tx_state<=oneus;

i2<=0;

else

tx_state<=high_hold;

i2<=i2+1;

endif;

whenoneus=>

LCD_E0<='0';

if(i2=50)then

tx_state<=low_setup;

i2<=0;

else

tx_state<=oneus;

i2<=i2+1;

endif;

whenlow_setup=>

LCD_E0<='0';

SF_D0<=tx_byte(3downto0);

if(i2=2)then

tx_state<=low_hold;

i2<=0;

else

tx_state<=low_setup;

i2<=i2+1;

endif;

whenlow_hold=>

LCD_E0<='1';

SF_D0<=tx_byte(3downto0);

if(i2=12)then

tx_state<=fortyus;

i2<=0;

else

tx_state<=low_hold;

i2<=i2+1;

endif;

whenfortyus=>

LCD_E0<='0';

if(i2=2000)then

tx_state<=done;

i2<=0;

else

tx_state<=fortyus;

i2<=i2+1;

endif;

whendone=>

LCD_E0<='0';

if(tx_init='1')then

tx_state<=high_setup;

i2<=0;

else

tx_state<=done;

i2<=0;

endif;

endcase;

endif;

endprocesstransmit;

--specifiedbydatasheet

power_on_initialize:

process(clk,rst_n,i

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 设计艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1