paulvee / GPSDO-Monitoring

Monitoring a high precision 10MHz GPS disciplined oscillator (GPSDO)
MIT License
8 stars 0 forks source link

Reciprocal frequency counter #2

Open paulvdhoeven opened 1 year ago

paulvdhoeven commented 1 year ago

I just read the article about your GPSDO monitoring thing, and you mention several times that a reciprocal frequency counter is complex or expensive.

I do not agree with this. A reciprocal frequency counter is quite easy to implement in nearly any microcontroller.

  1. Put the input signal though some (adjustable) divider, for example a 74HC4040 ripple counter with an 74HC151 MUX.
  2. Select a suitable MUX setting for your "approximate measurement time".
  3. Create a free running counter in your uC (Higher clock is better, preferably count with F_CPU.
  4. On every period (either rising or falling flank, but be consequent) of the input, capture the timer value in a capture register.
  5. Also count overflows of your internal timer.

Now you have all information you need to calculate the input frequency to a quite high degree. There are some conditions that need a bit of careful programming. For example if the timer capture is done near an overflow, then it may be difficult to determine the exact amount of internal overflows of the timer in the frequency calculation. One way to get around this is to use two timers in your uC and connect both of them to the input signal, and then make sure there is an offset between those two timers.

A ripple counter has a quite significant delay, but it is not relevant as long as the delay is constant.

paulvee commented 1 year ago

Hi Paul, Thanks for the comments. While in principle you are correct, I am still under the impression that a reciprocal counter that can measure a 1ppm difference of a 10MHz clock is very difficult to do and not in the realm of a DIY project. I will be very interested in seeing an example of an instrument that has this precision. I have not found any.

Best regards, Paul

paulvdhoeven commented 1 year ago

Is there any background to that impression?

The math is really simple. If you want to measure a frequency with 1ppm accuracy with a reciprocal meter, you just have to adjust your gate time to acquire more then 1e6 pulses, and you have to know what your gate time is with the same accuracy. The uncertainty with using uC timers is 1 or 2 clock cycles of your uC, and the rest is determined by the reference clock and jitter. (if your uC has a PLL on it's crystal, that will have jitter too...)

I once wrote a simple program for an microcontroller to test this and put it on a breadboard, together with a bunch of crystal oscillators I had, and I got up 10ppm repeatable measurements quite easily. I did of course not have that accuracy on a breadboard. I also only used cheap 200ppm crystals, but the measurements were repeatable and the principle works. I think I could also measure temperature drift caused by handling the crystals with my fingers, but I'm not sure about that, it was 15+ years ago. I never finished the project because the frequency meter in my DSO is good enough for my purposes, and I just have no application where even the cost of a standard TXCO is justified, and the cost of decent frequency meters is mostly determined by the reference clock, prescaler, the box with power supply, display and buttons, certification and profit margins.

You write you're interested in an example, but have not found any. Have you looked? A simple search: https://github.com/search?q=reciprocal+frequency+counter

And one of the first examples that pops up is: https://github.com/ingbird64/Pi-Pico_FrequencyCounter

Which claims a resolution of "8 digits at 10s gate time", I have not verified it, but it seems very plausible.

paulvee commented 1 year ago

You are now getting a little condesending with "Is there any background to that impression?"and "Have you looked?" Of course I did, in 2020, and at that time I did not find any (serious) projects that can measure a resolution down to 1ppb, which is what my GPSDO is striving for. With the help of your links I now found a recent (still unfinished) project (not the Pico based ones) that claims up to 12 digits of resolution and I put that on my research list.

paulvee commented 1 year ago

I have been in contact with the designer of projects for a Reciprocal Counter. It is NOT possible to get 10 digits of resolution without going through a lot of troubles. To really profile a GPSDO, that's what you need.

Have a look here: https://www.eevblog.com/forum/projects/8-11-digits-reciprocal-frequency-counter-0-1-hz-150-mhz/50/

Here is a comment from an email conversation with Michael: Ich weiss, dass viele Leute 12-stellige Auflösung/Genauigkeit haben möchten. Von mir gibt es Schaltungen mit TDC7200 und AS6501, von denen der AS6501 die beste Auflösung bietet. Aber alle diese Schaltungen habe ich nicht weiter dokumentiert und nur zwei weitere Kollegen (1 x D und 1 x NL) haben diese in Betrieb. Oberhalb von 10 Stellen Auflösung kommen deutliche Einschränkungen, die kaum zu umgehen sind. Eine perfekte Lösung bräuchte 2 x AS6501 und 1 x STM32H7xx Controller. Ich wüsste, wie es ginge, brauche es aber selber überhaupt nicht und habe den Aufwand daher nicht mehr betrieben.

I'm starting a project to see how far I can go, but it will not be as trivial as you think it is.

paulvdhoeven commented 1 year ago

I think there is a misunderstanding. The principles are quite simple and sound. Getting to an accurately working end result is indeed not so straightforward.

You will need some good knowledge of the timer hardware in your microcontroller, and you may need to add some clever software tricks to get around limitations of the hardware. Each uC family will have it's own pro's and con's. STM32 has some ways in which different timers can be combined. Some of the PIC uC's have some internal programmable logic that may be useful.

I had a look at the datasheet of the AS6501. It looks like "the lazy way out", and quite expensive too, at almost EUR 30 a piece (small quantities). I'm still convinced it can be done with just a (decent) uC with it's internal peripherals, some clever (and non trivial!) programming, and maybe some extra simple logic IC's

paulvee commented 1 year ago

What's stopping you from building one? Please post the results.

Happy Newyear

paulvdhoeven commented 1 year ago

I will not build one, and the reason is simple. I just have no need at all for such an accurate frequency counter. The 5 or so digits that my DSO can measure is good enough for me.

Long ago (Maybe 20 years ago, I only had an analog oscilloscope back then ) I did build one on a breadboard and almost finished the software (For an ATMEGA8 at that time). That is why I know it's doable. I also have a bad habit of not finishing projects. New projects are interesting and exciting, but when a project is 80% done and I know what the last 20% looks like there is no challenge any more and I loose interest.