Quartus II9.0 進(jìn)行的EDA頻率計(jì)設(shè)計(jì)
1、頻率計(jì)的測(cè)量范圍為1MHz,量程分10KHz、100KHz和1000KHz三檔(最大讀數(shù)分別為9.99KHz、99.9KHz、999KHz)。
2、當(dāng)讀數(shù)大于999時(shí),頻率計(jì)處于超量程狀態(tài)。此時(shí)顯示器發(fā)出溢出指示(最高位顯示F,其余各位不顯示數(shù)字),下一次測(cè)量時(shí),量程自動(dòng)增大一檔。讀數(shù)小于000時(shí),頻率計(jì)處于欠量程狀態(tài)。下次測(cè)量時(shí),量程減小一檔。 3、要求實(shí)現(xiàn)溢出報(bào)警功能。即當(dāng)頻率高于999KHz時(shí),頻率計(jì)處于超量程狀態(tài),產(chǎn)生一報(bào)警信號(hào),點(diǎn)亮LED燈,從而實(shí)現(xiàn)溢出報(bào)警功能。 4、用記憶顯示方式,即計(jì)數(shù)過程中不顯示數(shù)據(jù),待計(jì)數(shù)過程結(jié)束后,顯示計(jì)數(shù)結(jié)果,并將此顯示結(jié)果保持到下一次計(jì)數(shù)結(jié)束。顯示時(shí)間應(yīng)不小于1秒,小數(shù)點(diǎn)位置隨量程變更自動(dòng)移位。 2. 系統(tǒng)總體設(shè)計(jì) 本設(shè)計(jì)采用的是直接測(cè)頻率的方法。即測(cè)頻率法就是在一定的時(shí)間間隔內(nèi)TW內(nèi),得到這個(gè)周期信號(hào)重復(fù)變化的次數(shù)NX,則被測(cè)頻率可表示為FX=NX/TW。 頻率計(jì)的系統(tǒng)設(shè)計(jì)可以分為計(jì)頻基準(zhǔn)時(shí)鐘模塊、自動(dòng)換檔模塊、4位10進(jìn)制計(jì)數(shù)模塊鎖存模塊、譯碼顯示模塊。 計(jì)頻基準(zhǔn)時(shí)鐘模塊: 以1kHZ為基準(zhǔn),產(chǎn)生三個(gè)不同占比的0.5Hz脈沖信號(hào)其高電平時(shí)間分別為1s、0.1s、0.01s,分別用以測(cè)量頻率在0~9.99KHz、0~99.9KHz、0~999KHz的頻率。 自動(dòng)換檔模塊: 先以最低檔位測(cè)量,溢出時(shí)下一次計(jì)數(shù)自動(dòng)切換高檔位,計(jì)數(shù)不滿“000”下一次自動(dòng)切換到低檔位。計(jì)數(shù)溢出999khz時(shí),發(fā)出警報(bào)。 四位10進(jìn)制計(jì)數(shù)模塊鎖存模塊: 四位十進(jìn)制計(jì)數(shù),檔位基準(zhǔn)信號(hào)為高電平時(shí),開始計(jì)數(shù),低電平時(shí)鎖存輸出計(jì)數(shù)結(jié)果的前三位,計(jì)數(shù)器清零。當(dāng)溢出或計(jì)數(shù)不滿時(shí),輸出換擋信號(hào)。計(jì)數(shù)刷新頻率為0.5Hz。 譯碼顯示模塊: 將計(jì)數(shù)器輸出的結(jié)果按位譯成7段顯示數(shù)碼管對(duì)應(yīng)數(shù)字碼,根據(jù)所選檔位信號(hào)設(shè)置小數(shù)點(diǎn)位置。刷新頻率為 系統(tǒng)框圖(可打印) 3. 系統(tǒng)詳細(xì)設(shè)計(jì) 3.1 計(jì)頻基準(zhǔn)時(shí)鐘模塊設(shè)計(jì) 該模塊的電路框圖 各輸入輸出引腳的定義及作用 Clk:為基準(zhǔn)時(shí)鐘信號(hào),選用1kHz時(shí)鐘信號(hào) F0:根據(jù)clk分頻出的0.5Hz高電平為1s的計(jì)頻信號(hào),用以0~9.99kHz檔計(jì)頻。 F1:根據(jù)clk分頻出的0.5Hz高電平為0.1s的計(jì)頻信號(hào),用以0~99.9kHz檔計(jì)頻。 F2:根據(jù)clk分頻出的0.5Hz高電平為0.01s的計(jì)頻信號(hào),用以0~999kHz檔計(jì)頻。 - library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_arith.all;
- use ieee.std_logic_unsigned.all;
- entity dw is port(clk:in std_logic;
- f0:out std_logic;
- f1:out std_logic;
- f2:out std_logic);
- end dw;
- architecture body_dw of dw is
- begin
- process(clk) --clk選用1kHz時(shí)鐘信號(hào)
- variable ct:integer range 0 to 2000;
- begin
- if clk'event and clk='1'then --分頻周期為2s的脈沖
- ct:=ct+1;
- if ct=2000 then ct:=0;
- end if;
- if ct<1000 then f0<='1';
- elsif ct<2000 then f0<='0'; --f0為0.5Hz高電平為1s
- end if;
- if ct<100 then f1<='1';
- elsif ct<2000 then f1<='0'; --f1為0.5Hz高電平為0.1s
- end if;
- if ct<10 then f2<='1';
- elsif ct<2000 then f2<='0'; --f2為0.5Hz高電平為0.01s
- end if;
- end if;
- end process;
- end body_dw;
復(fù)制代碼
(可打。 仿真波形(可打印) 對(duì)波形的分析說明: Ct為整數(shù)計(jì)數(shù),檢測(cè)到clk上升沿時(shí)則加一計(jì)數(shù),f0,f1,f2根據(jù)ct計(jì)數(shù)結(jié)果分頻輸出所需脈沖。 3.2 自動(dòng)換檔模塊設(shè)計(jì) f0,f1,f2為各檔位計(jì)頻信號(hào) td為換擋信號(hào) f為所選檔位輸出的測(cè)頻信號(hào) sel輸出檔位選擇信號(hào),用以小數(shù)點(diǎn)位置控制 alarm為999kHz溢出報(bào)警 - library ieee;
- use ieee.std_logic_1164.all;
- use ieee.std_logic_arith.all;
- use ieee.std_logic_unsigned.all;
- entity xz is port(f0:in std_logic;
- f1:in std_logic;
- f2:in std_logic;
- td:in std_logic_vector(1 downto 0);
- f:out std_logic;
- alarm:out std_logic;
- sel:out std_logic_vector(1 downto 0)); --輸出檔位選擇信號(hào)
- end xz;
- architecture body_xz of xz is
- begin
- process(td,f0)
- variable dwxz:std_logic_vector(1 downto 0);
- begin
- if f0'event and f0='1' then --計(jì)數(shù)前以0.5Hz信號(hào)的上升沿檢測(cè)是否有換擋信號(hào)
- if td="10" then --換擋信號(hào)td為10表示切換到高一檔
- if dwxz="10" then alarm<='1'; --如果檔位已是最高,則報(bào)警
- else dwxz:=dwxz+1;
- alarm<='0'; --正常換擋則消除報(bào)警
- end if;
- elsif td="01" then --換擋信號(hào)td為01表示切換到低一檔
- if dwxz="00" then null;
- else dwxz:=dwxz-1;
- alarm<='0';
- end if;
- else alarm<='0'; --正常計(jì)頻,消除報(bào)警
- end if;
- sel<=dwxz;
- if dwxz=0 then f<=f0;end if;
- if dwxz=1 then f<=f1;end if;
- if dwxz=2 then f<=f2;end if;
- end process;
- end body_xz;
復(fù)制代碼

開始時(shí)量程輸出為(檔位選擇)sel=“00”,即最小檔,輸出f為f0,當(dāng)接收到(調(diào)檔)td=“10”切換高一檔,sel變?yōu)椤?0”。 3.3 四位10進(jìn)制計(jì)數(shù)鎖存模塊設(shè)計(jì) M輸入被測(cè)量信號(hào) En輸入測(cè)量脈沖,高電平時(shí)開始計(jì)頻率,低電平輸出鎖存結(jié)果。 q3,q2,q1為鎖存的計(jì)頻結(jié)果。 Td在溢出和欠量程時(shí)候輸出調(diào)檔信號(hào)。 library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity js is port(m:in std_logic;
en:in std_logic;
q1,q2,q3:out std_logic_vector(3 downto 0);
td:out std_logic_vector(1 downto 0));
end js;
architecture body_js of js is
signal js_td:std_logic_vector(1 downto 0);
signal b3,b2,b1: std_logic_vector(3 downto 0);
begin
process(en,m)
variable w0,w1,w2,w3:std_logic_vector(3 downto 0); --四位十進(jìn)制計(jì)數(shù)
begin
if en='1' then --當(dāng)計(jì)頻脈沖為1是開始計(jì)數(shù)
if m'event and m='1' then
if w3="1010" then null;
else w0:=w0+1;
if w0="1010" then
w0:="0000";w1:=w1+1;
if w1="1010" then
w1:="0000";w2:=w2+1;
if w2="1010" then
w2:="0000";w3:=w3+1;
end if ;
end if ;
end if;
end if;
b1<=w1; --計(jì)數(shù)結(jié)果實(shí)時(shí)緩存至b1,b2,b3
b2<=w2;
b3<=w3;
end if ;
end if ;
if en='0'then
q1<=b1; --en檔位脈沖為低電平時(shí)b1,b2,b3結(jié)果為最終值,保持不變
q2<=b2; --將結(jié)果輸出至Q1,Q2,Q3
q3<=b3; --當(dāng)下一次低電平時(shí),刷新計(jì)數(shù)結(jié)果
w0:="0000";
w1:="0000"; --低電平時(shí),計(jì)數(shù)器清零
w2:="0000";
w3:="0000";
end if;
end process;
process(en) --計(jì)數(shù)一結(jié)束,以下降沿觸發(fā)判斷是否欠量程或則溢出
begin --并輸出相應(yīng)調(diào)檔信號(hào)
if en'event and en='0'then
if b1="0000" and b2="0000" then
if b3="0000" then td<="01";
elsif b3="1010" then td<="10";
elsif b3>"0000"and b3<"1010" then td<="00";
end if;
end if;
end if;
end process;
end body_js;
En脈沖為99.9Hz量程脈沖 m被測(cè)脈沖設(shè)置為0~5s 50Hz;5~10s 10000Hz;10~13s 100000Hz; 第一個(gè)測(cè)量脈沖判定結(jié)果為欠量程,調(diào)檔信號(hào)TD輸出01,調(diào)低檔位 第三個(gè)脈沖檢測(cè)判定10.0kHz,在量程范圍,調(diào)檔不做輸出 第六個(gè)脈沖檢測(cè)判定100kHz,溢出,調(diào)檔TD輸出10,調(diào)高檔位
3.4 譯碼模塊 Clk為1kHz時(shí)鐘信號(hào),用以觸發(fā)賦值語句等 Sel為檔位信號(hào) Q1,Q2,Q3為計(jì)數(shù)器鎖存結(jié)果輸入 LED0,LED1,LED2為三位結(jié)果的譯碼輸出
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ym is port(
clk:in std_logic;
sel:in std_logic_vector(1 downto 0);
q1,q2,q3:in std_logic_vector(3 downto 0);
led0,led1,led2:out std_logic_vector(7 downto 0));
end ym;
architecture body_ym of ym is
signal tp:std_logic_vector(3 downto 0);
signal led:std_logic_vector(6 downto 0);
begin
led<="0111111"when tp="0000"else --0
"0000110"when tp="0001"else --1
"1011011"when tp="0010"else --2
"1001111"when tp="0011"else --3
"1100110"when tp="0100"else --4
"1101101"when tp="0101"else --5
"1111101"when tp="0110"else --6
"0000111"when tp="0111"else --7
"1111111"when tp="1000"else --8
"1101111"when tp="1001"else --9
"1110001"when tp="1010"; --F
process(clk,sel)
variable c:std_logic_vector(1 downto 0) ;
begin
if clk'event and clk='1' then
if c="10"then c:="00";
else c:=c+1;
end if;
if q3="1010"then --溢出顯示F
led2<="01110001";
led1<="00000000";
led1<="00000000";
else
if sel="10" then --999KHZ檔小數(shù)點(diǎn)賦值
case c is
when "00"=>tp<=q2;
led0<='1'&led;
when "01"=>tp<=q3;
led1<='0'&led;
when "10"=>tp<=q1;
led2<='0'&led;
when others=>null;
end case;
elsif sel="01" then -- 99.9khz檔小數(shù)點(diǎn)
case c is
when "00"=>tp<=q2;
led0<='0'&led;
when "01"=>tp<=q3;
led1<='1'&led;
when "10"=>tp<=q1;
led2<='0'&led;
when others=>null;
end case;
elsif sel="00" then --9.99kHz檔小數(shù)點(diǎn)
case c is
when "00"=>tp<=q2;
led0<='0'&led;
when "01"=>tp<=q3;
led1<='0'&led;
when "10"=>tp<=q1;
led2<='1'&led;
when others=>null;
end case;
end if;
end if;
end if;
end process;
end body_ym;
 設(shè)置0~2s 輸出為1017,溢出,LED2輸出F的段碼,兩外兩個(gè)消隱。 設(shè)置2s后輸出217,按照(量程選擇)sel=0時(shí),為0~9.99khz,小數(shù)點(diǎn)在高位即led2[7]為1。 3.4 顯示模塊 Clk:動(dòng)態(tài)顯示觸發(fā)信號(hào),1khz每一個(gè)點(diǎn)亮一個(gè)數(shù)碼管,三個(gè)循環(huán),其頻率顯然大于人眼可識(shí)別。 Led0,led1,led2:為譯碼輸出的數(shù)碼管顯示信號(hào)。 Ledag,sel:為動(dòng)態(tài)顯示
library ieee;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity dynamic_display is port(clk:in std_logic;
ledag:out std_logic_vector(7 downto 0);
sel:out std_logic_vector(2 downto 0);
led0,led1,led2:in std_logic_vector(7 downto 0));
end dynamic_display;
architecture body_display of dynamic_display is
begin
process(clk)
variable c:std_logic_vector(1 downto 0) ;
begin
if clk'event and clk='1' then
if c="10"then c:="00";
else c:=c+1;
end if;
end if;
case c is
when"00"=>sel<="001";
ledag<=led0;
when"01"=>sel<="010";
ledag<=led1;
when"10"=>sel<="100";
ledag<=led2;
when others=>null;
end case;
end process;
end body_display;

4. 系統(tǒng)調(diào)試 4.1 系統(tǒng)總體仿真 系統(tǒng)總體輸入輸出引腳的定義及作用 仿真波形(可打。 M在0~6s 設(shè)置為1000Hz 讀取波形led為1.00kHz
M在6~12s 設(shè)置為100khz 讀取顯示應(yīng)為100.khz
M在6~12s 設(shè)置為1mhz Alarm 溢出報(bào)警 顯示為F 0
全部資料51hei下載地址:
頻率計(jì).zip
(3.3 MB, 下載次數(shù): 85)
2020-5-9 10:51 上傳
點(diǎn)擊文件名下載附件
|