I’m a timenut, but the electronic sort not mechanical clocks. I have several GPS disciplined oscillators (normally 3 running at any time), multiple oven controlled oscillators, a few atomic standards, 3 high resolution (ps) counters plus other specialised stuff.
The though of usng an Arduino, never mind one with a ceramic resonator, as a time measurement device makes me shudder…
May I suggest that you look at low cost hardware designed for this task by people who really know what they are doing (I’m a novice by comparison). Specifically the PICPET and PICTIC. As the name suggests these use the PIC series of microcontrollers (RISC before it was called that) with highly deterministic firmware…
Thanks to John Haine I have a p06 picPET so have been able to compare it with my equivalent, an ‘ARDPET’. Both depend on the stability and precision of the oscillator, which in order of loveliness could be a resonator, quartz crystal, TCXO, OCXO or GPS Disciplined oscillator.
I wanted to implement a Precision Event Timer (PET) on Arduino rather than PIC for several reasons, notably:
- If anyone wants to copy what I’ve done, the Arduino family is far more beginner friendly: the no-soldering needed boards do not require a separate hardware programmer, just a USB cable; compile and link intricacies are largely hidden; the free IDE is straightforward; and there’s a massive support community. Almost all the code is open source, many cheap add-on modules are available, and the electronics are affordable.
- I wanted to implement a PET inside my clock, not as a separate utility. Makes it easy to log temp, pressure and humidity at the same time as period is measured.
- If necessary, because I wrote the code, ARDPET can be extended. For example, picPET is only programmed to count oscillator ticks between two events, whereas ARDPET can count ticks between 2 or more events, to average frequency/period over many cycles.
The instruction set of PIC vs Atmel is irrelevant in this application. The timing is done in hardware with a Counter/Timer in Input Capture Mode. A hardware peripheral counts the number of clock cycles between two input events, saves the result, generates an interrupt, and starts again. The Counter/Timer runs continually irrespective of whatever the software is doing. All that’s necessary is for whatever the software is doing to finish before the next interrupt, in my clock about 0.8 seconds.
An advantage of the Arduino processors over PIC (at least the CPU used by picPET), is that they run at 16MHz off-the-shelf, and can be driven at 20MHz. So a picPET has a resolution of 100nS, whilst an Arduino does 62.5nS, or 50nS at 20MHz. Further, depending on the chip, Arduino’s come with two or more counter timers that can do Input Capture at the same time.
My clock uses two PETS:
- One measures pendulum period in local clock ticks (accuracy depends on the Arduino’s oscillator)
- The other, optionally, measures the number of local clock ticks per GPS second.
This measures the actual frequency of the Arduino’s oscillator, counted over 1 second, allowing the pendulum period to be measured relative to GPS. Or it would if the Arduino’s oscillator were stable within the 1 second period! My mistake was assuming a ceramic resonator would drift predictably, and it turns out they don’t. Although mine stay close to 16MHz, the actual frequency jumps unpredictably by up to 1.5kHz, and then saw-tooths back to average, where it might or might not stabilise briefly.
My initial testing was done with an Arduino Leonardo, which is fitted with a crystal oscillator, and behaved well. I switched to an Arduino 2560 with a ceramic resonator because it has more counter/timers and it was useful to have another one generate pendulum pulses whilst bench testing the software. Unfortunately I didn’t realise just how unstable the 2560’s ceramic resonator was until I looked at the statistics produced by a long run.
ARDPET and picPET produce much the same result when used to time the same event – they both work the same way by counting clock pulses between events in hardware. Both count 1000000 when a 10MHz OXCO is gated by a GPS second; however gating the Arduino over 100 gps seconds suggests the OXCO isn’t quite spot on. Having a faster oscillator means the Arduino has higher resolution.
I’ve looked at Nucleo and other chips in hope of finding a seriously fast microcontroller that can also do hardware input capture, perhaps with an external clock. So far the answer is a lemon! I’ve not found anything general purpose that combines high frequency, high stability and Input Capture.
Dave