2007-05-10

Log clock

Got my log clock running. It is not entirely accurate, loses a second every 7hr or so. However its nature is such I doubt it will really matter.Thanks to the JAL interval library routines, it is very accurate. I originally thought the next interval routine returns after the 1 second delay I setup, only that is not the case. It returns when the internal clock ticks over to the next second. So as long as all the logic is done with in a second, and it is, each loop takes exactly 1 second.





The design is very simple. Using a 16F84A (yeah yeah, its obselete blah bah) with a 4Mhz crystal, lots of wires, and a 12 segment bar display. The button is used to advance the clock to the next interval. This method of setting the time is very crude - but then it doesn't have to be sophisticated. Software was written in JAL.



The loss of a second every ~7hr is due to the fact its basically a loop which has a delay of 1 second, and does some logic to handle display and button presses. The logic skews the overall delay per loop because each branch and such takes up cycles. There are several things I can do to improve this:




  • Pad out each branch with NOP so they all take the same time, then compensate for this in the loop delay accordingly.

  • Have a secondary circuit to output a pulse every second, so the logic and such won't skew the clock. This would also allow me to check for button presses more often.

  • Write my own interrupt routines to handle TMR0 interrupts and handle logic in the main routine.



The button is debounced in hardware implicitly, since there is a 1 second delay between each polling of button state. As the 16F84A only has 8bit registers, the intervals in seconds are not stored but rather the time in seconds between intervals is stored. This allows me to avoid multi-register arithmatics. The clock can also represent 13 states despite having only 12 LEDs - the 13th state is all LED off, which I have reserved for midnight.



I will report on how accurate it is eventually. I will check the log clock when I wake up, against real time, to see if the right interval is correctly illuminated.



Update 10/5/07 - Woke up, clock was right. Every 30minutes or so I check it and its been right so I declare it a success :-)




Cheers,

Steve