Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2006434
  • 博文数量: 356
  • 博客积分: 8284
  • 博客等级: 中将
  • 技术积分: 4580
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-15 20:25
个人简介

天行健,君子以自强不息

文章分类

全部博文(356)

文章存档

2018年(1)

2016年(4)

2015年(13)

2014年(14)

2013年(2)

2012年(25)

2011年(43)

2010年(65)

2009年(189)

分类:

2011-05-29 15:15:13

很多人对等精度测频不是很了解,以前弄过,现在大致总结如下:
(注:硬件环境:DE2开发板 软件环境:quarter II 7.2)
整个系统总共有四个小的模块,分别是D_CON.vhd,lc_test.vhd,suo_fre.vhd,test_time.vhd
然后各自生成bsf模块文件。
新建一个工程,在新建的工程中添加上面的四个vhd文件和各自生成的bsf文件。
在新建的工程中新建一个bsf文件,然后将各个模块添加进来,连线效果图如下:
 
 
 
 
 
 
 

各个子模块代码如下:

D_CON.vhd

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity D_CON is
    port (
     MK: in STD_LOGIC;          
           FX :in  STD_LOGIC;      
           CON:OUT STD_LOGIC           
         );
end D_CON;
architecture sc_arc of D_CON is
begin
  process(FX)
 
  begin
    if FX'event and FX='1'then
       CON<=MK;
    end if;
  end process;
end sc_arc;

test_time.vhd

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity test_time is
    port (
  clk_i: in STD_LOGIC;
  clk_25MHz_o : out STD_LOGIC;
  clk_10MHz_o : out STD_LOGIC;
  CLK_5Mhz_o: out STD_LOGIC;
  clk_1MHz_o : out STD_LOGIC;
  clk_200KHz_o : out STD_LOGIC;
  clk_1KHz_o : out STD_LOGIC;
  clk_500Hz_o : out STD_LOGIC;
  clk_100Hz_o : out STD_LOGIC;
  clk_10Hz_o : out STD_LOGIC;
  clk_2Hz_o : out STD_LOGIC;
  clk_1Hz_o : out STD_LOGIC;
  clk_2s_o : out STD_LOGIC
    );
end test_time;

architecture test_time_arch of test_time is
 signal clk_25MHz,clk_5MHz: STD_LOGIC;
 signal clk_10MHz : STD_LOGIC;
 signal clk_1MHz : STD_LOGIC;
 signal clk_200KHz : STD_LOGIC;
 signal clk_1KHz : STD_LOGIC;
 signal clk_500Hz : STD_LOGIC;
 signal clk_100Hz : STD_LOGIC;
 signal clk_10Hz : STD_LOGIC;
 signal clk_2Hz : STD_LOGIC;
 signal clk_1Hz : STD_LOGIC;
 signal clk_2s : STD_LOGIC;
 
begin
    clk_25MHz_o <= clk_25MHz;
     clk_5MHz_o <= clk_5MHz;
 clk_10MHz_o <= clk_10MHz;
 clk_1MHz_o <= clk_1MHz;
 clk_200KHz_o <= clk_200KHz;
 clk_1KHz_o <= clk_1KHz;
 clk_500Hz_o <= clk_500Hz;
 clk_100Hz_o <= clk_100Hz;
 clk_2Hz_o <= clk_2Hz;
 clk_1Hz_o <= clk_1Hz;
 clk_2s_o <= clk_2s;
process( clk_i )
variable t : integer range 0 to 5;
begin
 if ( clk_i 'event and clk_i = '1' ) then
  if ( t = 1 ) then
   t := 0;
   clk_25MHz <= '1';
  else
   t := t + 1;
   clk_25MHz<='0';
  end if;  
 end if;
end process; 

process( clk_i )
variable t : integer range 0 to 5;
begin
 if ( clk_i 'event and clk_i = '1' ) then
  if ( t = 4 ) then
   t := 0;
   clk_10MHz <= '1';
  else
   t := t + 1;
   clk_10MHz<='0';
  end if;  
 end if;
end process;

process( clk_i )
variable t : integer range 0 to 5;
begin
 if ( clk_i 'event and clk_i = '1' ) then
  if ( t = 9 ) then
   t := 0;
   clk_5MHz <= '1';
  else
   t := t + 1;
   clk_5MHz<='0';
  end if;  
 end if;
end process;

process( clk_i )
variable t : integer range 0 to 24;
begin
 if ( clk_i 'event and clk_i = '1' ) then
  if ( t = 24 ) then
   t := 0;
   clk_1MHz <= not clk_1MHz;
  else
   t := t + 1;
  end if;  
 end if;
end process;


process( clk_1MHz )
variable t : integer range 0 to 499;
begin
 if ( clk_1MHz 'event and clk_1MHz = '1' ) then
  if ( t = 499 ) then
   t := 0;
   clk_1KHz <= not clk_1KHz;
  else
   t := t + 1;
  end if;  
 end if;
end process;

process( clk_1MHz )
variable t : integer range 0 to 4;
begin
 if ( clk_1MHz 'event and clk_1MHz = '1' ) then
  if ( t <3  ) then
   clk_200KHz <= '0';
  else
   clk_200KHz <= '1';
  end if;  
  
  if ( t = 4  ) then
   t :=0;
  else
   t := t + 1;
  end if;
 end if;
end process;

process( clk_1KHz )
variable t : integer range 0 to 4;
begin
 if ( clk_1KHz 'event and clk_1KHz = '1' ) then
  if ( t = 4 ) then
   t := 0;
   clk_100Hz <= not clk_100Hz;
  else
   t := t + 1;
  end if;  
 end if;
end process;

process( clk_1KHz )
variable t : integer range 0 to 1;
begin
 if ( clk_1KHz 'event and clk_1KHz = '1' ) then
  if ( t = 1 ) then
   clk_500Hz <= not clk_500Hz;
  end if;  
  t := t + 1;
 end if;
end process;

process( clk_100Hz )
variable t : integer range 0 to 4;
begin
 if ( clk_100Hz 'event and clk_100Hz = '1' ) then
  if ( t = 4 ) then
   clk_10Hz <= not clk_10Hz;
   t := 0;
  else
   t := t + 1;
  end if;  
 end if;
end process;

process( clk_100Hz )
variable t : integer range 0 to 24;
begin
 if ( clk_100Hz 'event and clk_100Hz = '1' ) then
  if ( t = 24 ) then
   clk_2Hz <= not clk_2Hz;
   t := 0;
  else
   t := t + 1;
  end if;  
 end if;
end process;
 
process( clk_2Hz )
variable t : integer range 0 to 1;
begin
 if ( clk_2Hz 'event and clk_2Hz = '1' ) then
  if ( t = 1 ) then
   clk_1Hz <= not clk_1Hz;
   t := 0;
  else
   t := t + 1;
  end if;  
 end if;
end process;
 
process( clk_1Hz )
variable t : integer range 0 to 1;
begin
 if ( clk_1Hz 'event and clk_1Hz = '1' ) then
  if ( t = 1 ) then
   clk_2s <= not clk_2s;
   t := 0;
  else
   t := t + 1;
  end if;  
 end if;
end process;
 
end test_time_arch;

lc_test.vhd

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
use IEEE.std_logic_arith.all;

entity lc_test is
    port (
     clr,fs,door: in STD_LOGIC;                          
           freq:out std_logic_vector(31 downto 0)
         );
end lc_test;

architecture corn_arc of lc_test is
signal t2: std_logic_vector(31 downto 0);
signal fs_test:INTEGER range 0 to 100000000;
begin
   process(fs,clr)-- N1
    variable t :std_logic_vector(31 downto 0);
    begin
      if(clr='0') then
          t:=(OTHERS=>'0');
      elsif(fs'event and fs='1') then
        if(door='1') then
         t:=t+1;
        --else
        -- t:=(OTHERS=>'0');
        end if; 
     end if;
     freq<=t;
   end process;
end corn_arc;

 

suo_frq.vhd

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity suo_frq is
    port (
     en: in STD_LOGIC;          
           data_i : in std_logic_vector(31 downto 0);                
        data_o:out  std_logic_vector(31 downto 0)
         );
end suo_frq;

architecture sc_arc of suo_frq is
begin
  process(en)
  begin
    if en'event and en='1'then
       data_o<=data_i;
    end if;
  end process;
end sc_arc;

需要说明的是:

连线图中:

CLK_50是一个50M信号的输入引脚,大家也可以根据自己的具体的晶振的频率编写自己的分频模块test_time,只要有1hz和25Mhz的输出信号即可。

FX是被测信号的输入管脚,输入的数字电平的高逻辑是3.3v,低逻辑是0v。

FLAG_DOWN_OUT是输出管脚,连接到CPU的外部中断管脚,一旦测好一次数据,模块自己产生一个下降沿,使CPU产生外部中断,让CPU从NX_OUT以及NS_OUT这两根32位数据总线把数据读走。这里的CPU既可以是硬核,也可以是软核(例如NIOS II)。最后由CPU计算出频率:

  fre=(25000000.0/NS)*NX;//计算


上传编译成功的工程文件如下:

文件: my等精度测频模块.rar
大小: 1541KB
下载: 下载

阅读(3277) | 评论(0) | 转发(0) |
0

上一篇:GPS之上位机

下一篇:ARM下启动代码

给主人留下些什么吧!~~