frequency count with high accuracy

Hello all.

I'm am very new to arduino, so please forgive dumb questions. I have been reading page after page of data on using arduino as a freq counter but still can't seem to get anywhere.

Let's start at the beginning. I want to build a combo frequency counter and generator. The range will need to be between 10hz and 25khz. The generator will be piped out to a Bluetooth speaker and the counter will use a microphone.as a pickup an will also monitor output frequency of generator. The counter will tie to gps for its accuracy and I would like 8 to 12 digit display. (No sense of accuracy with out seeing it).

So, which Arduino board should I be looking at? Uno, mega?

Eventually I will use a 5 or 7 in display.

Thank you for any guidance.

Hi,

Welcome to the forum.

What is your electronics, programming, arduino, hardware experience?

What sort of accuracy do you require, what is the application?

Thanks.. Tom.. :slight_smile:

If you want an accurate 12 segment display then you are going to need a super accurate crystal located within a stable oven. Or an atomic clock because that's what you are asking for.

On the other-hand, if you want to be realistic and have a display that offers say 0.1% accuracy ( 1 part in 1,000) then you are looking for a device that can display say 0.01% or 1 part in 10,000 ie a 5 or 6 segment display.

Even then you are going to be looking at a pretty good crystal to act as a reference source driving a phase locked loop circuit

john12345:
Hello all.

I'm am very new to arduino, so please forgive dumb questions. I have been reading page after page of data on using arduino as a freq counter but still can't seem to get anywhere.

Let's start at the beginning. I want to build a combo frequency counter and generator. The range will need to be between 10hz and 25khz. The generator will be piped out to a Bluetooth speaker and the counter will use a microphone.as a pickup an will also monitor output frequency of generator. The counter will tie to gps for its accuracy and I would like 8 to 12 digit display. (No sense of accuracy with out seeing it).

So, which Arduino board should I be looking at? Uno, mega?

Eventually I will use a 5 or 7 in display.

Thank you for any guidance.

Now tell us what you actually want to do.

xyproblem.info

Thanks all for responding.

Tomgeorge: I am a pmel tech trained through the usaf. I've been in calibration for over 20 years mainly working on low freq, torque, force and pressure. I have some programing, but in vb and object pascal. I have no experiance with arduino.

I want to obtain accuracy that is easily e x 10-10 and the uncertainty can be calculated without major studies. I am planing to add a gps receiver that has a 1pps timing that a 10 MHZ reference can be derived (there's already a few out there).

I want to make a cal standard for audio level freqencys.

Jackrae, please see above about the gps.

Markt, I hope I clarified things.

Thanks all for responding.

Let me see if I understand this correctly.

You want to generate an audio sound , but you want to transmit the frequency for the sound via bluetooth. because the frequency transmitter is inside the "package" . The Bluetooth will receive the frequency (through the plastic wrapped around the package) and send it to the audio amplifier which will send the frequency to the speaker. A separate device will then search for the audio frequency , sending GPS coordinates as it does. When the "package" that was "dropped off" is located, the GPS coordinates are transmitted to the recovery team that dispatch the recovery vehicle to pickup the "package".

Does that sound about right ?

I want to make a cal standard for audio level freqencys.

Oh, my bad.

I found a sketch in Reply#11 of this post.

But for reasons I can't figure, it doesn't work. It compiles (with the timerone lib installed) but it doesn't do anything.

This one works.
The Timer1 initialize parameter:

Timer1.initialize(30);

(30 uS period) produces a frequency of 33.333 kHz.

/*
 *  Timer1 library example
 *  June 2008 | jesse dot tane at gmail dot com
 */

#include "TimerOne.h"

void setup()
{
  pinMode(10, OUTPUT);
  Timer1.initialize(30);         // initialize timer1, and set a 1/2 second period
  Timer1.pwm(9, 512);                // setup pwm on pin 9, 50% duty cycle
  Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
}

void callback()
{
  digitalWrite(10, digitalRead(10) ^ 1);
}

void loop()
{
  // your program here...
}


I found a frequency counter sketch here:

And this one works:

// Arduino UNO DDS

#include <PWM.h>

int32_t frequency_9 = 4000; //frequency (in Hz)
int32_t frequency_3 = 3000; //frequency (in Hz)
 

void setup()
{

InitTimersSafe(); 

SetPinFrequencySafe(9, frequency_9);
SetPinFrequencySafe(3, frequency_3);
 
}

void loop()
{
 
 int dutyC =512; // Duty Cycle 0 (0%) - 1023(100%)
 pwmWrite(9, dutyC / 4);
 pwmWrite(3, dutyC / 4);
 delay(30);
 
 }
Frequency Counter
0
4000
3996
3996
3996
3996
3996
3996
3995
3995
3996
3996
3996
3996
3996

Frequency Counter

#include <FreqCounter.h>

void setup() {
  Serial.begin(57600);                    // connect to the serial port
  Serial.println("Frequency Counter");
}

long int frq =0;
void
loop() {

 FreqCounter::f_comp= 8;             // Set compensation to 12
 FreqCounter::start(1000);            // Start counting with gatetime of 100ms
 while (FreqCounter::f_ready == 0)         // wait until counter ready
 
 frq=FreqCounter::f_freq;            // read result
 Serial.println(frq);                // print result
 delay(20);
}

See attached scope screenshot.
Note, the filename of the Frequency generator is based on the period parameter of 30 uS, which equates to 33,333 Hz.

The attached serial terminal capture file using Clear Terminal shows a frequency of 33,298 (35 Hz lower than scope reading and period parameter.

Frequency Counter

33332
33298
33298
33298
33298
33298
33297
33298
33298
33298
33297
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33299
33298
33299
33298
33298
33298
33298
33298
33298
33298
33298
33298
33298
33299
33298
33298
33298
33298
33298
33298
33298
33298
33298
33299
33298
33298
33298
33299
33298

It's only 5 digits accuracy and it's off by 0.1060 %.
NOTE: The very FIRST reading is right on the money. All the rest are off by 35 Hz.
When I changed the frequency to 9900 Hz T = (101 us), the reading was 9891 (10 Hz off). (again 0.1 % error)

ClearTerminal_Capture__Frequency counter reading.txt (528 Bytes)

Raschemmel, no problem. It's nothing like that. I gotta check one device with a freq counter and another with an audio tone generator that will be sent to a speaked via bluetooth. I'll achieve high accuracy with a gps receiver. Hopefully one unit. All controlled through a touch screen display.

I'll achieve high accuracy with a gps receiver

How so ?

Gps single is timed to an accuracy E x 10 to the -13. It is THE most accurate frequency source there is. Anyone can read that signal and use the timing signal. (1 pps). There are Senegal projects doing that now so I know it can be done.

Gps single is timed to an accuracy E x 10 to the -13. It is THE most accurate frequency source there is. Anyone can read that signal and use the timing signal. (1 pps). There are Senegal projects doing that now so I know it can be done.

I understand that GPS by it's very nature, is timing accuracy based technology because it works by triangulating the timing signals. Based on your wording, it sounds like this is something you have never yet done. So if I understand you correctly , the GPS doesn't check anything, but rather is the reference source and knowing it's frequency, you can compare a measured frequency and calibrate the measuring device until it returns the correct frequency sent by the GPS ?

On a side note, I was USAF , (659th Tac Wing) stationed in Tachikawa , Japan during the Vietnam War.
(69-71) as a Medical Service Specialist (SGT) (Hospital Corpsman, assigned to ICU WARD)

1 part in 10^10 for a 10kHz tone is about 30 degrees of phase change per day. That's nothing to do
with audio, the human ear is not that sensitive (!).

Phase lags/leads in an audio path are dominated by the Q of the speaker resonances, delays due
to the slow speed of sound in air, and similar.

john12345:
Gps single is timed to an accuracy E x 10 to the -13. It is THE most accurate frequency source there is. Anyone can read that signal and use the timing signal. (1 pps). There are Senegal projects doing that now so I know it can be done.

The 1 PPS from a GPS has a long term drift rate on the order of 10E-13, but there is a great deal of short term jitter in GPS time measurement so one needs to use the GPS signal to discipline a clock with good short term stability. A GPS Rubidum disciplined oscillator will get you in the neighborhood of 10E-11. 10E-13 instantaneous is Cesium Beam lab standard territory, thus, while it is possible to do this, it requires (last time I looked) a ~$70k instrument.

The question still is why you think you need this kind of accuracy in measuring an audio signal. Even if your receiver/frequency counter were that good, you'd need another precision reference at the audio transmit end because the bluetooth link is going to corrupt your source signal to maybe 10e-6 at best.

That is how I'm gonna use the gps. As a 10 MHz reference for the couner.

Raschelle, thank you for your service.

I know the human ear can not tell the difference between 5001.0004 Hz and 5001.0006, but the equipment I need to test does. And it is designed to work from about 800 Hz to 8 khz. (Audio range)

There are a lot of possible sources of a reference signal, but calculating their uncertainty of the signal is hard to calculate in lab conditions, and this project must be portable. The gps signals uncertainty will not change because of things like outside temp.

All of the frequency counters that are portable do not have the accuracy or resolution . And any counter with accuracy is not portable or cost thousands.

I can use a mic and the counter to monitor the output of the generator. I have the needed equipment to certify the entire system. I know gps is a bit overkill like a bazooka flyswatter, but it solves many issues for me.

Thanks for all the great discussion.

Is this for calibrating USAF equipment ?

No, although I can see the potential...

I guess the main question is if there is an arduino board capable of accuracy and resolution.

If one 8-bit processor won't cut it, I doubt any 8-bit processor board will.

Doesn't matter if its one bit or 64 bit, the issue is not processor power, its timing accuracy. Standard
Uno's have no crystal so are ruled out (unless you replace the ceramic resonator by hand).

There is a guy that created a frequency reference with an arduino and gps module. So I don't think it's a timing issue.

The big thing is to alter the circuit to be counting in the needed lower frequency range and to display the digits.

http://www.google.com/url?sa=t&source=web&cd=1&rct=j&q=arduino%20frequency%20reference%20gps&ved=0ahUKEwiow8nwt97MAhUJPiYKHQk0AowQFggxMAA&url=http%3A%2F%2Fwww.knology.net%2F~gmarcus%2FVFO%2FGPS_Sig_Gen_v1_1.pdf&usg=AFQjCNExogliBBykyw1Kmi3X4EXmxBYgvQ

Crossroads: I think I know the answer to this, but I want to make sure...how did you conclude that 8 bits might not be enough and all the comparisons I keep running into don't talk about bits. Do you have any data as to which board has what bits?

Thanks

On an UNO, I've tested the FreqMeasure Library with a 100kHz clock signal connected to pin 8. This uses the input capture unit and timer/counter 1 to achieve the highest accuracy possible and is unaffected by any variance in MCU cycles due to entering and leaving an interrupt and processing pending interrupts. I got repeatable results representing 160 UNO clock ticks (10µs).

In the link you've provided, it's curious they didn't use the input capture feature as there's a data line connected to pin 8 instead.

Check out the 16-bit Timer/Counter1 and input capture unit starting on page 111 here.