Hello everyone!
I'm having some trouble regarding the accuracy of a frequency measurement of a 1 MHz signal. I'm using the FreqCount library from PJRC. I'm using an Arduino Mega.
Right now I have two problems:
-
I need an accuracy of 10 ppm.
-
The measure fluctuate a lot if there are temperature variations.
Both problems seems to be related to the 16 MHz resonator. It has a tolerance of 0.5%, which is ~5000 ppm. And the resonator is very sensible to temperature.
After looking here in the forum, searching on Google and talking with my friends, we reached to the possible solutions:
S1) Change the resonator with a better crystal oscillator. But I haven't found a good crystal with the same mounting type of the resonator.
S2) Use an external clock signal in the terminal XTAL. We chose to use Si5351A Clock Generator. But I still don't understand how to change the fuse bits to use an external clock signal of an Arduino Mega/Atmega2560.
S3) Use an external clock signal in a timer clock input terminal. There are only 02 terminals available as timer clock inputs: 38 (Timer 0) and 47 (Timer 5). Right now I use the terminal 47 to measure the frequency. So probably I'm using Timer 5 as a counter and Timer 5 uses the resonator as a time reference. The idea is to insert a good clock source (the same as solution 2) in Timer 0 and set it as the time reference for Timer 5. But I still have no idea on how to do it.
S4) Find or create a device that does the frequency measure and sends the results to my main Arduino. But I didn't find such device. Maybe I should build one using a simple microcontroller...
And here are my questions after all this:
Q1: Are these solutions feasible?
Q2: Are there other possible solutions?
Q3: How do I change the fuse bits to use an external clock signal? Is it possible to do it using Arduino IDE? Do I need to set a bootloader?
Q4: If solution S3 is feasible, how would I do it? I still don't understand very well the FreqCount library. Where should I start learning about it? Are there information in Atmega2560 datasheet that I should know first?
I will try to apply the solution S4 if the others fail.
And that's it. Thank you very much for your time and help!