Arduino Frequency counter library

Background:
I’m using this library
(http://www.pjrc.com/teensy/td_libs_FreqCount.html)
(the 3 files I attached other than FC.h) to find the frequency of an input sin wave to pin 47 of Arduino mega 2560 for senior design project. The sin wave will be changing between roughly 340 kHz and 380kHz (0-5 V) at a rate of 20 thousand times per second. My Arduino needs to translate 340kHz into 0’s and 380kHz into 1’s.

Problem:
I’ve tested it with a function generator and the frequency is accurate up to 8MHz! I need to sample the frequency several more times faster than the transmission bit rate (20kbits/sec) in order to reduce bit error rate and at least twice as fast (40kbits/sec) to get any accuracy at all.
BUT the frequency library, from what I can tell, can only update the frequency 1000 times a second. 40 times slower than the bare minimum sampling frequency…

When I look through the FreqCount.cpp and FreqCountTimers.h files I get lost.

Suggestions? Thanks in advance for any responses!

My code is FC

FC.h (1.09 KB)

FreqCount.cpp (2.77 KB)

FreqCount.h (260 Bytes)

FreqCountTimers.h (16.6 KB)

The Arduino Mega can probably not decode such a signal. I don't know if there is a hardware module that can decode it. Perhaps some kind of PLL decoder.

Can you tell us more ? What is creating that signal ? Why is that signal roughly 340 and 380 kHz ? Do you know the precise frequency ? Is it a continuous signal or bursts ? If you want to translate 340 kHz to '0' and 380 kHz to '1', then you have no information. Because the output will be 01010101010 and so on. Perhaps you want to measure the duration as well ? Is it a FM modulated signal of 360 kHz ? with a 20 kHz data rate ?

About 360 kHz is in the long wave radio range. A 20 kHz data rate is very high for such a low frequency. Can you show us a picture of the actual signal ?

I could absolutely tell you more but I didn't want to make it overly complicated haha!

-One of my group members is constructing a transmit circuit using a separate arduino and 555 timer I don't need to concern myself with that too much

-The two frequencies are by design. We are doing power line communication and the 300-400kHz range is optimal for noise reduction and other factors. Those two frequencies I mentioned are fairly arbitrary as long as they are in the range we are designing the transmit circuit for.

-The transmit signal will be in bursts of bit packets and not always transmitting though that is irrelevant at this stage

-There will be a language implemented for these packets later in the project it will [u]not[/u] be just pure alternating 10101010... sorry for bad explanation

-The transmit circuit will be switching between resistor values rapidly to produce a 1 or 0 frequency for a period of 1/20,000 seconds at a time and my arduino/receive circuit needs to detect these bits

-right now I'm just using a function generator to test the FreqCounter library functionality. My plans are to sample the frequency generated by the freqcounter functions to extract these 1's and 0's from an arbitrary signal produced from a transmit circuit my partner is developing separately.

My problem is that the input signal frequency will change 20,000 times a second and this freqcounter library seems to max out at sampling the frequency 1000 times a second and I don't know how to overcome this.

Thanks for the explanation. I understand the 300...400 kHz range. The 50 µs pulse is however very short. The FreqCount library is not for a burst and is already optimized, I don't want to mess with that. Your idea to sample with 40kHz is a theoretical approach, and I think that is not going to work. Perhaps code that waits for a burst and gives the frequency after the burst is gone might work. But I don't know how to do that.

It would help if those frequencies are fixed. The 555 seems the most unreliable part in this.

Have you tried SDR on a computer to see if it can be decoded easily ?

I'm not very familiar with radio signals and short burst of frequencies. I think you need extra hardware. Perhaps someone else knows how to deal with it.

The examples that I can find are for example for ultrasonic signals of 40 kHz, that is no where near 400 kHz. There might be Arduino code for metal detectors which use up to 500 kHz, I have not found that yet. When I search really hard with Google, then I find this topic... :o