Sidereal seconds hand

I spent some time thrashing about trying to make sure that the circuit was producing the correct output.

I decided to try the Hz counter on my DMM, to see whether it could give me an accurate enough reading.

Hooked it all up, fired up the circuit, and…

256Hz.

Erm. Clearly I’d made an error somewhere.

I played around with the Bresenham constants, did a lot of streamlining and simplifying, and was finally able to find out that I’d set up an incorrect prescaler on the timer. With that fixed, I found:

– If I just toggle the LED every time the interrupt fires, I get ~62kHz (expect 62500 — close enough)
– If I set the Bresenham constants for add 1 and overflow at 62500, I get ~0.5Hz (half of my expected rate — fixed it by adding “2” instead for ~1.0Hz)
– If I set the Bresenham constants with a scalar that will get the numbers up close to 2^32 (4.29billion), things don’t work right.
– If I set the Bresenham constants with a scalar of 10,000 (for 32857.7158000Hz), I get ~16kHz (again, the toggling thing halves the output frequency)
– If I increase a counter by 2 every time a sidereal tick happens, and I toggle every 32857 ticks, I get ~0.999Hz

At this point, I stopped, claiming success.

This morning in the shower, I realized that I should be able to see the difference between 1Hz and 1Hz(sidereal) — they differ in the thousandths place.

So either my DMM isn’t very accurate (totally possible), or I had a code bug (very likely). I decided to blame myself, thought about where the code bug must be, and …

I’ll pause here for a second, to see if you “see” it before I did.

.
.
.

The whole point of this exercise was to get 32768Hz(sidereal) out of the circuit. That is, to produce 2^15 ticks in 1 sidereal second.

The circuit is a filter that takes a bunch of nasty numbers as input (366.24/365.24, lots more decimal places, of course, and corrected for nutation, precession, and everything else), and spits out a nice, clean 2^15 output.

So I didn’t want to toggle the pin every 32857.7158 ticks, I wanted to toggle the pin every 32768 ticks exactly.

I updated the constant, re-ran the circuit, and wouldn’t you know, my DMM now reads 1.002Hz (expected: 1.002 737 909 35). Perfect!

By the way, I was a little worried about accuracy. So I decided to check how far off my “only to 4 decimal places” time base would be against the 11 decimal places of accuracy in the number above (gleaned from the US Naval Observatory, etc).

32857.7158 / 32768 = 1.002737908935547 (the actual Hz output I expect from the circuit)

1.002 737 908 935 547 – 1.002 737 909 35 = 0.000 000 000 414 453

That’s a difference in the 10th decimal place (the 10 billionth). As I expect that the non-temperature-controlled crystal in the Arduino runs somewhere in the 20-100 parts per million error, any error from the crystal will far outshadow any derived from this calculation.

I’ll have to get the circuit onto an oscilloscope to determine how jittery the signal is. For now, though, I’m sitting here marveling at my 1Hz(sidereal) timebase!

This entry was posted in Electronics, Knowledge, Making, Science and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *