测量频率及占空比的频率计设计.docx

上传人:b****5 文档编号:12304433 上传时间:2023-04-18 格式:DOCX 页数:29 大小:493.87KB
下载 相关 举报
测量频率及占空比的频率计设计.docx_第1页
第1页 / 共29页
测量频率及占空比的频率计设计.docx_第2页
第2页 / 共29页
测量频率及占空比的频率计设计.docx_第3页
第3页 / 共29页
测量频率及占空比的频率计设计.docx_第4页
第4页 / 共29页
测量频率及占空比的频率计设计.docx_第5页
第5页 / 共29页
点击查看更多>>
下载资源
资源描述

测量频率及占空比的频率计设计.docx

《测量频率及占空比的频率计设计.docx》由会员分享,可在线阅读,更多相关《测量频率及占空比的频率计设计.docx(29页珍藏版)》请在冰豆网上搜索。

测量频率及占空比的频率计设计.docx

测量频率及占空比的频率计设计

简易数字频率计设计

一、设计任务与要求:

设计一个具有如下功能的简易频率计。

(1)基本要求:

a.被测信号的频率范围为1~20kHz,用4位数码管显示数据。

b.测量结果直接用十进制数值显示。

c.被测信号可以是正弦波、三角波、方波,幅值1~3V不等。

d.具有超量程警告(可以用LED灯显示,也可以用蜂鸣器报警)。

e.当测量脉冲信号时,能显示其占空比(精度误差不大于1%)。

(2)发挥部分:

a.修改设计,实现自动切换量程。

b.构思方案,使整形时,跳变阈值自动进行调节,以实现扩宽被测信号的幅值范围。

二、方案设计与论证:

(1)数字频率计概述:

数字频率计是直接用十进制数字来显示被测信号频率的一种测量装置。

它不仅可以测量正弦波、方波、三角波、尖脉冲信号和其他具有周期特性的信号的频率,而且还可以测量它们的周期。

经过改装,可以测量脉冲宽度,做成数字式脉宽测量仪;可以测量电容做成数字式电容测量仪;在电路中增加传感器,还可以做成数字脉搏仪、计价器等。

因此数字频率计在测量物理量方面应用广泛。

(2)数字频率计方案选择:

本设计要求的测频范围是1~20KHZ,可分1~9999HZ和10.00~20.00KHZ两个量程,有两种不同的方案实现量程的划分:

方案1:

将1HZCLK信号二分频,取分频后信号的高电平作为测频的1S闸门信号,测量结果有5位,当结果小于9999HZ时选择低四位由数码管显示输出,大于9999HZ且小于20KHZ时,选择高四位输出,大于20KHZ时,超量程指示灯亮。

通过选择高四位或低四位来实现量程的自动转换。

此方案的特点是实现方法简单,适合小范围的频率测量,但测频范围较大时,实现起来,测量速度较慢,还会造成所用元器件的浪费。

方案2:

由分频来实现量程的划分,将基准信号经分频得1HZ和10HZ的分频信号,设置一信号量SEL,初值为1HZ,将SEL信号二分频取分频后信号的高电平作为测频的闸门信号。

测频的量程为1~9999HZ时,SEL为1HZ,测频的闸门信号为1S;量程为10.00~20.00KHZ时,将SEL为10HZ,同时表示小数点的指示灯亮,测频的闸门信号为0.1S;当测量结果小于9999HZ时,SEL赋值为10HZ,测量结果大于9999HZ且小于20KHZ时,SEL赋值为10HZ,测量结果大于20KHZ时,超量程指示灯亮从而实现量程的自动转换。

此方案的特点是测频范围较小时,分频略显麻烦。

但总体实现起来较为可行。

比较两方案可知:

对于本设计,方案1较方案2简单,方案1结果有5位,按情况选择4位输出显示即可实现频率的测量和量程的自动转换;而方案2要经过分频略显麻烦。

但是,在本设计中,频率测量范围较小,量程划分也简单,所以,我选方案1进行设计。

方案一原理图:

方案二原理图:

(3)实验相关电路原理:

(1)设计原理:

a测频率:

数字频率计的核心是电子计数器。

电子计数器可以对脉冲数目进行累加运算,能把任意一段时间内的脉冲总数计算出并由数码管显示出来。

如某个时间间隔t内对周期性信号的累加计数值为N,则信号频率f为f=N/t 。

 因此,首先应将被测信号变成周期性的脉冲,脉冲形成电路就是起这个作用,其脉冲的重复频率等于被测信号频率。

脉冲形成后将它加到闸门电路的一个输入端A,闸门电路就是用来控制开和关的一种电路,当具有标准时间的闸门脉冲到达时,闸门便开启,允许由A进入的脉冲通过;闸门脉冲结束后,闸门便关闭,信号就不能通过。

闸门开启时通过的脉冲送到电子计数器进行计数,由装在面板上的数码管显示出来。

例如,时基信号的作用时间为1秒,闸门电路将打开1秒,若在这段时间内通过闸门电路的脉冲数目为1000个,则被测信号的频率就是1000Hz。

b测占空比:

测占空比有很多种方法,本设计采用多周期测量法其测量原理是:

预置的时间和被测信号同时输入到同步电路,在同步电路输出端得到一个与被测信号同步的闸门信号。

基准信号同时控制两个闸门的开启和关闭。

在相同的闸门开启时间内,两个计数器分别对被测信号的通过的高电平和低电平个数进行计数,对得出的结果做运算,得到的结果即为被测信号的占空比。

(2)超高速A/D、D/A板GW_ADDA说明:

GW_ADDA板含两片10位超高速DAC(转换速率最高150MHz)和一片8位ADC(转换速率最高50MHz),另2片3dB带宽大于260MHz的高速运放组成变换电路。

GW_ADDA板上所有的A/D和D/A全部处于使能状态,除了数据线外,任一器件的控制信号线只有时钟线,这有利于高速控制和直接利用MATLAB/DSPBuilder工具的设计。

GW_ADDA板上工作时钟必须由FPGA的I/O口提供,且DAC和ADC的工作时钟是分开的。

无法直接利用MATLAB和DSPBuilder进行自动流程的设计,优点是时钟频率容易变化,且可通过Cyclone中的PLL的到几乎任何时钟频率。

由此即可测试ADC和DAC的最高转换频率。

两个电位器可分别调协两个D/A输出的幅度(输出幅度峰峰值不可大于5V,否则波形失真);模拟信号从接插口的2针“AIN”输入,J1和J2分别是模拟信号输出的PA、PB口,也可在两挂钩处输出,分别是两个10位DA5651输出口。

注意,使用A/D,D/A板必须打开GW48-PK2主系统板上的+/-12V电源,用后关闭!

三、电路图及设计文件:

(1)系统电路图:

(2)系统的RTL级描述:

(3)系统的引脚锁定图

(4)程序源代码:

libraryieee;--输入信号模块

useieee.std_logic_1164.all;

entitycompis

port(signl:

instd_logic_vector(7downto0);

fout:

outstd_logic);

endcomp;

--signl为信号发生器产生的信号

architectureoneofcompis

begin

process(signl)

begin

if(signl>"00000000")then--判断输入信号不为0

fout<='1';--fout为以后电路的门

else--信号

fout<='0';

endif;

endprocess;

endone;

libraryieee;--自动切换量程模块

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entitycornais

port(clr,fin,en,key2,rst:

instd_logic;

ranin:

instd_logic_vector(15downto0);

alm:

outstd_logic;

dis_out:

bufferstd_logic_vector(15downto0));

endcorna;

architectureoneofcornais

signalc0,c1,c2,c3,c4:

std_logic_vector(3downto0);

begin

p1:

process(en,fin)

begin

ifrst='1'thenalm<='0';

elsifclr='1'then

c0<="0000";c1<="0000";c2<="0000";c3<="0000";c4<="0000";

elsiffin'eventandfin='1'then

ifen='1'then

ifc0<"1001"then

c0<=c0+1;

else

c0<="0000";

ifc1<"1001"then

c1<=c1+1;

else

c1<="0000";

ifc2<"1001"then

c2<=c2+1;

else

c2<="0000";

ifc3<"1001"then

c3<=c3+1;

else

c3<="0000";

ifc4<"0001"then

c4<=c4+1;

else

c4<="1111";

c3<="1111";

c2<="1111";

c1<="1111";--超过量程2KHZ时会报警,并

alm<='1';--且数码管显示为”FFFF”

endif;

endif;

endif;

endif;

endif;

else

c4<="0000";

c3<="0000";

c2<="0000";

c1<="0000";

c0<="0000";

alm<='0';

endif;

endif;

endprocessp1;

p2:

process(key2,ranin,c4)

begin

ifkey2='1'then

dis_out<=ranin;--若key2有效,则输出为占空比,否

elsifc4/="0000"then--则为显示频率

dis_out<=c4&c3&c2&c1;--c4不为“0000”时,量程最低位为

else--10HZ,记频率范围为0-2KHZ,c4为

dis_out<=c3&c2&c1&c0;--“0000”时,量程最低位为1HZ,记

endif;--频率范围为0-9999HZ

endprocessp2;

endone;

 

libraryieee;--记低电平个数木块

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitycount1is

port(enl,clr,clk0:

instd_logic;

loout:

bufferintegerrange1to600000);

endcount1;

architectureoneofcount1is

begin

process(enl,clr,clk0)

begin

ifclr='1'then

loout<=1;

elsif(clk0'eventandclk0='1')then

ifenl='1'then--当输入信号有效时,在clk0

loout<=loout+1;--上升沿来临时,记下低电

endif;--平个数

endif;

endprocess;

endone;

libraryieee;--记高电平个数模块

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitycount2is

port(enh,clr,clk0:

instd_logic;

hiout:

bufferintegerrange1to600000);

endcount2;

architectureoneofcount2is

begin

process(enh,clr,clk0)

begin

ifclr='1'then--clk0为实验板自带的12MHZ

hiout<=1;--信号

elsif(clk0'eventandclk0='1')then

ifenh='1'then--当输入信号有效时,在clk0

hiout<=hiout+1;--上升沿时记下高电平的个

endif;--数

endif;

endprocess;

endone;

libraryieee;--控制模块一

useieee.std_logic_1164.all;

entityctrlis

port(clk2:

instd_logic;

rst,load:

outstd_logic;

en:

bufferstd_logic);

endctrl;

architectureoneofctrlis

begin

process(clk2,en)

begin--clk2为试验箱自带的1HZ信号

ifclk2'eventandclk2='1'then

en<=noten;--以clk2二分频产生相反的en,rst

endif;--信号,用来作为自动切换量程模块

ifclk2='0'anden='0'then

rst<='1';--的使能信号和复位信号

else

rst<='0';

endif;

endprocess;

load<=noten;--对en取反得到load,作为锁存器模块

endone;--的允许锁存信号

libraryieee;--控制模块二

useieee.std_logic_1164.all;

entityctrl1is

port(fin:

instd_logic;

enl:

bufferstd_logic;

clr,load:

outstd_logic);

endctrl1;

architectureoneofctrl1is

signalct:

std_logic;

begin

process(fin,enl,ct)

begin

iffin'eventandfin='1'then

ct<=(notct);

endif;

iffin='1'andct='0'then

clr<='1';--clr为记低电平模块的复位信号

else

clr<='0';

endif;

ifct='1'andfin='0'then

enl<='1';--enl为记高电平模块的使能信号

else

enl<='0';

endif;

endprocess;

load<=(notct);--load为计算占空比模块的门控信号

endone;

libraryieee;--控制模块三

useieee.std_logic_1164.all;

entityctrl2is

port(fin:

instd_logic;

enh:

bufferstd_logic;

clr:

outstd_logic);

endctrl2;

architectureoneofctrl2is

signalct:

std_logic;

begin

process(fin,enh,ct)

begin

iffin'eventandfin='1'then

ct<=(notct);

endif;

iffin='0'andct='0'then

clr<='1';--clr为记高电平模块的复位信号

else

clr<='0';

endif;

ifct='1'andfin='1'then

enh<='1';--enh为记高电平模块的使能信号

else

enh<='0';

endif;

endprocess;

endone;

libraryieee;--译码显示模块

useieee.std_logic_1164.all;

entitydispis

port(key2,clk0:

instd_logic;

ran:

instd_logic_vector(7downto0);

dataout:

outstd_logic_vector(15downto0));

enddisp;

architectureoneofdispis

begin

process(key2,clk0)

begin

ifclk0'eventandclk0='1'then

if(key2='1')then--key2有效时,把计算的占空比

dataout<=ran&"00000000";--输出显示

endif;

endif;

endprocess;

endone;

libraryieee;--锁存器模块

useieee.std_logic_1164.all;

entityreg16is

port(load:

instd_logic;

datain:

instd_logic_vector(15downto0);

dataout:

outstd_logic_vector(15downto0));

endreg16;

architectureoneofreg16is

begin

process(load)

begin

ifload'eventandload='1'then

dataout<=datain;--锁存要输出的信息

endif;

endprocess;

endone;

libraryieee;--计算占空比模块

useieee.std_logic_1164.all;

useieee.std_logic_arith.all;

entityslovis

port(load:

instd_logic;

high,low:

inintegerrange1to600000;

ran:

outstd_logic_vector(7downto0));

endslov;

architectureoneofslovis

signala,b:

integerrange0to9;

signalranh,ranl:

std_logic_vector(3downto0);

begin

process(high,low)

begin--计算占空比

a<=(high*10)/(high+low);

b<=((high*10)rem(high+low))*10/(high+low);

endprocess;

process(a,b)

begin--把计算出来的占空比转换输出

ifload'eventandload='1'then

ranh<=conv_std_logic_vector(a,4);

ranl<=conv_std_logic_vector(b,4);

endif;

ran<=ranh&ranl;

endprocess;

endone;

libraryieee;--整形模块

useieee.std_logic_1164.all;

entityzhengxingis

port(clk0,a:

instd_logic;

q:

outstd_logic);

endzhengxing;

architectureoneofzhengxingis

begin

process(clk0)

begin

ifclk0'eventandclk0='1'then

q<=a;--对输入信号进行整形

endif;

endprocess;

endone;

libraryieee;--顶层文件

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

useieee.std_logic_arith.all;

entitydivis

port(clk0,clk2,key2,rst:

instd_logic;

signl:

instd_logic_vector(7downto0);

alm:

outstd_logic;

data:

outstd_logic_vector(15downto0));

enddiv;

--各个模块的元件例化声明

architectureoneofdivis

componentcompis

port(signl:

instd_logic_vector(7downto0);

fout:

outstd_logic);

endcomponent;

componentzhengxingis

port(clk0,a:

instd_logic;

q:

outstd_logic);

endcomponent;

componentctrlis

port(clk2:

instd_logic;

rst,load:

outstd_logic;

en:

bufferstd_logic);

endcomponentctrl;

componentreg16is

port(load:

instd_logic;

datain:

instd_logic_vector(15downto0);

dataout:

outstd_logic_vector(15downto0));

endcomponent;

componentctrl1is

port(fin:

instd_logic;

enl:

bufferstd_logic;

clr,load:

outstd_logic);

endcomponent;

componentctrl2is

port(fin:

instd_logic;

enh:

bufferstd_logic;

clr:

outstd_logic);

endcomponent;

componentcount1is

port(enl,clr,clk0:

instd_logic;

loout:

outintegerrange1to600000);

endcomponent;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1