【正文】
960000HZ時,輸出頻率值為 ,誤差為: 960 000 959 995 100 % 052 %960000? ?? 當(dāng)輸入頻率值為 1000000HZ時,輸出頻率值為 ,其誤差為: 1 0 0 0 0 0 0 9 9 9 9 9 6 1 0 0 % 0 . 0 0 0 4 %1000000 ? ?? 其余的相對誤差計算方法一樣,分析結(jié)果可見,誤差都在 %左右,這個數(shù)很小,因此在一般精度的系統(tǒng)中,就可以應(yīng)用該頻率計來計數(shù)或測頻。可減少誤差對測 頻誤差影響。由公式 (3)可知,不管計數(shù)值 N多少,其最大誤差總是個計數(shù)單位,故稱“個字誤差”。由此可知,最大計數(shù)誤差為 1N?? 個數(shù)。 (a)、誤差 在測頻時,主門的開啟時刻與計數(shù)脈沖之間的時間關(guān)系是不相關(guān)的,所以它們在時間軸上的相對位置是隨機(jī)的。當(dāng)閘門時間為 1s時,測得結(jié)果如下: 序號 輸入( Hz) 輸出( KHz) 1 1 2 10 3 1000 4 10000 5 100000 6 100000 7 202100 8 300000 9 400000 10 500000 11 600000 12 700000 13 800000 14 900000 18 15 920210 16 960000 17 1000000 18 1000008 19 1000017 溢出 十、誤差分析 由上表可以看出實驗測量中存在誤差,誤差一方面來源于閘門時間 T,另一方面來源于計數(shù)器計得的數(shù)。引腳分配完畢后雙擊“ Generate programming”對所有程序進(jìn)行綜合,改正綜合過程中提示的錯誤和警告,然后運(yùn)行“ Configure Device”把程序下載到電路板上。 end and2_arc1 。 end and_2。 entity and_2 is port(clk1,f_hz:in std_logic。 use 。 模塊圖: 仿真波形圖: 八. 與門 源程序: library IEEE。 end process。 when others=seg_out=0111111。 when1000=seg_out=0000000。 when0110=seg_out=0000011。 when0100=seg_out=0011001。 when0010=seg_out=0100100。 case bcd_code is when0000=seg_out=1000000。 nc=en。 then seg_out=0111111。 architecture Behavioral of fre_s_decode is begin process(bcd_code,dp2,en,rst) begin if rst=39。 dot,nc:out std_logic )。 dp2,en,rst:in std_logic。 use 。 use 。 use 。 模塊圖: 仿真波形圖: 15 七、 7段譯碼顯示控制系統(tǒng) 六位十進(jìn)制數(shù)的 BCD碼相繼進(jìn)入 bcd_code,經(jīng) 7段譯碼輸出,顯示十進(jìn)制數(shù)。 end process。 end case。dp1=39。 count=000。dp1=sel(5)。 count=count+1。dp1=sel(4)。 count=count+1。dp1=sel(3)。count=count+1。dp1=sel(2)。count=count+1。dp1=sel(1)。count=count+1。dp1=sel(0)。139。 elsif clk39。)then 14 count=000。 begin process(rst,clk,sel,data_in_0,data_in_1,data_in_2,data_in_3,data_in_4,data_in_5) begin if(rst=39。 end mux。 dig:out std_logic_vector(2 downto 0)。 sel:in std_logic_vector(5 downto 0)。 data_in_4:in std_logic_vector(3 downto 0)。 data_in_2:in std_logic_vector(3 downto 0)。 data_in_0:in std_logic_vector(3 downto 0)。 use 。 use 。 use 。最終的輸出接譯碼器實現(xiàn)數(shù)字顯示。 end Behavioral。 end if。light=39。 else f_hz=39。light=39。)then f_hz=f100hz。 and p2=39。 and p1=39。 elsif(p3=39。light=39。 )then f_hz=f10hz。 and p3=39。 and p1=39。 elsif(p2=39。light=39。)then f_hz=f1hz。 and p3=39。 and p2=39。 architecture Behavioral of controler is begin process(f1hz,f10hz,f100hz,p1,p2,p3) begin if(p1=39。 dp:out std_logic_vector(5 downto 0))。 p1,p2,p3:in std_logic。 f10hz:in std_logic。 use 。 use 。 use 。 模塊圖: 仿真波形: 五,門控模塊 本模塊通過 p1,p2,p3三個開關(guān)來控制閘門時間,同時輸出位選信號 dig( 2:0)以及閘門標(biāo)志light。 latch=g2。 rst=(not f_hz) and (not g1) and (g2)。 end if。 end if。039。039。 architecture Behavioral of chepinkongzhi is signal g1,g2:std_logic。 11 rst,latch,gate:out std_logic)。 use 。 use 。 use 。鎖存信號之后,必須有一清零信號 clear 對計數(shù)器清零,為下一秒的計數(shù)操作準(zhǔn)備。當(dāng) Gate 為高電平時,允許計數(shù),為低電平時停止計數(shù),并保持其所計得脈沖數(shù)。計數(shù)清零信號也由測頻控制器變換后輸出,控制整個電路。 end rtl。 f1khz=clkout_1khz。 end if。)。 if count_1khz=48000 then count_1khz=(others=39。 else clkout_1khz=39。 if count_1khz24000 then clkout_1khz=39。)。)then count_1khz=(others=39。 P_F1KHZ:process(clk,clkout_1khz,rst) begin if(rst=39。 f100hz=clkout_100hz。 end if。)。 if count_100hz=480000 then count_100hz=(others=39。 else clkout_100hz=39。 if count_100hz240000 then clkout_100hz=39。)。)then count_100hz=(others=39。 P_F100HZ:process(clk,clkout_100hz,rst) begin if(rst=39。 f10hz=clkout_10hz。 end if。)。 if count_10hz=4800000 then count_10hz=(others=39。 else clkout_10hz=39。 if count_10hz2400000 then clkout_10hz=39。)。)then count_10hz=(others=39。 P_F10HZ:process(clk,clkout_10hz,rst) begin if(rst=39。 f1hz=clkout_1hz。 end if。)。 if count_1hz=48000000 then count_1hz=(others=39。 else clkout_1hz=39。 if count_1hz24000000 then clkout_1hz=39。)。)then count_1hz=(others=39。 begin P_F1HZ:process(clk,clkout_1hz,rst) begin if(rst=39。 signal count_1khz:std_logic_vector(26 downto 0)。 signal count_100hz:std_logic_vector(26 downto 0)。 signal count_10hz:std_logic_vector(26 downto 0)。 }} End of automatically maintained section architecture rtl of clk_div is signal count_1hz:std_logic_vector(26 downto 0)。 f1khz: out STD_LOGIC)。 f10hz: out STD_LOGIC。 clk: in STD_LOGIC。 use 。 use 。本設(shè)計石英振蕩器提供的標(biāo)準(zhǔn)頻率是 48MHz,采用計數(shù)器分頻輸出四個信號 1Hz, 10Hz, 100Hz, 1KHz。 end Behavioral。 end if。 d4_out=counter4。 d2_out=counter2。 d0_out=counter0。139。 architecture Behavioral of latch is begin process(f_hz,counter0,counter1,counter2,counter3,counter4,counter5) begin if f_hz39。 d0_out,d1_out,d2_out,d3_out,d4_out,d5_out:out std_logic_vector(3 downto 0))。 counter0,counter1,counter2,counter3,counter4,counter5:in std_logic_vector(3 downto 0)。 use 。 7 use 。 use 。由測頻控制模塊產(chǎn)生的 latch 信號來提供鎖存脈沖。 end Behavioral。 count_out4=m10_counter4。 count_out2=m10_counter2。 count_out0=m10_counter0。 end process。039。 end if。 end if。 end if。 m10_counter5= m10_counter5+1。 if m10_counter41001 then m10_counter4= m10_counter4+1。 else m10_counter3=0000。 m10_counter3= m10_counter3+1。 if m10_counter21001 then m10_counter2= m10_counter2+1。 else m10_counter1=0000。 m10_counter1= m10_counter1+1。)then if m10_counter01001 then m10_counter0= m10_counter0+1。event and clk2=39。 m10_counter5=0000。