【文章內(nèi)容簡介】
00。 begin if clock39。event and clock=39。139。 then if t1=50 then t1:=1。 q1 = not q1。 掃描信號 if t2=400 then t2:=1。 q2 =not q2。 else t2:=t2+1。 end if。 else t1:=t1+1。 end if。 end if。 end process。 clk_div1 =q1。 clkq =q2。end syn。編譯成功后生成元件圖如下:仿真時設(shè)置總時間為4s,對clock引腳輸入設(shè)置成時間信號,周期是25ns,則其頻率為40kHZ。經(jīng)過分頻后產(chǎn)生1HZ的基準信號,從clkq輸出。仿真波形如圖下圖:輸入端clk收到1Hz信號后,其輸出端testen控制各個t10的使能,clr_t控制各個t10的清零,load控制鎖存器內(nèi)數(shù)據(jù)的輸出。library ieee。use 。use 。entity testpl is port(clk:in std_logic。1Hz信號 tsten:out std_logic。計數(shù)器使能信號 clr_t:out std_logic。計數(shù)器清零信號 load:out std_logic)。鎖存器輸出控制信號end testpl。architecture art of testpl is signal div2clk:std_logic。begin process(clk) begin if clk39。event and clk=39。139。then div2clk=not div2clk。 div2clk為2Hz end if 。 end process。 process (clk ,div2clk) begin if( clk=39。039。and div2clk=39。039。)then clr_t=39。139。 當div2clk與clk同時為零時計數(shù)器清零 else clr_t=39。039。 當div2clk處于的高電平時計數(shù)器計數(shù) end if。 end process。 load=not div2clk。 鎖存器輸出與計數(shù)器使能信號反相 tsten=div2clk。 end art。編譯成功后生成元件圖如下:從測頻控制信號發(fā)生器模塊的仿真圖,很鮮明的給出了時鐘信號與計數(shù)允許信號tsten、清零信號clr_t和鎖存信號load的關(guān)系,從仿真圖可以看出計數(shù)允許信號、清零信號和鎖存信號與變量Q之間所存在的相對應(yīng)的關(guān)系。仿真結(jié)果如下圖所示:有一時鐘使能輸入端en,用于鎖定計數(shù)值。當高電平1時允許計數(shù)器計數(shù),低電平0時禁止計數(shù)。多位十進制計數(shù)器時,最低位的計數(shù)器的clk端輸入被測信號,各計數(shù)器的進位輸出端c10將信號輸?shù)较乱晃皇M制計數(shù)器t10的輸入端clk,最高位十進制計數(shù)器t10的進位輸出端c10給carry_out,進行報警提示(超出量程)。library ieee。use 。use 。entity t10 is port(clk,clr,en: in std_logic。 clk:計數(shù)器時鐘,clr:清零信號,en:計數(shù)使能信號 q: out std_logic_vector(3 downto 0)。q:4位計數(shù)結(jié)果輸出 c10: out std_logic)。 計數(shù)進位end t10。architecture art of t10 issignal cqi: std_logic_vector(3 downto 0)。begin process (clk,clr) begin if clr=39。139。 then cqi=0000。 當輸入的clr_t為低電平0時清零 elsif clk39。event and clk=39。139。 then if en=39。139。 then 當輸入的tesen為高電平1時允許計數(shù) if (cqi9) then cqi=cqi+1。 else cqi=0000。 等于9則計數(shù)器清零 end if。 當輸入的tesen為低電平0時禁止計數(shù),鎖定計數(shù)值 end if。 end if。end process。產(chǎn)生進位process(cqi) begin if cqi=1001 then c10=39。139。 當加的9時產(chǎn)生進位輸出 else c10=39。039。 end if。end process。q=cqi。end art。在項目編譯仿真成功后,用于以下的頂層設(shè)計。編譯成功后生成元件圖如下:在源程序中c10是計數(shù)器進位輸出;q[3..0]是計數(shù)器的狀態(tài)輸出;clk是被測信號轉(zhuǎn)換后的矩形脈沖輸入端;clr是復(fù)位控制輸入端,當clr=1時,q[3..0]=0;en是使能控制輸入端,當en=1時,計數(shù)器計數(shù),當en=0時,計數(shù)器保持狀態(tài)不變。編譯成功后進行仿真,其仿真波形如下: 24位鎖存器將已有24 位bcd碼存在于此模塊的輸入口din[23..0],在信號load的上升沿后即被鎖存到寄存器reg24b的內(nèi)部,并由reg24b的輸出端dout[23..0]輸出,設(shè)置鎖存器的好處是,數(shù)碼管上顯示的數(shù)據(jù)穩(wěn)定,不會由于周期性的清零信號而不斷閃爍。library ieee。use 。use 。entity reg24b is port (load: in std_logic。輸出鎖存控制信號 din: in std_logic_vector(23 downto 0)。 dout: out std_logic_vector(23 downto 0))。end reg24b。architecture art of reg24b isbegin process(load,din) begin if load39。event and load=39。139。then load為高電平時teten為低電平,計數(shù)器禁止 dout=din。 鎖存輸入的數(shù)據(jù) end if。 end p