劉博 吳華 李頔 曹佳哲
【摘 要】利用Xilinx ISE集成開發(fā)環(huán)境和FPGA開發(fā)板實現(xiàn)電子秒表的功能。該電子秒表的顯示范圍為0.00秒-59.99秒,精度位0.01秒,通過按鍵控制其啟動、暫停和清零。應(yīng)用VHDL語言設(shè)計數(shù)字系統(tǒng),可大大縮短設(shè)計時間、降低開發(fā)成本,而且易于修改。
【關(guān)鍵詞】FPGA;ISE;電子秒表;VHDL
中圖分類號: TH714 文獻標(biāo)識碼: A 文章編號: 2095-2457(2018)33-0048-002
DOI:10.19694/j.cnki.issn2095-2457.2018.33.020
0 引言
傳統(tǒng)的電子秒表設(shè)計開發(fā)周期長、精度不高,而且不能根據(jù)用戶需求現(xiàn)場修改功能。本文利用美國Xilinx公司的ISE集成開發(fā)軟件[1]和FPGA(現(xiàn)場可編程門陣列)開發(fā)板,采用自頂向下的設(shè)計方法[2],根據(jù)設(shè)計指標(biāo)和需求,從整個系統(tǒng)的邏輯功能觸發(fā),將整個系統(tǒng)分為若干個子系統(tǒng),每個子系統(tǒng)又可分為幾個功能模塊,利用邏輯框圖描述各功能模塊和相互間的聯(lián)系,即繪制系統(tǒng)的結(jié)構(gòu)框圖,最后用VHDL語言[2]實現(xiàn)。在ISE軟件中輸入源程序和管腳約束文件,經(jīng)過綜合、實現(xiàn)、生成二進制文件,最后下載到FPGA開發(fā)板上驗證。采用自頂向下的設(shè)計方法可將復(fù)雜問題分解成若干小模塊,符合常規(guī)的邏輯思維習(xí)慣,而且便于分工合作,從而提高設(shè)計效率?;贔PGA的電子秒表具有更多的功能、更好的性能和靈活性。
1 整體設(shè)計
該電子秒表要實現(xiàn)以下功能:設(shè)置啟動鍵和復(fù)位鍵(即清零),以便秒表能隨意啟動、暫停和清零。顯示0.00秒到59.99秒,共有4個輸出顯示位,分別是0.01秒位、0.1秒位、秒位和10秒位,需要4個計數(shù)器與之對應(yīng)。4個計數(shù)器的輸出全部為BCD碼(二-十進制碼)輸出,便于同譯碼器連接,最終通過7段數(shù)碼管顯示。
根據(jù)以上分析,電子秒表主要由十進制計數(shù)器、六進制計數(shù)器、分頻器、控制模塊和顯示譯碼器組成。其中三個十進制計數(shù)器分別對0.01秒、0.1秒和秒位進行計數(shù),六進制計數(shù)器用來對用來對10秒位進行計數(shù),分頻器用來產(chǎn)生100Hz的計數(shù)脈沖和1KHz的掃描時鐘(因為4個LED數(shù)碼管采用動態(tài)掃描顯示方式,所以需要掃描時鐘),顯示譯碼器將BCD碼轉(zhuǎn)換成7段數(shù)碼管顯示,控制模塊用來控制讓4個數(shù)碼管中的哪一位輸出。
2 各功能模塊實現(xiàn)和頂層文件編寫
2.1 底層模塊實現(xiàn)
2.1.1 十進制計數(shù)器
計數(shù)時鐘為100Hz。
entity count6 is
Port ( clk,clr,start : in STD_LOGIC;
cout : out STD_LOGIC;
daout:out STD_LOGIC_VECTOR(3 downto 0));
end count6;
architecture Behavioral of count6 is
signal temp:std_logic_vector(3 downto 0);
begin
process(clk,clr)
begin
if clr='1' then
temp<="0000";
cout<='0';
elsif (clk'event and clk='1') then
if start='1' then
if temp>="0101" then
temp<="0000";
cout<='1';
else
temp<=temp+1;
cout<='0';
end if;
end if;
end if;
daout<=temp;
end process;
end Behavioral;
2.1.2 六進制計數(shù)器
實體聲明部分與十進制計數(shù)器程序相同,不同的只有結(jié)構(gòu)體中以下兩行:
if temp>="1001" then
temp<="0000";
2.1.3 分頻器
將FPGA開發(fā)板上的50MHz的時鐘分出一個100Hz的計數(shù)時鐘和一個1KHz的掃描時鐘。
entity div is
Port ( clr,clk : in STD_LOGIC;
q1 : buffer STD_LOGIC;
q2 : buffer STD_LOGIC);
end div;
architecture Behavioral of div is
signal counter:integer range 0 to 249999;
signal counter2:integer range 0 to 24999;
begin
process(clr,clk)
begin
if (clk='1' and clk'event) then
if clr='1' then
counter<=0;
elsif counter=249999 then
counter<=0;
q1 <= not q1;
else
counter<=counter+1;
end if;
end if;
end process;
process(clr,clk)
begin
if (clk='1' and clk'event) then
if clr='1' then
counter2<=0;
elsif counter2=24999 then
counter2<=0;
q2 <= not q2;
else
counter2<=counter2+1;
end if;
end if;
end process;
end Behavioral;
2.1.4 顯示譯碼器
將輸入的BCD碼轉(zhuǎn)換成7段數(shù)碼管對應(yīng)的值輸出,F(xiàn)PGA開發(fā)板是共陽極接法。
entity deled is
Port ( num : in STD_LOGIC_VECTOR (3 downto 0);
led : out STD_LOGIC_VECTOR (6 downto 0));
end deled;
architecture Behavioral of deled is
begin
process(num)
begin
case num is
when"0000"=>led<="0000001";-----------3FH0
when"0001"=>led<="1001111";-----------06H 1
when"0010"=>led<="0010010";-----------5BH 2
when"0100"=>led<="1001100";-----------66H 4
when"0101"=>led<="0100100";-----------6DH 5
when"0110"=>led<="0100000";-----------7DH 6
when"0111"=>led<="0001101";-----------27H 7
when"1000"=>led<="0000000";-----------7FH 8
when"1001"=>led<="0000100";-----------6FH 9
when others=>led<="1111111";-----------00H
end case;
end process;
end Behavioral;
2.1.5 控制模塊
控制先讓哪一位輸出,再讓哪一位輸出。
entity seltime is
Port ( clr : in STD_LOGIC;
clk : in STD_LOGIC;
dain0 : in STD_LOGIC_VECTOR (3 downto 0);
dain1 : in STD_LOGIC_VECTOR (3 downto 0);
dain2 : in STD_LOGIC_VECTOR (3 downto 0);
dain3 : in STD_LOGIC_VECTOR (3 downto 0);
daout : out STD_LOGIC_VECTOR (3 downto 0);
an : out STD_LOGIC_VECTOR (3 downto 0);
dp:out std_logic);
end seltime;
architecture Behavioral of seltime is
signal temp:integer range 0 to 3;
begin
process(clk)
begin
if (clr='1') then
daout<="0000";
temp<=0;
elsif (clk='1'and clk'event) then
if temp=3 then temp<=0;
else temp<=temp + 1;
end if;
case temp is
when 0=>daout<=dain0; an<="1110";dp<='1';
when 1=>daout<=dain1; an<="1101";dp<='1';
when 2=>daout<=dain2; an<="1011";dp<='0';
when 3=>daout<=dain3; an<="0111";dp<='1';
when others=>daout<=dain3; an<="1111";dp<='1';
end case;
end if;
end process;
end Behavioral;
2.2 頂層文件編寫
頂層文件應(yīng)根據(jù)系統(tǒng)功能結(jié)構(gòu)圖編寫,它的主要作用是將底層的7個模塊進行連接,并明確這些模塊與外圍部件(按鍵、7段數(shù)碼管)如何進行連接。利用元件例化語句,可實現(xiàn)自頂向下的層次化設(shè)計。編好后,要經(jīng)過ISE軟件編譯檢查語法錯誤。最后將生成的二進制文件下載到FPGA開發(fā)板上驗證。
3 總結(jié)
利用美國Xilinx公司的ISE集成開發(fā)軟件,通過VHDL語言編程實現(xiàn)電子秒表設(shè)計的功能,并下載到FPGA開發(fā)板上驗證。因為FPGA器件便于根據(jù)用戶需求修改功能、靈活、可移植性好,所以基于FPGA設(shè)計數(shù)字電路系統(tǒng)可大大提高設(shè)計效率、縮短開發(fā)時間、降低開發(fā)成本。
【參考文獻】
[1]鄒彥,等.EDA技術(shù)與數(shù)字系統(tǒng)設(shè)計[M].電子工業(yè)出版社,2007.
[2]何賓,EDA原理及應(yīng)用[M].清華大學(xué)出版社,2009.