从原理图我们可以看到,当en变化时,实际闸门信号finish(start)待检测到待测频率上升沿时才会变化,这就保证了在闸门信号内,我们测量的是待测频率的整数倍。
代码如下:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity frequency is
port(
bclk:in std_logic; --输入标准频率
tclk:in std_logic; --输入待测频率
reset:in std_logic; --高电平复位
en:in std_logic; --门限信号
finish:out std_logic; --结束计数信号,下降沿结束
dataout:out std_logic_vector(127 downto 0));
end frequency;
architecture behav of frequency is
signal start :std_logic:='0';
signal bzq:std_logic_vector(31 downto 0); --标准频率计数
signal tsq:std_logic_vector(31 downto 0); --待测频率计数
signal mkh:std_logic_vector(31 downto 0); --高电平计数
signal mkl:std_logic_vector(31 downto 0); --低电平计数
begin
dataout<=bzq&tsq&mkh&mkl; --128位数据输出
STAET: process(tclk,reset)
begin
if reset='1' then start<='0';
elsif tclk'event and tclk='1' then
start<=en;
end if;
end process;
finish<=start;
BZH: process(bclk,reset)
begin
if reset='1' then bzq<=(others=>'0');
elsif bclk'event and bclk='1' then
if start='1' then bzq<=bzq+1;
end if;
end if;
end process;
TCH: process(tclk,reset)
begin
if reset='1' then tsq<=(others=>'0');
elsif tclk'event and tclk='1' then
if start='1' then tsq<=tsq+1;
end if;
end if;
end process;
MKH1: process(bclk,reset,start,tclk)
begin
if reset='1' then
mkh<=(others=>'0');
mkl<=(others=>'0');
else
if start='1' then
if bclk'event and bclk='1' then
if tclk='1' then mkh<=mkh+1;
else mkl<=mkl+1;
end if;
end if;
end if;
end if;
end process;
end behav;
网友评论