News for hackers. Stuff that matters.

Show HN: Apple II clock using interrupts from physical pendulum clock

https://github.com/wkjagt/apple2_pendulum_clock/blob/main/README.md

A clock app for my Apple ][ clone in 6502 assembly, using interrupts generated by an inductive proximity sensor and a physical pendulum clock. I wanted to polish the code a bit more before sharing (I especially dislike the self modifying code part), but the computer seems to have developed a hardware problem lately and it keeps crashing (bad RAM chip most likely), so I am sharing as is.
( 29 comments | 35 points | on HN )
Re:Show HN: Apple II clock using interrupts from physical pe... by em3rgent0rdr on Sunday January 28, 2024 @12:23PM (#39167774)
Interesting idea to use an inductive sensor. I personally would have suggested a hall sensor (though that would involve fixing a tiny magnet to the pendulum) as the cheapest solution. But of course there are many ways to solve the same problem. Neat project, thanks for sharing!
Re:Show HN: Apple II clock using interrupts from physical pe... by SomeoneFromCA on Sunday January 28, 2024 @01:02PM (#39168099)
The canonical way of using pendulums as time reference in electronic circuits, is to use magnetic pendulum coupled a special circuit (a bjt and an inductor) that would not only sense the pendulum but also reenergize it.

example: https://electronics.stackexchange.com/questions/685779/elect...

Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @01:45PM (#39168561)
Oh cool I didn't know that existed. In my case I don't have to re-energize it because I use an existing mechanical clock.
Re:Show HN: Apple II clock using interrupts from physical pe... by zokier on Sunday January 28, 2024 @03:45PM (#39169642)
If you are curious about this sort of thing, look up master pendulum clocks. They were precision clocks that provided electric timing pulses to network of slave clocks or other uses. Afaik they were common in mid-20th century
Re:Show HN: Apple II clock using interrupts from physical pe... by totetsu on Sunday January 28, 2024 @06:56PM (#39171202)
Here I was imagining you had to wind your computer with a key every morning.
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @09:03PM (#39171951)
I also got a rotary encoder with the plan to use it with a wind up clock. So maybe one day!
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @01:42PM (#39168534)
Thanks! I liked the inductive sensor, because it meant I didn't have to change the physical clock in any way. And they were only like 5 CAD each.
Re:Show HN: Apple II clock using interrupts from physical pe... by joezydeco on Sunday January 28, 2024 @12:52PM (#39168037)
My mind went to an optical sensor. Either interrupt a beam with the pendulum or attach a small reflector to the arm.
Re:Show HN: Apple II clock using interrupts from physical pe... by NikkiA on Wednesday January 31, 2024 @06:03AM (#39202365)
Optical sensor would be the best option - both induction and hall effect will add a very tiny eddy current brake effect that will slow down the pendulum. Probably imperceptively, but it'll be there and will affect time keeping eventually.
Re:Show HN: Apple II clock using interrupts from physical pe... by guytv on Sunday January 28, 2024 @12:20PM (#39167758)
This is awesome!

Also, a heads-up to OP: the personal website linked from your GitHub account appears to be down.

Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @01:46PM (#39168584)
Thanks! And I forgot I still had that site linked there. I'll remove it.
Re:Show HN: Apple II clock using interrupts from physical pe... by mungoman2 on Sunday January 28, 2024 @12:20PM (#39167756)
Really love this idea and execution. Truly fantastic!
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @01:46PM (#39168573)
Thanks :D
Re:Show HN: Apple II clock using interrupts from physical pe... by geerlingguy on Sunday January 28, 2024 @12:38PM (#39167899)
This is quite interesting; I've been reading up on PLL and chip design lately, as well as VCOs, TCXOs, etc.

And now I'm wondering how accurate someone could make a reference signal from a physical pendulum like this—or what strange quirks you could introduce into a system using such a 'weighty' clock source!

Re:Show HN: Apple II clock using interrupts from physical pe... by tvb on Sunday January 28, 2024 @01:29PM (#39168362)
Many pendulum clocks are capable of well under 1 ppm accuracy, which is better than many quartz oscillators. Here is a tour of clock precision by orders of magnitude:

http://leapsecond.com/ten/

Here is a world record setting pendulum clock from a few years ago:

http://leapsecond.com/pend/clockb/

Precision pendulum clocks are a very deep rabbit hole.

Re:Show HN: Apple II clock using interrupts from physical pe... by zokier on Sunday January 28, 2024 @03:50PM (#39169672)
See also https://en.wikipedia.org/wiki/Shortt%E2%80%93Synchronome_clo...

> The Shortt was the first clock to be a more accurate timekeeper than the Earth itself; it was used in 1926 to detect tiny seasonal changes in the Earth's rotation rate. Shortt clocks achieved accuracy of around a second per year

If my math is right, thats about 30ppb

Re:Show HN: Apple II clock using interrupts from physical pe... by kazinator on Sunday January 28, 2024 @01:43PM (#39168544)
Wow, people are still working on the problem of the Apple II not having an RTC, in some shape? :)

Say, weren't there some issues with interrupts on the Apple II, due to both the 6502 as well as buggy ROMs? Basically, none of the I/O in the stock system with Apple parts used interrupts whatsoever. Not disks, not serial communication.

Re:Show HN: Apple II clock using interrupts from physical pe... by thought_alarm on Sunday January 28, 2024 @02:32PM (#39169012)
The problem with the original firmware was that its interrupt handler used a zero-page location to store the accumulator. AppleSoft BASIC uses the same zero-page location for its own use, which makes BASIC incompatible with interrupts.

Another problem was with in the original Apple IIe. Its firmware interrupt handler was not updated to handle the new auxiliary memory and 80-column video configurations.

ProDOS provided proper support for interrupts, even on older Apple IIs (needed for mouse-based GUI apps and realtime clocks), and the firmware was eventually updated in the IIc and Enhanced IIe.

Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @02:00PM (#39168711)
Yeah I think nothing actually uses interrupts by default. But they're accessible through the expansion ports. Not sure what the problem would be though.
Re:Show HN: Apple II clock using interrupts from physical pe... by noxon on Sunday January 28, 2024 @02:02PM (#39168740)
Serial interfaces could use interrupts, and it was necessary at higher baud rates.
Re:Show HN: Apple II clock using interrupts from physical pe... by tonyedgecombe on Sunday January 28, 2024 @02:08PM (#39168811)
Yes, I remember writing a print spooler using interrupts as part of my first job.
Re:Show HN: Apple II clock using interrupts from physical pe... by lisper on Sunday January 28, 2024 @01:51PM (#39168629)
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @02:02PM (#39168737)
Oh wow, he uses the 60hz signal from the video circuitry. That's way more convenient than a big wall clock ;) And he even uses the same interrupt gating idea for the interrupts by using the game port.
Re:Show HN: Apple II clock using interrupts from physical pe... by lisper on Sunday January 28, 2024 @02:14PM (#39168856)
He is me :-) And yes, that's exactly right.
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @03:27PM (#39169496)
Ha, even cooler! Very nice to see :-)
Re:Show HN: Apple II clock using interrupts from physical pe... by technothrasher on Sunday January 28, 2024 @02:51PM (#39169174)
Neat project. But I want more pictures of the mechanical clock too. All I can see are the pendulum, weights and chain. I'm going to guess it is a German Hermle movement? Is that a custom made clock case?
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @03:35PM (#39169565)
Oh good point, I hadn't even considered posting a photo of the clock itself. I'll add a picture of it to the post later. But to answer you question: no custom made clock case. The wood you're seeing is the wall. And the clock is a Junghans (so indeed German), I would say midcentury modern? Almost identical to this model (found through Google Images) : https://a.1stdibscdn.com/archivesE/upload/1121189/f_13997072...
Re:Show HN: Apple II clock using interrupts from physical pe... by jamesbfb on Sunday January 28, 2024 @03:18PM (#39169418)
The high pitch from the CRT in the video (on GitHub) has my 40 year old ears feeling pretty happy about themselves!
Re:Show HN: Apple II clock using interrupts from physical pe... by wkjagt on Sunday January 28, 2024 @03:50PM (#39169671)
I am 46 and I don't hear it, not even when I am sitting right next to it. But others who I've show the computer to have noticed the noise as well, so I know it's there. I'm actually kinda happy about not hearing it myself :D