FPGA實(shí)驗(yàn)報(bào)告-交通燈控制器設(shè)計(jì)_第1頁(yè)
FPGA實(shí)驗(yàn)報(bào)告-交通燈控制器設(shè)計(jì)_第2頁(yè)
FPGA實(shí)驗(yàn)報(bào)告-交通燈控制器設(shè)計(jì)_第3頁(yè)
FPGA實(shí)驗(yàn)報(bào)告-交通燈控制器設(shè)計(jì)_第4頁(yè)
FPGA實(shí)驗(yàn)報(bào)告-交通燈控制器設(shè)計(jì)_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、FPGA實(shí)驗(yàn)報(bào)告 -交通燈控制器設(shè)計(jì) 院 系: 電子與信息工程系 專 業(yè): 通信工程 班 級(jí): 姓 名: 學(xué) 號(hào): 指導(dǎo)教師: 1、 實(shí)驗(yàn)任務(wù) 1、任務(wù)名稱:交通燈控制器的設(shè)計(jì) 2、設(shè)計(jì)內(nèi)容與要求: 設(shè)計(jì)一個(gè)十字路口交通信號(hào)燈的定時(shí)控制電路。要求紅、綠燈按一定的規(guī)律亮和滅,并在亮燈期間進(jìn)行倒計(jì)時(shí),并將運(yùn)行時(shí)間用數(shù)碼管/液晶顯示出來。 綠燈亮?xí)r,為該車道允許通行信號(hào),紅燈亮?xí)r,為該車道禁止通行信號(hào)。要求主干道每次通行時(shí)間為99秒,支干道每次通行時(shí)間為30秒。每次變換運(yùn)行車道前綠燈閃爍,持續(xù)時(shí)間為5秒。即車道要由主干道轉(zhuǎn)換為支干道時(shí),主干道在通行時(shí)間只剩下5秒鐘時(shí),綠燈閃爍顯示,支干道仍為紅燈,以

2、便主干道上已過停車線的車?yán)^續(xù)通行,未過停車線的車停止通行。同理,當(dāng)車道由支干道轉(zhuǎn)換為主干道時(shí),支干道綠燈閃爍顯示5秒鐘,主干道仍為紅燈。 對(duì)紅、綠燈的運(yùn)行時(shí)間要能比較方便的進(jìn)行重新設(shè)置。 對(duì)器件進(jìn)行在系統(tǒng)編程和實(shí)驗(yàn)驗(yàn)證。 用VHDL語言對(duì)設(shè)計(jì)進(jìn)行描述,設(shè)計(jì)一個(gè)測(cè)試方案,通過ISE對(duì)設(shè)計(jì)進(jìn)行仿真驗(yàn)證。并能夠下載到實(shí)驗(yàn)板上調(diào)試成功。6 寫出設(shè)計(jì)性實(shí)驗(yàn)報(bào)告,并打印各層次的源文件和仿真波形,然后作簡(jiǎn)要說明。 2、補(bǔ)充功能與要求: 1.在主干道和支干道添加左轉(zhuǎn)向燈; 2.各燈亮的時(shí)間及最后閃爍時(shí)間可調(diào)節(jié); 3.緊急路況時(shí),主干道和支干道都為紅燈。2、 實(shí)驗(yàn)環(huán)境1、 ISE軟件一套;2、 PC機(jī)一臺(tái)。三、

3、設(shè)計(jì)思路1、根據(jù)題目要求,知道整個(gè)交通燈的運(yùn)行過程是周期的,所以可以設(shè)計(jì)一個(gè)總的計(jì)數(shù)器,滿周期則清零;2、將燈閃爍時(shí)間、主干道綠燈亮的時(shí)間、主干道轉(zhuǎn)向燈亮的時(shí)間、支干道綠燈亮的時(shí)間、支干道轉(zhuǎn)向燈亮的時(shí)間分別記為變量t0、t1、t2、t3、t4,通過調(diào)整它們,實(shí)現(xiàn)調(diào)節(jié)各燈亮的時(shí)間;3、將所有需要顯示的量由同一個(gè)信號(hào)表示并最終輸出、顯示在LCD上。4、 系統(tǒng)設(shè)計(jì)a)系統(tǒng)框圖b)狀態(tài)轉(zhuǎn)換說明:主干道和支干道永遠(yuǎn)有且只有一個(gè)燈亮,緊急路況時(shí)兩邊紅燈亮,其余時(shí)候有且只有一個(gè)紅燈亮;主干道綠燈、主干道轉(zhuǎn)向燈亮、支干道綠燈、支干道轉(zhuǎn)向燈依次亮,在最后t0S(默認(rèn)為5S)閃爍。c)輸入輸出及信號(hào)設(shè)計(jì): Por

4、t ( LCD_Clk : in STD_LOGIC;-50mhz時(shí)鐘 reset : in STD_LOGIC:='0'-復(fù)位 sensor:in std_logic :='0'-特殊情況時(shí),兩邊都是紅燈 up:in std_logic :='0' ;-有效時(shí)調(diào)整時(shí)間時(shí)增大時(shí)間 down:in std_logic :='0'-有效時(shí)調(diào)整時(shí)間時(shí)減少時(shí)間 choose:in std_logic :='0'-選擇調(diào)整哪一個(gè)時(shí)間 control:in std_logic :='0'-有效時(shí)可以暫停,調(diào)整時(shí)

5、間 LCD_RS : out STD_LOGIC; LCD_RW : out STD_LOGIC; LCD_EN : out STD_LOGIC; redax,greenax ,greenay:out std_logic;-主干道的紅燈和兩個(gè)綠燈,greenay為左轉(zhuǎn)燈 redbx,greenbx ,greenby:out std_logic;-支干道的紅燈和兩個(gè)綠燈,greenby為左轉(zhuǎn)燈 data : out STD_LOGIC_VECTOR (3 downto 0); -Lcd顯示type istate is(write_instr,write_dataup4,write_datadow

6、n4,set_addrup,set_addrdown,ret_homeup,ret_homedown);signal state:istate;signal cnt_clk,clk500:std_logic;-分別為1hz,500hzsignal cnt:integer range 0 to 15:=0;signal cntnumh,cntnuml:integer range 0 to 9;-輸入到數(shù)碼管的數(shù)字signal countnum:integer ;-計(jì)數(shù)器signal reda,greena,greena1,redb,greenb,greenb1:std_logic;-各交通燈對(duì)應(yīng)

7、的信?signal t:integer range 0 to 99;-要輸入lcd中的數(shù)字d)基本模塊設(shè)計(jì):1)字符譯碼函數(shù)function putc(data:character) return std_logic_vector is -字符譯碼函數(shù),將字符顯示在lcd上variable result:std_logic_vector(7 downto 0);begincase data iswhen 'o'=>result:=conv_std_logic_vector(111,8);when 'u'=> result:=conv_std_logi

8、c_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_vect

9、or(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)數(shù)字譯碼函數(shù)function putn(num:in integer range 0 to 9) return std_logic_vector is -數(shù)字譯碼函數(shù),將數(shù)字顯示在lcd上variable fig:std_logic_vector(7 downto 0);begincas

10、e num iswhen 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&qu

11、ot;when 8=> fig:="00111000"when 9=> fig:="00111001"end case;return fig;end putn;3)分頻,由50Mhz得到500hz,驅(qū)動(dòng)lcd process(LCD_Clk)-分頻,得到500hz時(shí)鐘variable n3:integer range 0 to 49999;beginif rising_edge(LCD_Clk) thenif n3<49999 thenn3:=n3+1;elsen3:=0;clk500<=not clk500;end if;end

12、 if;end process;4)分頻,由500hz得到1hz,作為交通燈控制器輸入process(clk500)-分頻,得到1hz時(shí)鐘variable n:integer range 0 to 249;beginif rising_edge(clk500) thenif n<249 thenn:=n+1;elsen:=0;cnt_clk<=not cnt_clk;end if;end if;end process;5)主要功能實(shí)現(xiàn):process(cnt_clk,reset,choose,up,down,control,t)-實(shí)現(xiàn)各種要求功能,包括倒計(jì)時(shí)顯示,紅綠燈(含左轉(zhuǎn)燈)

13、轉(zhuǎn)換,以及轉(zhuǎn)換時(shí)間調(diào)整variable m:integer range 0 to 4 ;-m表示轉(zhuǎn)換的是哪一個(gè)時(shí)間(t0-t4中哪一個(gè))variable count : natural range 0 to 99;-計(jì)數(shù)器,將正計(jì)數(shù)轉(zhuǎn)換為倒計(jì)數(shù)variable t0:integer range 0 to 99 :=5;-綠燈閃爍時(shí)間variable t1:integer range 0 to 99 :=79;-主干道綠燈亮的時(shí)間variable t2:integer range 0 to 99 :=20;-主干道左轉(zhuǎn)燈亮的時(shí)間variable t3:integer range 0 to 99:

14、=20;-支干道綠燈亮的時(shí)間variable t4:integer range 0 to 99:=10;-支干道左轉(zhuǎn)燈亮的時(shí)間beginif reset='1' then-1-復(fù)位,計(jì)數(shù)器清零,m,t0-t4賦初值 countnum<=0; m:=0; t0:=5; t1:=79; t2:=20; t3:=20; t4:=10;elsif control='1' then-可調(diào)節(jié)時(shí)間或暫停if rising_edge(cnt_clk) then-2if choose ='1' then 選擇t0-t4中的哪一個(gè) 3if m=4 then -

15、4m:=0;-m在0-4之間循環(huán)else m:=m+1;end if; -4t<=m;-顯示melse -choose為0時(shí)調(diào)節(jié)所選時(shí)間 3if up='1' then -tx增大 -4if m =0 then -調(diào)整t0,即閃爍時(shí)間,上限為7s, 5if t0=7 then -6t0:=5;else t0:=t0+1;end if; -6t<=t0;-顯示t0elsif m=1 then-調(diào)整t1,上限99sif t1=99 then -6t1:=79;else t1:=t1+1;end if; -6t<=t1;-顯示t1elsif m=2 then-調(diào)整t

16、2,上限為30sif t2=30 then -6t2:=20;else t2:=t2+1;end if; -6t<=t2;-顯示t2elsif m=3 then -調(diào)整t3,上限為30sif t3=30 then -6t3:=20;else t3:=t3+1;end if; -6t<=t3;-顯示t3elsif m=4 then-調(diào)整t4,上限為15sif t4=15 then -6t4:=10;else t4:=t4+1;end if; -6t<=t4;-顯示t4end if; -5elsif down='1' then -tx減小 4if m =0 the

17、n -調(diào)整t0,即閃爍時(shí)間,下限為2s, 5if t0=2 then -6t0:=5;else t0:=t0-1;end if; -6t<=t0;-顯示t0elsif m=1 then-調(diào)整t1,下限為39秒if t1=39 then -6t1:=79;else t1:=t1-1;end if; -6t<=t1;-顯示t1elsif m=2 then -調(diào)整t2,下限為10sif t2=10 then -6t2:=20;else t2:=t2-1;end if; -6t<=t2;-顯示t2elsif m=3 then -調(diào)整t3,下限10sif t3=10 then -6t3

18、:=20;else t3:=t3-1; end if;-6t<=t3;-顯示t3elsif m=4 then-調(diào)整t4,下限8sif t4=8 then -6t4:=10;else t4:=t4-1;end if;-6t<=t4; -顯示t4end if; -5end if; -4end if; -3end if; -2elsif rising_edge(cnt_clk) then -此時(shí)reset=0if countnum=t1+t2+t3+t4 then -2記數(shù)到整周期時(shí),記數(shù)器清零countnum<=0;elsecountnum<=countnum+1; -計(jì)數(shù)

19、器小于整周期時(shí),正常記數(shù)end if; -2if sensor='1' then -2 sensor信號(hào)有效期間,表示緊急情況兩組路燈都為紅燈reda<='1'redb<='1'greena<='0'greenb<='0'greena1<='0'greenb1<='0'elseif countnum<=t1-t0 then-3主干道綠燈亮且非閃爍,支干道紅燈亮 reda<='0'greena<='1'

20、;greena1 <= '0'redb<='1'greenb<='0'greenb1<='0' elsif countnum<=t1 then -主干道綠燈亮且閃爍,支干道紅燈亮 reda<='0'greena<=not greena;greena1<= '0'redb<='1'greenb<='0'greenb1<='0'elsif countnum<=t1+t2-t0 then

21、 -主干道左轉(zhuǎn)綠燈亮且非閃爍,支干道紅燈亮 reda<='0'greena<='0'greena1 <= '1'redb<='1'greenb<='0'greenb1<='0'elsif (countnum<=t1+t2) then -主干道左轉(zhuǎn)綠燈亮且閃爍,支干道紅亮reda<='0'greena<='0'greena1 <= not greena1;redb<='1'greenb&l

22、t;='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'g

23、reena<='0'greena1 <= '0'redb<='0'greenb<=not greenb;greenb1<='0'elsif (countnum<=t1+t2+t3+t4-t0) then -支干道左轉(zhuǎn)綠燈亮且非閃爍,主干道紅燈亮 reda<='1'greena<='0'greena1 <= '0'redb<='0'greenb<='0'greenb1<='1

24、'elsif (countnum<=t1+t2+t3+t4) then -支干道左轉(zhuǎn)綠燈亮且閃爍,主干道紅燈亮 reda<='1'greena<='0'greena1 <= '0'redb<='0'greenb<='0'greenb1<=not greenb1;end if; -3end if; -2-下面將正計(jì)數(shù)轉(zhuǎn)換為倒計(jì)數(shù)-if countnum<=t1 then -2count:=t1-countnum; -主干道綠燈亮,支干道紅燈亮?xí)r倒計(jì)時(shí)elsif

25、countnum<=t1+t2 then -主干道左轉(zhuǎn)綠燈亮,支干道紅燈亮?xí)r倒計(jì)時(shí)count:=t1+t2-countnum;elsif countnum<=t1+t2+t3 then-支干道綠燈亮,主干道紅燈亮 時(shí)倒計(jì)時(shí)count:=t1+t2+t3-countnum;elsif countnum<=t1+t2+t3+t4 then-支干道左轉(zhuǎn)綠燈亮,主干道紅燈亮 時(shí)倒計(jì)時(shí)count:=t1+t2+t3+t4-countnum; end if; -2-上面將正計(jì)數(shù)轉(zhuǎn)換為倒計(jì)數(shù)- t<=count;-顯示countend if; -1-以下代碼為分位譯碼-if t>

26、;=90 then -1cntnumh<=9;cntnuml<=t-90;elsif t>=80 thencntnumh<=8;cntnuml<=t-80;elsif t>=70 thencntnumh<=7;cntnuml<=t-70;elsif t>=60 thencntnumh<=6;cntnuml<=t-60;elsif t>=50 thencntnumh<=5;cntnuml<=t-50;elsif t>=40 thencntnumh<=4;cntnuml<=t-40;elsif t

27、>=30 thencntnumh<=3;cntnuml<=t-30;elsif t>=20 thencntnumh<=2;cntnuml<=t-20;elsif t>=10 thencntnumh<=1;cntnuml<=t-10;elsecntnumh<=0;cntnuml<=t;end if;-1-以上代碼為分位譯碼-各信號(hào)賦給各輸出的交通燈greenax<=greena;-主干綠燈greenay<=greena1;-主干左轉(zhuǎn)綠燈greenbx<=greenb;-支干道綠燈greenby<=green

28、b1;-支干道左轉(zhuǎn)綠燈redax<=reda;-主干紅燈redbx<=redb;-支干道綠燈end process;主要功能仿真如下:a)、reset為1時(shí),初始化。為0時(shí),會(huì)從79倒計(jì)時(shí),主干道綠燈亮,支干道紅燈亮,sensor為1時(shí),主干道和支干道都為紅燈亮:b)默認(rèn)情況下倒計(jì)時(shí)到最后5S時(shí)會(huì)閃爍顯示,并切換到下一狀態(tài),繼續(xù)倒計(jì)時(shí):c)如果reset=0且control為1時(shí),暫停計(jì)數(shù),此時(shí)若choose為1,則會(huì)在0-4之間循環(huán)計(jì)數(shù),選擇調(diào)節(jié)哪一個(gè)時(shí)間(t0-t4),若choose改為0,就會(huì)暫停計(jì)數(shù):d)此時(shí)(reset=0,control=1,choose=0)若選擇do

29、wn=1或up=1,則會(huì)減計(jì)數(shù)(默認(rèn)值到最小值循環(huán))或加計(jì)數(shù)(默認(rèn)值到最大值循環(huán))調(diào)整當(dāng)前選中的時(shí)間t:(當(dāng)前選的t0,閃爍時(shí)間,最后調(diào)整為7s)e)若將control置于0 ,則會(huì)接著倒計(jì)時(shí),就像最初初始化時(shí),但此時(shí)調(diào)整后的時(shí)間生效(這里閃爍時(shí)間改為7s):6)顯示process(clk500,reset)-lcd上顯示數(shù)字和字符beginif reset='1' then-復(fù)位時(shí)不顯示state<=write_instr;LCD_RS<='0'cnt<=0;elsif rising_edge(clk500) then-顯示數(shù)字或字符case

30、 state iswhen write_instr=>LCD_RS<='0'case cnt is when 0=> data<="0011"when 1=> data<="0011"when 2=> data<="0011"when 3=> data<="0010"when 4=> data<="0010"when 5=> data<="1000"when 6=> da

31、ta<="0000"when 7=> data<="0110"when 8=> data<="0000"when 9=> data<="1100"when 10=> data<="0000"when 11=> data<="0001"when others=> data<="0000"end case;if cnt=11 thencnt<=0;state<=write

32、_dataup4;elsecnt<=cnt+1;state<=write_instr;end if;when write_dataup4=>LCD_RS<='1'case cnt iswhen 0=> data<=putc('C')(7 downto 4);when 1=> data<=putc('o')(7 downto 4);when 2=> data<=putc('u')(7 downto 4);when 3=> data<=putc('n

33、9;)(7 downto 4);when 4=> data<=putc('t')(7 downto 4);when 5=> data<=putc('e')(7 downto 4);when 6=> data<=putc('r')(7 downto 4);when 7=> data<=putc(':')(7 downto 4);when 8=> data<=putn(cntnumh)(7 downto 4);when 9=> data<=putn(cntnuml

34、)(7 downto 4);when others=>data<="0000"end case;state<=write_datadown4;when write_datadown4=>case cnt iswhen 0=> data<=putc('C')(3 downto 0);when 1=> data<=putc('o')(3 downto 0);when 2=> data<=putc('u')(3 downto 0);when 3=> data<=putc('n')(3 downto 0);when 4=> data<=putc('t')(3 downto 0);when 5=> data<=putc('e')(3 downto 0);whe

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論