Problem:
If signal frequency is higher than about 13Hz, it shows the exact value.
But if the signal is lower than 13Hz, the value is swing between the exact value and another value.
How to fix this problem. It's urgent situation for me.
Signal source is function generator. It works fine.
At long period inputs counter overflow is going to be an issue, as master clock/nstages will be less time than your input cycle time. You may have to capture the timer overflow flag in the SFR and tally overflows and do math calculations based on number of overflows and the counter value at the time of the ISR call. In a benchtop counter prescalers are used to multiply and divide rates as necessary to keep the count rate in the realm of repeatability and then the display is corrected to reflect the influence of the prescaler. You can tell the chip to use XTAL2 and configure a different timebase than the mpu clocks at. This approach with a few external line selector logic circuits would allow you to autorange as appropriate.
Are you clipping and squaring the incoming waveform? Square waves are easier to obtain accurate timing from, sinewaves are somewhat ambiguous as trigger levels are subject to incoming amplitude variations.
#include <FreqCounter.h>
void setup() {
Serial.begin(57600); // connect to the serial port
Serial.println("Frequency Counter");
}
long int frq;
Void loop() {
FreqCounter::f_comp= 8; // Set compensation to 12
FreqCounter::start(100); // 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);
}