以前做的,以前調試出來了,現在不知道合適沒有
摘要: 可編程邏輯器件,不僅速度快、集成度高,并且能隨心所欲地完成用戶定義的邏輯功能,還可以加密和重新編程,其編程次數最大可達1萬次以上。使用可編程邏輯器件可以大大簡化硬件系統、降低成本、提高系統的可靠性、靈活性和保密性。交通燈控制電路自動控制十字路口兩組紅、黃、綠交通燈的狀態轉換,指揮各種車輛和行人安全通行,實現十字路口交通管理的自動化。交通信號燈的出現,使交通得以有效管制,對于疏導交通流量、提高道路通行能力、減少交通事故有明顯效果。本設計主要以74190芯片為核心實現交通燈控制。這個電路采用兩個74190芯片連成一個從25到00的計數器,用JK觸發器實現信號燈的轉換,倒計時顯示采用七段數碼管作為顯示,非常簡單地實現了交通信號燈的控制。使用電腦仿真技術對系統進行仿真。
目錄 1.EDA技術概述17
2.設計思路17
2.1設計思路18
2.2所實現功能說明19
3.各模塊的編程實現20
3.1 時基脈沖發生模塊20
3.2 計數及紅綠燈控制模塊22
3.3 譯碼模塊23
3.4 主程序25
3.5 仿真時序圖29
4.心得體會30
5.參考文獻30
1.EDA技術概述 FPGA(現場可編程門陣列)和CPLD(復雜可編程邏輯器件)都是可編程邏輯器件,他們是在PAL,GAL等邏輯器件的基礎上發展起來的。同以往的PAL,GAL相比較,FPGA/CPLD的規模比較大,它可以替代幾十甚至幾千塊通用IC芯片。這樣的FPGA/CPLD實際上就是一個子系統部件。這種芯片受到世界范圍內電子工程設計人員的廣泛關注和普遍歡迎。比較典型的就是Altera公司和Xilinx公司的CPLD器件系列和FPGA器件系列,他們開發較早,占用了較大的PLD市場。 對用戶而言,雖然FPGA/CPLD的內部結構稍有不同,但其用法都一樣,所以大多數情況下,不加以區分。FPGA/CPLD芯片都是特殊的ASIC芯片,除了具有ASIC的特點外,還具有以下幾個優點: (1) 隨著VLSI(Very LargeScale IC,超大集成電路)工藝的不斷提高單一芯片內部可以容納上百萬個晶體管,FPGA/CPLD芯片的規模也越來越大,其單片邏輯門數已達到上百萬門,它所實現的功能也越來越強,同時也可以實現系統集成,即片上系統SOC. (2) FPGA/CPLD芯片在出廠之前都做過百分之百的測試,不需要設計人員承擔芯片風險和費用,設計人員只需在自己的實驗室就可以通過相關的軟硬件環境來完成芯片的最終功能設計。所以,FPGA/CPLD的資金投入就小,減少了潛在的花費。 (3) 用戶可以反復地編程、擦除、使用或者在外圍電路不動的情況下用不同軟件就可實現不同的功能。FPGA/CPLD軟件包中有各種輸入工具和仿真工具,及版圖設計工具和編程器等全線產品,電路設計人員在很短的時間內就可完成電路的輸入、編譯、優化。仿真,直至最后芯片的制作。當電路有少量的改動,更能顯示FPGA/CPLD的優勢。電路設計人員在使用FPGA/CPLD進行電路設計時,不需要具有專門的IC(集成電路)深層次的知識,FPGA/CPLD軟件易學易用,能使設計人員更能集中精力進行電路設計,快速將產品推向市場。 (4) 在線可編程技術(ISP)使得使用FPGA/CPLD的產品可以做到遠程升級。 2.設計思路 2.1設計思路 所設計的交通信號燈控制電路,主要適用于在兩條干道匯合點形成的十字交叉路口,路口設計兩組紅綠燈分別對兩個方向上的交通運行狀態進行管理。 東西方向和南北方向各使用3個LED顯示,紅黃綠各代表紅黃綠燈,綠燈亮同時是人行燈。 東西方向和南北方向計時均為2位數,共需要4個LED七段數碼管顯示。Time信號輸出顯示的內容。采用EPF10K10LC84-4 實現 2.2 所實現功能說明 南北和東西方向各有一組綠,人行,紅,黃燈,各自的持續時間分別為20s,20s,25s,5s;用兩組數碼管,以倒計時方式顯示兩個方向允許通行或禁止通行的剩余時間;綠燈也可看做人行燈; 3.各模塊的編程實現 3.1時基脈沖發生模塊 在紅綠燈交通信號系統中,大多數的情況是通過自動控制的方式指揮交通的。因此,為了避免意外事件的發生,電路必須給出一個穩定的時鐘才能讓系統正常的工作。因此時鐘發生模塊最主要的功能就是產生一些穩定的輸出信號,并將其用做后面幾個電路的使能控制與同步信號。通過編程實現1Hz脈沖的產生,程序如下所示。 - Library IEEE ;
- use IEEE.std_logic_1164.all ;
- ENTITY CLKGEN IS
- PORT( CLK1:IN STD_LOGIC;
- CLK:OUT STD_LOGIC);
- END CLKGEN;
- ARCHITECTURE behav OF CLKGEN IS
- SIGNAL CNTER:INTEGER RANGE 0 TO 25000000;
- BEGIN
- PROCESS(CLK) BEGIN
- IF CLK'EVENT AND CLK='1' THEN
- IF CNTER=25000000 THEN CNTER<=0;
- ELSE CNTER<=CNTER+1;
- END IF;
- END IF;
- END PROCESS;
- PROCESS(CNTER)
- BEGIN
- IF CNTER=12500000 THEN CLK<='1';
- END IF;
- IF CNTER=25000000 THEN CLK<='0';
- END IF;
- END PROCESS;
- END behav;
復制代碼3.2計數及紅綠燈控制模塊
南北向和東西向各有一組紅黃綠燈,各自持續的時間為分別為25s、5s、20s。通過編程可以實現控制各通道的計數控制且輸出為二進制數,并且可以控制各燈的亮滅情況,高電平為亮,低電平為滅。
東西向模塊程序為: - library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity daolu1 is
- port(
- clk:in std_logic;
- timel:out std_logic_vector(4 downto 0);
- r,g,t:out std_logic );
- end daolu1;
- architecture daodu of daolu1 is
- type color is(green,yellow,red);
- begin
- process(clk)
- variable reset:std_logic:='0';
- variable tempr,tempg,tempt:std_logic;
- variable temp_l:std_logic_vector(4 downto 0);
- variable temp_color:color:=green;
- begin
- if(clk'event and clk='1')then
- case temp_color is
- when yellow=>
- tempr:='1';
- tempg:='0';
- tempt:='0';
- case reset is
- when '0' =>
- temp_l:="00100";
- reset:='1';
- when others =>
- case temp_l is
- when "00000"=>
- temp_l:="11000";
- temp_color:=red;
- when others=>
- temp_l:=temp_l-1;
- end case;
- end case;
- when green=>
- tempr:='0';
- tempg:='0';
- tempt:='1';
- case reset is
- when '0' =>
- temp_l:="10011";
- reset:='1';
- when others =>
- case temp_l is
- when "00000"=>
- temp_l:="00100";
- temp_color:=yellow;
- when others=>
- temp_l:=temp_l-1;
- end case;
- end case;
- when red=>
- tempr:='0';
- tempg:='1';
- tempt:='0';
- case reset is
- when '0' =>
- temp_l:="11000";
- reset:='1';
- when others =>
- case temp_l is
- when "00000"=>
- temp_l:="10011";
- temp_color:=green;
- when others=>
- temp_l:=temp_l-1;
- end case;
- end case;
- end case;
-
- end if;
- timel<=temp_l;
- r<=tempr;
- g<=tempg;
- t<=tempt;
- end process;
- end;
- 南北向模塊程序為:
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity daolu2 is
- port(
- clk:in std_logic;
- time2:out std_logic_vector(4 downto 0);
- r1,g1,t1:out std_logic
- );
- end daolu2;
- architecture daolu of daolu2 is
- type color is(red,green,yellow);
- begin
- process(clk)
- variable reset:std_logic:='0';
- variable tempr,tempg,tempt:std_logic;
- variable temp_l:std_logic_vector(4 downto 0);
- variable temp_color:color:=red;
- begin
- if(clk'event and clk='1')then
-
- case temp_color is
- when yellow=>
- tempr:='1';
- tempg:='0';
- tempt:='0';
- case reset is
- when '0' =>
- temp_l:="00100";
- reset:='1';
- when others =>
- case temp_l is
- when "00000"=>
- temp_l:="11000";
- temp_color:=red;
- when others=>
- temp_l:=temp_l-1;
- end case;
- end case;
- when green=>
- tempr:='0';
- tempg:='0';
- tempt:='1';
- case reset is
- when '0' =>
- temp_l:="10011";
- reset:='1';
- when others =>
- case temp_l is
- when "00000"=>
- temp_l:="00100";
- temp_color:=yellow;
- when others=>
- temp_l:=temp_l-1;
- end case;
- end case;
- when red=>
- tempr:='0';
- tempg:='1';
- tempt:='0';
- case reset is
- when '0' =>
- temp_l:="11000";
- reset:='1';
- when others =>
- case temp_l is
- when "00000"=>
- temp_l:="10011";
- temp_color:=green;
- when others=>
- temp_l:=temp_l-1;
- end case;
- end case;
- end case;
- end if;
- time2<=temp_l;
- r1<=tempr;
- g1<=tempg;
- t1<=tempt;
- end process;
- end;
復制代碼
3.3 譯碼模塊
計數控制電路輸出為二進制碼,要想用數碼管顯示計數需要把二進制碼變為七段碼。通過編程先把二進制碼轉換為BCD碼再把BCD碼轉換為七段碼實現程序如下:
將二進制碼轉化為BCD碼 - library ieee;
- use ieee.std_logic_1164.all;
- entity yima is
- port (time : in std_logic_vector(4 downto 0);
- tim : out std_logic_vector(7 downto 0));
- end yima;
- architecture one of yima is
- begin
- process(time)
- begin
- case time is
- when "00000" => tim <= "00000000";
- when "00001" => tim <= "00000001";
- when "00010" => tim <= "00000010";
- when "00011" => tim <= "00000011";
- when "00100" => tim <= "00000100";
- when "00101" => tim <= "00000101";
- when "00110" => tim <= "00000110";
- when "00111" => tim <= "00000111";
- when "01000" => tim <= "00001000";
- when "01001" => tim <= "00001001";
- when "01010" => tim <= "00010000";
- when "01011" => tim <= "00010001";
- when "01100" => tim <= "00010010";
- when "01101" => tim <= "00010011";
- when "01110" => tim <= "00010100";
- when "01111" => tim <= "00010101";
- when "10000" => tim <= "00010110";
- when "10001" => tim <= "00010111";
- when "10010" => tim <= "00011000";
- when "10011" => tim <= "00011001";
- when "10100" => tim <= "00100000";
- when "10101" => tim <= "00100001";
- when "10110" => tim <= "00100010";
- when "10111" => tim <= "00100011";
- when "11000" => tim <= "00100100";
- when others => NULL;
- end case;
- end process;
- end;
- 將BCD碼轉化為七段碼
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity yima1 is
- port (jin : in std_logic_vector(3 downto 0);
- chu : out std_logic_vector(6 downto 0));
- end yima1;
- architecture art of yima1 is
- begin
- process (jin) is
- begin
- case jin is
- when "0000"=>chu<="0111111";
- when "0001"=>chu<="0000110";
- when "0010"=>chu<="1011011";
- when "0011"=>chu<="1001111";
- when "0100"=>chu<="1100110";
- when "0101"=>chu<="1101101";
- when "0110"=>chu<="1111101";
- when "0111"=>chu<="0000111";
- when "1000"=>chu<="1111111";
- when "1001"=>chu<="1101111";
- when others=>chu<="0000000";
- end case;
- end process;
- end architecture art;
- 3.4 主程序
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_unsigned.all;
- entity jtd is
- port(clk:in std_logic;
- r,g,t,r1,g1,t1:out std_logic;
- dout1,dout2,dout3,dout4:out std_logic_vector(6 downto 0));
- end entity jtd;
- architecture art of jtd is
- component daolu1 is
- port(
- clk:in std_logic;
- timel:out std_logic_vector(4 downto 0);
- r,g,t:out std_logic);
- end component daolu1;
- component daolu2 is
- port(
- clk:in std_logic;
- time2:out std_logic_vector(4 downto 0);
- r1,g1,t1:out std_logic);
- end component daolu2;
- component yima is
- port (time : in std_logic_vector(4 downto 0);
- tim : out std_logic_vector(7 downto 0));
- end component yima;
- component yima1 is
- port (shr : in std_logic_vector(4 downto 0);
- chu : out std_logic_vector(7 downto 0));
- end component yima1;
- signal ad1,ad2:std_logic_vector(4 downto 0);
- signal ac1,ac2:std_logic_vector(7 downto 0);
- begin
- u1:daolu1 port map(clk=>clk,g=>g,t=>t,r=>r,timel=>ad1);
- u2:daolu2 port map(clk=>clk,g1=>g1,t1=>t1,r1=>r1,time2=>ad2);
- u3:yima port map(time=>ad1,tim=>ac1);
- u4:yima port map(time=>ad2,tim=>ac2);
- u5:yima1 port map(shr=>ac1(3 downto 0),chu=>dout1);
- u6:yima1 port map(shr=>ac1(7 downto 4),chu=>dout2);
- u7:yima1 port map(shr=>ac2(3 downto 0),chu=>dout3);
- u8:yima1 port map(shr=>ac2(7 downto 4),chu=>dout4);
- end architecture art;
復制代碼3.5 仿真時序圖
4. 心得體會
在拿到題目后,首先進行了單元模塊的設計,將每一個單元模塊設計完成后再經行仿真,仿真成功后就可以進行頂層文件的編寫了,在頂層文件的編寫過程中遇到了一些問題,特別是各模塊之間的連接,以及信號的定義,總是有錯誤。有的時候信號的定義容易出現混淆,在反復的修改過后,頂層文件終于能夠編譯成功了。
在波形仿真的過程中,同樣遇到了困難,有的時候,由于END TIME的時間修改的太大,會出現仿真時間過長的問題,這個時候應該要把END TIME的時間相應的改小,或是修改系統時鐘的頻率。
在設計的過程中還應該多聯系下實際情況,要了解實際情況下交通信號燈的工作情況,才能更好的完成此次的課程設計。在今后的工作和學習中,我們不能僅僅把目光停留在課本上,要多理論聯系實際。有的時候,理論上是正確的東西放到現實中去,可能由于種種因素的制約,并不能達到實際的效果,還需要我們進行相應的修改才能完成要求。這次的課程設計使我鞏固了以前學習到的知識,還使我掌握了以前沒有掌握的知識,同時鍛煉了自己的能力。
|