Mars Clock
      Main           Construction           Operation           Schematics           Code           HowTo      Other Projects  

The microcontroller program is written in assembly language. I tried to make it as extensible as possible - even at the price of increasing the code size sometimes. It has room for improvement, for sure, but it works and is not overly messy - that's enough for me. I might be updating the program from time to time - providing bugfixes and new features. If you decide to build this clock, make sure you check this site for the latest version.

Mars Clockv.1.3, 2009/04/04
Complete MPLab Projectastro_clock.zip
Compiled HEX fileastro_clock.HEX
Main programastro_clock.asm
Keyboard definitionsKBD.h
LCD module definitionsLCD.h

Adjusting the Clock Rate
I spent some time tuning the clock rate and got the accuracy is to a pretty good level - less than a second for a week. If your clock is doing worse than this, you can easily adjust the rate by changing the TMR_STD_LO, TMR_STD_HI, TMR_XTR_LO, and TMR_XTR_HI constants defined in the beginning of
astro_clock.asm.

First, how it all works. Every time the microcontroller's T1 timer overflows, it generates an interrupt. TMR_STD_LO and TMR_STD_HI set the starting point of the timer, so increasing or decreasing those values will speed up or slow down the timer respecively. For nineteen cycles of the timer the TMR_STD_LO and TMR_STD_HI values are used, but for the twentieth the timer is initialized using TMR_XTR_LO and TMR_XTR_HI. This allows TMR_XTR_LO and TMR_XTR_HI to be used for precision adjustments.

Use the TMR_STD_LO and TMR_STD_HI for rough adjustments. The current value is $0x66C5 - increase this a bit to speed-up the clock, redice it to slow it down. I expect you will have to modify only the TMR_STD_LO byte, but if you are using a resonator running at different frequency than mine, you might have to adjust both.

When you have found the best value for this, use the TMR_XTR_LO and TMR_XTR_HI to fine-tune the clock rate. Again, to speed-up the clock, increase the two-byte number; to slow it down, decrease it. This adjustment is about 20 times more accurate than the first.


Using a Different Keyboard
The keyboard that I've found for the clock (see the image in the
Operation section) might not be the same as yours. If your keyboard layout does not match mine, edit the button definitions in KBD.h. In this file, all the keys are listed in order, starting from the top left, and going row by row. Reorder these definitions according the layout of your keyboard, then update the hex numbers for each key so they are sequential.

If you plan to use alternative keys for the menu navigation, stopping, starting and reversing the timers, change the definitions of the special buttons in that same file. They appear toward the end of KBD.h.


 




      Main           Construction           Operation           Schematics           Code           HowTo      Other Projects