基于FPGA的A/D轉(zhuǎn)換采樣控制模塊的設(shè)計(jì)
2.3 A/D采樣控制與數(shù)據(jù)轉(zhuǎn)換的部分程序及仿真
采用QuartusⅡ軟件平臺下的VHDL語言編程實(shí)現(xiàn)。
library ieee;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_1164.all;
entity ad_hgq is
port( d :in std_logic_vector(7 downto 0);---AD輸入;
clk,eoc :in std_logic; ---eoc:轉(zhuǎn)換結(jié)束狀態(tài)信號; oe : buffer std_logic;
addr :out std_logic_vector(2 downto 0); ---oe:輸出允許,addr:選通地址;
ale,start:out std_logic; ---ale:允許地址鎖存;
q :buffer std_logic_vector(7 downto 0)); ---轉(zhuǎn)換數(shù)據(jù)輸出顯示;
end ad_hgq;
architecture behaviour of ad_hgq is
type state is (st0,st1,st2,st3,st4,st5,st6,st7); ---以枚舉類型定義各狀態(tài)子類型;
signal current_state,next_state :state:=st0; signal regl :std_logic_vector(7 downto 0);
signal addrx :std_logic_vector(2 downto 0):=000;
signal lock :std_logic; ---轉(zhuǎn)換后數(shù)據(jù)輸出鎖存時(shí)鐘信號;
signal hex :std_logic_vector(7 downto 0);
begin
process(clk)
begin
if(clk'event and clk='1') then current_state=next_state;
end if; ---在時(shí)鐘上升沿,轉(zhuǎn)換至下一狀態(tài);
end process ; ---由信號current_state將當(dāng)前狀態(tài)帶出進(jìn)程,進(jìn)入下一進(jìn)程;
process(lock)
begin
if lock='1'and lock'event then regl=d;
end if; --在lock上升沿,將轉(zhuǎn)換好的數(shù)據(jù)鎖存入8位鎖存器中;
end process;
process(clk)
begin
if clk'event and clk='1' then
if current_state=st0 then addrx=addrx+1; ---進(jìn)入下一地址通道;
end if;
end if;
addr=addrx;
end process;
q=regl; ---數(shù)據(jù)輸出;
process(clk)
begin
if( clk'event and clk ='1') then if oe='1' then hex=q; ---將數(shù)據(jù)送給hex;
end if;
end if;
end process;
end behaviour;
圖2顯示的是A/D采樣控制并將所采的數(shù)據(jù)轉(zhuǎn)換為BCD碼的仿真結(jié)果。圖中Value為所采的電壓結(jié)果值。
3 結(jié)束語
采用EP1C6T144C8芯片實(shí)現(xiàn)對A/D轉(zhuǎn)換器的采樣控制,充分利用了FPGA的高速度和高可靠性,從而解決了傳統(tǒng)中用單片機(jī)控制時(shí)速度慢的問題。FPGA具有靈活的編程方式,簡單方便的編程環(huán)境,易學(xué)易用,大大提高工作效率,縮短研制周期。本設(shè)計(jì)可用于高速應(yīng)用領(lǐng)域和實(shí)時(shí)監(jiān)控方面。
評論