enl 227 Posted July 1, 2013 Share Posted July 1, 2013 (Code is for CCS) Noting that the standard clock runs twelve hour cycles, and that there are 12 months in the year, I thought, "What if I use the hour hand for months? What can I do with this?" The result looks like a clock, uses a standard single phase quartz movement from the art store (cheaper and more consistant than the full clocks from Wally-world or Target, plus, I get the fun of making the face), but the hour hand shows months and the minute and second hands indicate point in month, using the standard Sumerian system, with minute hand being 60ths and the second hand being residual 3600ths of the month. To keep the month indication correct, the rate must be compensated for the length of the month. There are four month lengths (28, 29, 30, and 31 days), and the cycle is four years. Sorry, no compensation for the year divisible by 100 coming up. This will require manual intervention. Then, of course, the batteries will have to be changed roughly 10 times before then, so not a big deal. The months are 1-48 to cover the four year cycle, with the beginning of the cycle being the year following leap year (no special reason, but since this is 2013, it means that I didn't have to bang the button a lot during testing). The 32KHz crystal provides a timebase. The interface is dirt simple, but in no way elegant. NO pushbuttons to ground with pullup resisters and capacitive debounce for setting each of the month, day of month, hour, and minute. Feedback is in binary on six LED's. Simple. I used the Launchpad LED lines for the clock drive to make debugging easy. The interface is interrupt driven and not optimized for power-- I used a dummy loop rather than going to sleep while in the set state-- since it is infrequently used and the LED's will take one or two orders of magnitude more power than the processor while in set mode. See comments in the code for details. During run, the timer interrupts every 8sec on rollover (16 sec doesn't work evenly in a month with 29 or 31 days, increasing software burden. Energy usage not significantly more than for logic to alternate interval size) and the interupts are counted. When the count reaches 1/3600th of a month (12 min for a 30 day month, less for 29 and 28, more for 31... see the table in the code), the clock mechanism is ticked, the counter is reset, and, if hte last tick for the month has been done, the month is changed. Lessons demonstrated for new programmers: Tables are your best friend, if the memory is available. Const tables go in ROM, and need not initialization, so they take no time to set up. Saves a lot of computation during run time. Don't worry about efficiency (within limits) for something you only do once. The time/date set uses multiplication and division, which the '430 generally doesn't do in hardware. THere are warnings galore on compile. Doesn't matter, since there is plenty of memory even the smallest '430's for the software, and the power and time issues are irrelevent since, to paraphrase Daffy Duck, you only gotta do it once. Inherently floating point operations can often be done with integers. It is worth spending the time with pencil and paper. The initial setting for position in month requires, on first look, real number computation. By a we bit of algebra and appropriate sequence of operation, only the single divide is needed (note that there are 7200 half-seconds per hour...) The initial setting is within 8 sec (one timer cycle) of one minute, and could have been more accurate with another input for the second and precomputing the timer counter. In this case, it isn't worth it. Simple input schemes can be used effectively. Pushbuttons don't need debounce if they only get used once (the launchpad button on P1.3 for entering run) Use #define as a way of building your test cases into code. #ifdef and #endif bracket the test cases to prevent compile into production code, but there are in the source for debugging later if needed, and for use if changes are made to re-feature/upgrade Things that are open: better interface Self setting-- set the hands to 00:00, set the date/time, and the '430 steps the mechanism until it is in the appropriate location. May take a good part of 6 hours to synch (these mechanism's step at about 2/sec max) In my case, much better shield for the programming interface. There is no pic for a reason. I built it from the junk pile. 4 mismatched buttons with loose, uninsulated wie all over. If there are any questions or criticisms as to the software, let me know. It is not beautiful. I did not include a video, as it is quite boring to watch. About 12 min, tick, about 12 min, tick, etc. main.c oPossum 1 Quote Link to post Share on other sites
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.