关于Arduino的 FreqCount Library

FreqCount requires the input frequency as a digital level signal on a specific pin.
FreqCount requires the input frequency as a digital level signal on a specific pin.

An amplifier may be needed if the input signal is a sine wave or small AC signal which can not directly drive a TTL logic level input.

Basic Usage

FreqCount.begin(GateInterval);
Begin frequency counting. GateInterval is the time in milliseconds for each measurement. Using 1000 provides direct frequency output without mulitplying or dividing by a scale factor.
FreqCount.available();
Returns true when a new measurement is available. Only a single measurement is buffered, so it must be read before the next gating interval.
FreqCount.read();
Returns the most recent measurement, an unsigned long containing the number of rising edges seen within the gating interval. There is no delay between gating intervals, so for example a 1000.5 Hz input (and perfectly accurate crystal osciallator) will alternate between 1000 and 1001 when used with a 1 second gate interval.
FreqCount.end();
Stop frequency counting. PWM (analogWrite) functionality may be used again.

Example Program

Open from the menu: File > Examples > FreqCount > Serial_Output

#include <FreqCount.h>

void setup() {
  Serial.begin(57600);
  FreqCount.begin(1000);
}

void loop() {
  if (FreqCount.available()) {
    unsigned long count = FreqCount.read();
    Serial.println(count);
  }
}

Interrupt Latency Requirements

FreqCount uses a timer interrupt for the gate interval. If another interrupt is running, or interrupts are disabled by the main program, response to the timer could be delayed. That will lengthen the gate interval, perhaps leading to counting more cycles. The next gate interval will be shorter (if normal interrupt response occurs), so a corresponding decrease will occur in the next measurement.
During USB startup on Teensy, activity from the PC can cause interrupts which interfere with FreqCount's gate interval. Other libraries which disable interrupts for long times, such as NewSoftSerial, can cause trouble.

FreqCount vs FreqMeasure
FreqCount: best for 1 kHz to 8 MHz (up to 65 MHz with Teensy 3.0 & 3.1)
FreqMeasure: best for 0.1 Hz to 1 kHz
FreqCount measures the number of cycles that occur during a fixed “gate interval” time. This works well for relatively high frequencies, because many cycles are likely to be counted during gate interval. At lower frequencies, very few cycles are counted, giving limited resolution.

FreqMeasure measures the elapsed time during a single cycle. This works well for relatively low frequencies, because a substantial time elapses. At higher frequencies, the short time can only be measured at the processor’s clock speed, which results in limited resolution.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一个非常简单但对您的实验室有用的设备。 硬件组件: Arduino Nano R3×1个×1个 通用晶体管NPN×1个 1N4148 –通用快速开关×3 4个电阻×1个 电容器类×1个 软件应用程序和在线服务: Arduino IDE 手动工具和制造机: 烙铁(通用) 频率计是一种显示周期性电信号频率的仪器。视频显示了这种仪器,其中频率值以复古风格显示在7段LED显示屏上,这也非常引人注目。 它可以测量矩形,正弦形和三角形的信号频率。它的测量范围是从几赫兹到6.5兆赫兹。有了“ FreqCount”和“ LedControl”库,代码很简单。该设备包含几个组件: -Arduinio Nano微控制器 -整形功放板 -8位7段显示 -和输入插孔 如果仅在矩形信号上测量频率,则可以省略输入电路(整形放大器),在这种情况下,我们将信号直接传送到Arduino的D5引脚。该仪器在整个范围内都非常精确,我们还可以通过以下简单步骤校准频率表: 在Arduino库文件夹中找到FreqCount库, 在FreqCount.cpp文件中找到以下行: #如果已定义(TIMER_USE_TIMER2)&& F_CPU == 12000000L 正确的浮点数= count_output * 0.996155; #如果已定义(TIMER_USE_TIMER2)&& F_CPU == 16000000L 浮点数正确= count_output * 1.000000; 其中1.000000是您的修正系数, 必须通过对频率表的输入施加1 MHz的频率来进行校正。 更改文件后,将新的草图上传到Arduino开发板。最后,频率表被内置在合适的塑料盒中,并且是电子实验室中的另一有用仪器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值