Posted By azog on December 23, 2007
After looking at my unfinished project for the past few months, I finally decided to pick up where I left off. The last thing I needed to figure out was a way to set the minutes and hours, and I was hoping to use an interrupt. I was already using INT0 for the calibration mode, but needed two more. The Arduino basic docs only talked about INT0 and INT1. I know from previous experience that most of the PORT pins have a “port change interrupt”, and figured out how to use it. It is fairly easy, vaguely similar to doing it in assembler. For some reason, it worked in the simulator, but not in real-life. I suspect it has to do with button bounce. I made a workaround that works, but I’m not entirely happy. Here is the original post.
The front of the clock, running in “calibration” mode. Each PWM register is loaded with the max value so that the pots can be trimmed for full deflection.
This the clock in “run” mode, with a random time set.
And the rear panel. The three pots adjust the meter deflection, as above. The single switch is calibration mode. The two stacked switches are hours set and minutes set.
And finally the ugly inside.
I basically had to throw almost everything out and start from scratch.
Originally I was just loading the PWM registers with the respective time element (23:59:59), and was using a home-made driver board to boost the current to archive full meter deflection. The driver board was just four transistors.
I’ve tossed the driver board, and instead multiply the output of the basic time element by some number no greater than 255 (the max value you can output on a PWM port). In the case of the seconds and hours, it’s a x4 multipler, giving no greater than 239. For the hours, it’s x10, for 230. Calibration mode loads 230:239:239; during run mode, I just do (secs*4), etc.
Calibration mode is on INT0 for CHANGE. For some reason, in calibration mode, the meters pulse each second, in accordance with the time-keeping. I tried the alternate modes (RISING, etc), but CHANGE was the best.
The setting buttons are accomplished by reading the respective pin each second (during the main loop, after the “delay” of one second). That’s awkward, because the settings change only once a second. When I tried it with interrupts, the interrupt would constantly trigger, changing the values too fast. I don’t have an answer, altho I am sure one exists. Again, it worked fine in the simulator, so it’s probably bounce related.
Code is very straight-forward. Count from 0-59, increment the minutes and/or hours, and roll-over when needed. I did run this thru the simulator at full-speed so I could watch every increment, and at least that part works fine.
Also, see a later post regarding some changes to the software.