- Figured out interrupts: avr-gcc makes them TRIVIAL. Thanks guys for making such a fantastic little compiler.
So, yeah. Moved the entire loop into the ISR and put a "while (1) {sleep_mode()}" in main(). As long as I can keep the ISR under 8192 cycles (the number of cycles between interrupts), I'm golden. This should not be a problem, even with the inefficiencies of C.
- Added three buttons:
- Calibrate: Sends all meters to full scale
- Minutes: increment the minutes hand
- Hours: increment the hours hand
The calibrate button is required to adjust the 10-turn pots feeding the meters. Turn the device off, set the zero point using the adjustment on the front of the meter. Turn it on, hit the calibrate, and adjust the pots for full scale. Then you're off and running.
- Somewhere along the way, I accidentally programmed the chip to use the low frequency crystal, but didn't remove the CKDIV8 bit, meaning that the chip was running at (32.768kHz / 8 =) 4.092kHz. The in-circuit programmer needs to write at at-least 5kHz, and must be at most 1/4 the clock rate (1.024kHz). You see a problem forming here? I thought I bricked my chip. Then I did a bit of Googling and found out that the high voltage parallel programming modes don't depend on the system clock, and that my STK-500 supports the high voltage parallel programming mode. After about 30 minutes of doing what Real Geeks do: try stuff without reading any documentation, then giving up and reading the manual, I had it running in no time. My chip is un-bricked, and running at the correct speed of 32.768kHz now. The other bonus is that 32.768kHz / 4 > 5kHz, so I can still do in-circuit programming, which makes me happy.
So, I now have the chip up and running at the same level of functionality as the Propeller version, but this one will run at 1.8vDC, 32.768kHz, probably on the order of 100uA or less, and with a more precise oscillator. The next step is to build up a bread board with the hardware and hook it up to some meters. (Right now, I'm still just looking at LEDs of varying levels of brightness on the development board.)
I've drawn up a quick schematic for what I'm planning. The 1k fixed resistor and 5k 10-turn potentiometer are sized to be able to provide 1mA to a meter for a variety of system voltages, but still provide a reasonable current limit in case someone takes the pot and cranks it all the way down. With a 10-turn, it should be plenty precise. For my planned VCC of 1.8vDC and a "full scale" value on the PWM of 240 (out of 255), an impedance of 1687ohms will give 1mA. The meters are 100ohms, and the fixed resistor is 1k, meaning the pot will need to be set to about 500 to 600ohms, plenty far from the 0 point to be cleanly adjustable.
TODO: Order a few parts from Digikey. I don't have any 10-turn 5k pots on hand, and I'm probably running low on 1kOhm. And I'm pretty sure I don't have any push buttons.