基于賽靈思FPGA的頻率計(jì)設(shè)計(jì)
第四步,將測(cè)得的頻率鎖存,即設(shè)計(jì)鎖存器:
-------------------------------------------------------------------
-- 說(shuō)明: 鎖存器模塊
-- 文件: suocun.vhd
-- 作者:
-- 日期: 2012/04/09
-- 修改:
-- 軟件: Altera QuartusII 9.0
-- 芯片: Altera Cyclone FPGA (EP1C3T144C8)
-------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL; --運(yùn)算符重載的一個(gè)頭文件
--實(shí)體描述部分
ENTITY suocun IS
PORT( --端口聲明
RESET, CLK1HZ : IN STD_LOGIC;
AIN0,AIN1,AIN2,AIN3 : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
Q0,Q1,Q2,Q3 : OUT STD_LOGIC_VECTOR (3 DOWNTO 0)
);
END suocun;
--結(jié)構(gòu)體描述部分
ARCHITECTURE bhv OF suocun IS
BEGIN
PROCESS(CLK1HZ) --這里輸入的1HZ是來(lái)自控制模塊的LOAD,LOAD是1HZ的信號(hào)
VARIABLE T3,T2,T1,T0 : STD_LOGIC_VECTOR (3 DOWNTO 0);--定義變量
BEGIN
IF RESET = '0' THEN --復(fù)位信號(hào)為低電平有效,當(dāng)RESET=0時(shí),將所有值清零
T3 := 0000 ;
T2 := 0000 ;
T1 := 0000 ;
T0 := 0000 ;
ELSIF (CLK1HZ'EVENT AND CLK1HZ='1') THEN --根據(jù)題目要求,LOAD上升沿鎖存數(shù)據(jù)
T3:=AIN3;
T2:=AIN2;
T1:=AIN1;
T0:=AIN0;
END IF;
Q3 = T3;
Q2 = T2;
Q1 = T1;
Q0 = T0;
END PROCESS; --進(jìn)程結(jié)束
END bhv; --結(jié)束結(jié)構(gòu)體
最后是譯碼輸出在數(shù)碼管顯示:
-------------------------------------------------------------------
-- 說(shuō)明: 譯碼器設(shè)計(jì)
-- 文件: decoder.vhd
-- 作者:
-- 日期: 2012/04/09
-- 修改:
-- 軟件: Altera QuartusII 9.0
-- 芯片: Altera Cyclone FPGA (EP1C3T144C8)
-------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY decoder IS
PORT(
ain : IN STD_LOGIC_VECTOR (3 DOWNTO 0);
yout : OUT STD_LOGIC_VECTOR (6 DOWNTO 0)
);
END decoder;
ARCHITECTURE yimaqi OF decoder IS
BEGIN
PROCESS ( ain )
BEGIN
CASE ain IS
WHEN 0000 => yout= 0111111; --0
WHEN 0001 => yout= 0000110; --1
WHEN 0010 => yout= 1011011; --2
WHEN 0011 => yout= 1001111; --3
WHEN 0100 => yout= 1100110; --4
WHEN 0101 => yout= 1101101; --5
WHEN 0110 => yout= 1111101; --6
WHEN 0111 => yout= 0000111; --7
WHEN 1000 => yout= 1111111; --8
WHEN 1001 => yout= 1101111; --9
WHEN 1010 => yout= 1110111; --A
WHEN 1011 => yout= 1111100; --B
WHEN 1100 => yout= 0111001; --C
WHEN 1101 => yout= 1011110; --D
WHEN 1110 => yout= 1111001; --E
WHEN 1111 => yout= 1110001; --F
WHEN OTHERS => NULL;
END CASE;
END PROCESS;
END yimaqi;
評(píng)論