Clockmakers Clock timer - adivce and suggestions!

Hi,
Ive recently made my first clock, Dr Philip Woodwards Gearless clock. I say made, well it is now running but it isnt complete as far as case, hands etc. but as far as the running mechanism, it is working. There are some details about it here at my site: www.raynerd.co.uk

Im really interested in building a timer to check the errors in my clock. I have very limited skills in microcontollers but Im not a complete noob, you can see some of my PIC projects on my website as well ... just basic stuff like electronic dice, binary clock and my "best" device was a single axis stepper motor controller for my milling machine. I used an EasyPIC 6 from mikroelectronica in Mikro C for all my work but Ive recently been playing with the arduino boards which seem a little easier to use and ideally Id like to use this for my project.

The basic funtion of a clock timer is to keep accurate time itself and compare this to the time being measured by the clock. The way commercial timers work (which are too expensive for me to consider right now!) The PIC on commercial timers uses one of two main methods to input the clock time, either it uses a microphone to "listen" to the beat of the clock or watch escape wheel (tick tock!) or with clocks, you can use a physical sensor on the pendulum and measure the period of the pendulum.

I imagine using a physical sensor to measure the pendulum swing/period would be easiest in terms of an input for the arduino. My initial thoughts are to time the length of each period (mount a sensor of some sort on the pendulum and on the wall behind the pendulum bob and two passes of the sensor will equal one period). I know my clock should do 40 complete swings/periods each minute (easier to calculate if it was 60!!), so it should take 60/40 = 1.5seconds per period if it is keeping correct time. I`m guessing really it should take the readings of a number of periods and calculate an average.
Commercial controllers have lots of functions but a lot of the functions are just “extras” to the code, playing around with the numbers to show things like beats per minute, beats per hour etc.
Has anyone any suggestions as to how I would keep the “perfect” accurate on-board time keeping on the arduino?
Any idea what sensor would be best to measure the passing of the pendulum at a specific point?

Any other ideas would be welcome…
Chris

Sorry, Ive just done a little more reading and thinking. Will I need to use a RTC module or will the "millis" function timer that I believe is on the arduino be suitable? From what Ive read the RTC modules keep the time when the arduino loses power, but this isnt necessary for me since if the arduino is off, I cant be using it to check the clock time. I believe the millis function will run for upto 50 days before resetting which is plenty. I`m not sure how accurate this is or if it is even a timer!

I was hoping to use a quartz timer but then I guess this accuracy is gained from the onboard quartz oscillator. I have the "duemilanove" board at present.

Chris

Will I need to use a RTC module or will the "millis" function timer that I believe is on the arduino be suitable?

You want a timer that is more accurate than your clock so it depends on how accurate a Dr Philip Woodward's Gearless Clock can be made. For example, if the very best that can be expected from the clock is ±1% then the processor's internal oscillator (after calibrating) may be good enough. But, if the clock is capable of 100 ppm then a real-time clock is appropriate.

millis() can be pretty good if the MCU is clocked by a crystal instead of a resonator. An important question is how accurately we want to measure the subject clock, or how closely we might want to adjust it. A DS1307 RTC isn't real great, a couple seconds error per day is typical. A DS3231 is much better, and is software compatible with the DS1307 unless the software stores data in the DS1307 memory (DS3231 has none) or uses the DS3231 alarms (DS1307 has no alarms!) Google "Chronodot" for a nice DS3231 breakout board. The other option is to sync the Arduino and/or RTC with NIST or other internet time service.

I certainly wouldn't attach anything directly to the pendulum as this will no doubt affect its period. I'm thinking optical sensing of some sort, perhaps an infrared interrupter if it can be positioned properly.

With most of the common RTCs it gets to be difficult keeping things accurate below the one-second level, even syncing with a time service. Over a long enough period of time, ±1 second could represent pretty good accuracy, but that doesn't make for quick measurements.

HTH. Very cool web site by the way, lots of interesting projects, have to check it out some more!

Thanks for your replies. To address a few of the issues...

If I could get my clock running to within 2 seconds a week, that would be excellent! Im not sure how long you would need to run the timer for to attain an accurate measure of error. Im guessing an error of 2 seconds a week would be a tiny error over a period of a few hours, therefore I expect we are talking high accuracy, but no greater than a good quartz timer.

http://www.bmumford.com sell the cheapest timers but these are still too expensive for me! They say that there timers are of a "resolution of one quarter of a millionth of a second. These increments are added up for each beat of the clock or watch and displayed to show elapsed time"

The clock can be very accurately regulated by dropping tiny masses on the pendulum!! I was totally blown away with this knowing that only length effects period! However, the formula presumes that the mass is at point at the end of the pendulum rod which it isn`t. Adding masses reduces the effective length of the pendulum by raising its centre of mass, decreasing the period and therefore speeding up the clock. This is apparently how Big Ben in London is altered.

I`m quickly wondering if this project is going to be above me!!

With any typical RTC, you will need to measure the clock over a long period of time to detect any delta, since their resolution is one full second. The expensive timers are measuring in very tiny increments, which is why they measure the pendulum accuracy very quickly.

A compromise would be to use a temperature-compensated oscillator, such as the Chronodot's 32HKz output or another TCXO with higher speed output. You could use that higher speed output to interrupt an Arduino and have it measure pendulum position in small, accurate slices of time. Still much slower to get a result than the big name timers, but better than running the two clocks for a few weeks. You'll also probably notice that the number of cycles to process an interrupt, and other stuff happening behind the scenes, will affect the final accuracy of your project.

You could potentially have an all-external counter mechanism, using logic ICs. Use the signal from the optointerrupter to start and stop a counter connected to a temperature compensated clock source. Then use the Arduino to read off the final count, when timing isn't critical anymore.

You could use that higher speed output to interrupt an Arduino

...drive timer 1 directly and use input capture to get nice clean snapshots of the value. At least I think timer 1 can be driven asynchronously. Maybe it was timer 2 that has that feature...

I really can`t get this idea out of my head despite me probably not being capable of it but a few more thoughts...

Looking at the commerical ones, the most expensive detector seems to be a sort of gate which the pendulum swings between and interupts. My pendulum is very thick at 2" and so the gate opening would have to be at least that wide. Although, for saying that, I could always measure the interruption of the beam caused by the pendulum rod a little higer than the pendulum bob itself.

If I make this too difficult I`m not going to be able to start it.
Could anyone recommend a suitable sensor that I could use as an input to measure the pass of the pendulum?

Chronodot's 32HKz output or another TCXO with higher speed output. You could use that higher speed output to interrupt an Arduino and have it measure pendulum position in small, accurate slices of time. Still much slower to get a result than the big name timers, but better than running the two clocks for a few weeks.

What do you mean by "the big name timers" ?

Would a LS7366 be any use? I believe there are some Arduino code examples around (for quadrature stuff but I'm sure it could be adapted)...

DaveG - Ive just looked at the LS7366 data sheet and Im lost already! My work with microcontrollers is only a hobby and my understanding of electronics isn`t great! How would the LS7366 help above what the microcontroller alone can do?

Chris

btw.. still interested in any ideas as to components to use to detect the pendulum swing and then I can get these ordered to at least make an effort at starting.

I suspect that unitized opto-interrupters (example) may have physical dimensions that are too small for this application, but all they are is an emitter (e.g. an infrared LED) and a detector (e.g. phototransistor) in one package, so no reason one couldn't be fashioned from the separate components (example, example).

Jack, thanks for the info. I expect the single unit would be too narrow but I could certainly knock one together.

I know I`m now really looking at this in a simple way but is there no way of simply starting an onboard timer when the sensor is triggered, timing the length of time until the next sensor signal... perhaps doing this with a number of swings (2400 would be good, an hours worth!) and displaying a moving average of the time taken?

In really simplistic terms, I would like to know the average time for a period of the pendulum. If my clock is accurate, I should be 1.5 seconds per period.

Chris

EDIT. that is 1.5 seconds per period and therefore the sensor will trigger twice each period. It should actually be a 0.75 sec gap between sensor impulses.

Perhaps this data storage is too much for the microcontoller, does the data need to be sent to a computer? Now I`m making things difficult again.

Easier to just note the start time and count the number of times the sensor gets triggered. Then just calculate the average based on time now. If you want an hour's moving average - not sure how much that helps compared to the average, just maintain another time variable and counter. Timing the pulses and keeping that data individually will, as you say, eat too much memory, but worse, it'll introduce inaccuracies of it's own - millis isn't that precise for short time periods.

From looking at crystal datasheets, it appears to me that if your Arduino has a crystal and not a ceramic resonator, the 16MHz crystal is likely to have a stability of +/- 50ppm over a temperature range of about -10 to +60 degC, and a tolerance of about +/- 50ppm or better when the capacitance loading is as specified. However, the capacitive loading in the Arduino migh not be quite right, so the actual frequency at 25C could be incorrect by more than 50ppm. Therefore, if you don't calibrate your Arduino oscillator, you should reckon that the crystal could be about 100ppm out. That's about 9 seconds per day.

If you calibrate your Arduino (say by making a simple clock with it and checking it daily against a known time reference e.g. time pips on the radio), and you keep it at a reasonably constant temperature, you should be able to achieve about +/- 25ppm or better accuracy.

Don't try to time half-periods, because unless your sensor senses exactly the mid point of the pendulum, the two half-periods will be different.

If the period is 1.5 seconds, then to measure that to within 20ppm you would need a resolution of 30 microseconds. That would be measurable if the Arduino is in a tight loop, were it not for the tick interrupt getting in the way and delaying detection of the pendulum passing. However, if you time 10 periods then you only need a resolution of 300 microseconds, which is easier. Or you could time 40 periods (1 minute) so you only need a resolution of 1.2 milliseconds.

To sense the pendulum, you can buy inrared sensors with separate transmitter and receiver, but they are expensive. A cheaper solution would be to use a LED and a phototransistor, with the phototransistor mounted in a tube to block out extraneous light, and paint that part of the pendulum black to prevent it reflecting. Alternatively, buy a reflecting-type sensor and make that part of the pendulum highly reflective - google for "reflective object sensor".

Ke7gkp - there are a few reasons why a lot of clockmakers and repairers don't just do this. Primarily because it takes so long to check any real difference but also on my clock their are no seconds hands and so timing of the pendulum swing is a better measure. And like you said, it seemed a good excuse for a pic project!!!

Dc42 - thanks for your input.

Can I ask then, is there going to be a much more complex circuit to the official timers, eg www.bmumford.com than I was thinking. I presumed it was going to be a simple micro controller project which I thought I could deal with but now it looks like for accuracy I'd need more external circuitry.

Chris

If you're looking for an accuracy of 2 seconds per week, that's about 4ppm. So you need a time reference with an accuracy and stability no worse than about 1ppm. The easiest ways I can think of to achieve this are a temperature controlled crystal oscillator or a GPS receiver.

One way to use a TCO would be to take an Arduino (or make an Arduino clone) and feed the clock input pin from a TCO instead of connecting a crystal to it. For example, this one http://uk.rs-online.com/web/p/controlled-oscillator/6720788/ costs GBP7.42 + tax here in the UK. It's a little over 16MHz so you would need to to create your own board definition, and possibly modify some of the library files.

A GPS module has better long-term accuracy, but possibly worse short-term accuracy, given that there will be some jitter if the rate at which you read the time from the module doesn't exactly match the rate at which the module calculates the time.

create your own board definition, and possibly modify some of the library files

It sounds a great idea but I think your then going well beyond my capablities! I`m in the UK - Manchester so that little TCO seemed a decent price and I already have the arduino board. The commerical ones are cheapest about £200 delivered from the USA. Just too much for me at present.

The clock has no seconds hand so it is difficult to check accuracy without a real analytical method such as this timer Im trying to build. Also, the impulse pawl on the pendulum interacts with the pin wheel once a minute and Im interested to see if the effect on the pendulum is constant throughout the hour.

It is a pitty there is no similar project built that I could adapt the code and electronics to suit!

Chris

Creating a new board definition is actually very easy. Modifying an Arduino to accept an external clock could be a little tricky, but you could instead prototype your solution on a standard 16MHz Arduino, and then migrate your design to your own atmega328p-based circuit with clock pin fed from the TCO. Soldering the TCO may be a little tricky because all the inexpensive ones I found are surface mount.

Just a quick question...and I really hope Im not going around in circles but is there any reason why I couldnt use something like this:

http://www.arduino.cc/playground/Code/Stopwatch

It is basically a millis stopwatch but say measure the time elapsed between say 800 passes of the pensulum (sensor) (10 minutes - pendulum does 40 periods/80 swings/80 passes of the sensor every minute - 800 passes in 10 minutes) or even longer.

Im not going to lie, I dont really understand in my head the errors involved in the timing!

My other thought was that every two passes (1 period) could be measured and that this data fed to a computer or storage device.

Any more advice would be welcome and any further explanation of the errors involved and accuracy Im needing to measure to to get within 2 seconds a week would be much appreciated. I also just wanted to clarify, that when I talk about getting to within 2 seconds a week, I dont mean physically recording data for a week, I`m talking about doing a few hours or minutes of timing and then scaling this up to estimate the error over this longer period.

Chris

Timing individual pendulum swings requires extreme accuracy. Even the time the arduino takes to do its operations may be important. Any error could throw off your calculation to the point of making it worthless. Try timing 2400 passes, recording start millis and end millis. See if it's repeatable. Put an adjustment weight on the pendulum - can you measure the difference? Yes? Now you're good to go - add a GPS and use the timing from that, being careful to find out how long the arduino takes to get the time from the GPS over the serial port.