R. Steve McKown [Sat, 17 Dec 2011 18:30:53 +0000 (11:30 -0700)]
Add persistent configuration
Save mode and color any time mode changes, or if in MODE_SOLID and
color changes. Configuration is saved in internal EEPROM. The
PIC16LF1933 claims 100K writes. At 5 hrs per day, thats over 13
years of config writes assuming MODE_SOLID and a color change 4
times per year.
When the configuration changes, a 3 second timer is set. When the
timer expires, then the configuration is written. This should help
reduce reduce unnecessary EEPROM writes when the uesr is cycling
through the modes to find the one they want.
R. Steve McKown [Sat, 17 Dec 2011 17:46:13 +0000 (10:46 -0700)]
Auto: 5 hrs on, 19 hrs off
The 32 kHz clock is running about 7.3 seconds slow per hour. Not great.
Perhaps the board just needs a capacitance tweak or adjustment.
Currently using 22 pF load caps with a 12.5 pF crystal, using Vss pin 8
on the micro as ground.
R. Steve McKown [Mon, 12 Dec 2011 02:46:33 +0000 (19:46 -0700)]
Add tmr32 module
* tmr32 module uses Timer 1 + crystal
* Use tmr32 to time auto on and off events
* Put the CPU in sleep when off, either by switch or timer.
Use the tmr32 module or a button ISR to wake back up.
R. Steve McKown [Sat, 10 Dec 2011 17:35:26 +0000 (10:35 -0700)]
Rocker switch off condition is both inputs high
Before 09441b496c6b40be151e4e655572cb37518e7225, the logic used "% 3",
which effectively converted 0b11 input to 0. Since the mod operation
is slow and code expensive, it was removed. Therefore the off condition
state has changed to 0b11.
R. Steve McKown [Thu, 8 Dec 2011 03:05:19 +0000 (20:05 -0700)]
Ensure proper behavior in timer_cwait
Ah, the Hi-Tech compiler's lovely interpretation of promotions. See
3.6.1, Integral Promotion. This may affect the conditional in
timer_cwait(), so force a cast of the result to be sure it is correct.
R. Steve McKown [Wed, 7 Dec 2011 02:07:47 +0000 (19:07 -0700)]
Update buttons_sleep() for auto-off restart case
buttons_sleep() now first sleeps until the rocker switch is turned off
before then sleeping until it is turned on. This allows the function to
be used for the auto-off case, where the lamp must stay in auto-off when
the rocker switch is still in position B. To wake from auto-off manually,
one simply turns the rocker off then back to either position A or B.
R. Steve McKown [Wed, 7 Dec 2011 00:16:33 +0000 (17:16 -0700)]
Clock loop start to loop start using Timer 0
Timer 0 is configured to overflow every 32 msec, which is the period we
wait when driving the main control loop. Once a loop iteration has
completed its processing, it calls timer_owait() to wait on the next
overflow.
R. Steve McKown [Tue, 6 Dec 2011 18:36:13 +0000 (11:36 -0700)]
Run at Fosc = 4MHz
* Run on internal oscillator at 4 MHz
* Get rid of the RUNAT32MHz definition
* Adjust PWM for ~ 1 kHz frequency, at Fosc = 4 MHz
* Loop processing <= 12 ms, out of a period of 32 ms
R. Steve McKown [Sun, 4 Dec 2011 22:57:55 +0000 (15:57 -0700)]
Closer to a full featured setup
Rocker switch is power switch.
* Off: lamp is off, PWM off, CPU in sleep
* On (right): Random time to fade between colors, with a random time
staying in each color.
* Off (left): No fade between colors, with a random time in each color.
The push button speeds up fade and incolor times by a factor of 8.
R. Steve McKown [Wed, 30 Nov 2011 23:49:33 +0000 (16:49 -0700)]
Alter PWM in small increments
* Use unsigned char, as unsigned short is a 16-bit value
* Increment and decrement PWM value by 1 instead of 16
* Alternate fixed LED state based on increasing/decreasing PWM duty
* Ignore /funclist file