数字频率计原理功能
功能原理:该频率计可以测量1HZ――999999HZ信号频率,并在六位数码管上显示.该系统包括标准时钟发生器,控制器,计数器,锁存器,扫描电路及译码电路六个模块构成.
当系统正常工作时,标准时钟发生器提供的1 Hz的输入信号,经过控制模块进行信号的变换,产生计数信号,被测信号送入计数模块,计数模块对输入的矩形波进行计数,将计数结果送入锁存器中,保证系统可以稳定显示数据,译码电路将二进制表示的计数结果转换成相应的能够在七段数码显示管上可以显示的十进制结果。在数码显示管上可以看到计数结果.
ctrl为控制模块。ctrl的计数使能信号能产生一个1 s宽的周期信号,并对频率计的每一计数器CNT10的en使能端进行同步控制:当EN高电平时允许计数、低电平时停止计数。
latch为锁存器。在信号Load的上升沿时,立即对模块的输入口的数据锁存到Latch的内部,并由输出端q输出,然后,七段译码器可以译码输出。在这里使用了锁存器,好处是可以稳定显示数据,不会由于周期性的清零信号而不断闪烁。
count10为十进制计数器。有一时钟使能输入端en,用于锁定计数值。当高电平时允许计数,低电平时禁止计数。图1中将6个十进制计数器CNT10级联起来实现6位十进制计数功能。
decode为七段译码显示驱动电路,可以将频率计数的结果译成能在数码管上显示相对应的阿拉伯数字,便于读取测量的结果。
为了实现系统功能,测频控制信号发生器、计数器、锁存器存在一个工作时序的问题,设计时需要综合考虑。
图3给出了系统的工作时序。图2中CLK是由图1中标准时钟发生器产生的频率为1 Hz的标准时钟信号,当控制器ctrl的en端为高电平时允许计数、低电平时停止计数,在停止计数期间,控制器ctrl的Load端产生一个上升沿,将计数器在前1 s的计数值锁存进24b锁存器latch中,并由6个7段译码器将计数结果译出稳定显示。锁存信号之后经过半个clk周期,测频控制信号发生器clr的端产生一个上升沿,对计数器进行清零。为下1 s的计数操作做准备。
各模块的VHDL程序如下:
标准时钟分频器:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fpq0 is
Port ( clk0 : in std_logic;
cp : out std_logic);
end fpq0;
architecture Behavioral of fpq0 is
signal a: integer range 0 to 9999999;
begin
process(clk0)
begin
if (clk0 'event and clk0='1')then
if a=9999999 then
a<=0;
else a<=a+1;
end if;
case a is when 0 to 4999999=>cp<='1';
when 5000000 to 9999999=>cp<='0';
end case;
end if;
end process;
end Behavioral;
待测分频器:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dcfpq is
Port ( clk0 : in std_logic;
cp : out std_logic);
end dcfpq;
architecture Behavioral of dcfpq is
signal a: integer range 0 to 49;
begin
process(clk0)
begin
if (clk0 'event and clk0='1')then
if a=49 then
a<=0;
else a<=a+1;
end if;
case a is when 0 to 24=>cp<='1';
when 25 to 49=>cp<='0';
end case;
end if;
end process;
end Behavioral;
控制模块:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ctrl is
Port ( cp : in std_logic;
reset : in std_logic;
en : out std_logic;
clr : out std_logic;
load : out std_logic);
end ctrl;
architecture Behavioral of ctrl is
signal b:integer range 0 to 1;
begin
process(cp,reset)
begin
if reset ='1' then en<='0'; clr<='0'; load<='0';
elsif (cp 'event and cp='1') then
if b=1 then b<=0;
else b<=b+1;
end if;
case b is when 1=>en<='0';
load<='1';144
数字频率计原理
clr<='1' ;
when 0=>en<='1';
load<='0';
clr<='0';
end case;
end if;
end process;
end Behavioral;
十进制计数器:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity count10 is
Port ( reset : in std_logic;
enable : in std_logic;
clk : in std_logic;
cout : out std_logic;
q : out std_logic_vector(3 downto 0));
end count10;
architecture Behavioral of count10 is
signal q_tmp: std_logic_vector(3 downto 0);
begin
process(clk)
begin
if (clk 'event and clk='1')then
if reset='1' then
q_tmp<="0000";
elsif enable='1' then
if q_tmp="1001" then
q_tmp<="0000";
else q_tmp<=q_tmp+1;
end if;
end if;
end if;
q<=q_tmp;
if (q_tmp="1001" and enable='1') then cout<='1';
else cout<='0';
end if;
end process;
end Behavioral;
锁存器
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity latch is
Port ( data : in std_logic_vector(23 downto 0);
oe: in std_logic;
g : in std_logic;
q : out std_logic_vector(23 downto 0));
end latch;
architecture Behavioral of latch is
signal q_tmp: std_logic_vector (23 downto 0);
begin
process (oe,g)
begin
if oe='0' then
if g'event and g='1' then
q_tmp<=data;
end if;
else q<=q_tmp;
end if;
end process;
end Behavioral;
扫描电路:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity scan is
Port ( clk0: in std_logic;
vin : in std_logic_vector(23 downto 0);
vout : out std_logic_vector(3 downto 0);
d : out std_logic_vector(2 downto 0));
end scan;
architecture Behavioral of scan is
signal c: integer range 0 to 5;
begin
process(clk0)
begin if (clk0 'event and clk0='1') then
if c=5 then c<=0;
else c<=c+1;
end if;
case c is when 0=>vout<=vin(3)&vin(2)&vin(1)&vin(0);
d<="101";
when 1=>vout<=vin(7)&vin(6)&vin(5)&vin(4);
d<="100";
when 2=>vout<=vin(11)&vin(10)&vin(9)&vin(8);
数字频率计原理功能
d<="011";
when 3=>vout<=vin(15)&vin(14)&vin(13)&vin(12);
d<="010";
when 4=>vout<=vin(19)&vin(18)&vin(17)&vin(16);
d<="001";
when 5=>vout<=vin(23)&vin(22)&vin(21)&vin(20);
d<="000";
end case;
end if;
end process;
end Behavioral;
译码电路:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity decode is
Port ( din : in std_logic_vector(3 downto 0);
dout : out std_logic_vector(6 downto 0));
end decode;
architecture Behavioral of decode is
begin
process(din)
begin
case din is when"0000"=>dout<="0111111";
when"0001"=>dout<="0000110";
when"0010"=>dout<="1011011";
when"0011"=>dout<="1001111";
when"0100"=>dout<="1100110";
when"0101"=>dout<="1101101";
when"0110"=>dout<="1111101";
when"0111"=>dout<="1011000";
when"1000"=>dout<="1111111";
when"1001"=>dout<="1101111";
when others=>dout<="0000000";
end case;
end process;
end Behavioral;
实验总结:
1:控制电路的EN,CLR输出要接缓冲器,否则不能驱动译码电路.
2:扫描分频器的输出频率要在200----1000HZ之间.
3:锁存器的G输入端应是跳变沿触发,否则频率不能锁定.
4:如果要测多个频率,可设计不同的分频器,并用多选一电路实现.
5六个十进制计数器在原理图上直接级联,如果在VHDL层面用PORTMAP语句实现,可以使原理图更简洁.