Description
This project provides automatic backup lighting whenever the mains power is lost.
Using high power white leds the lighting allows me to safely move about.
Multiple lights can be daisy chained via the power connectors marked AB in the schematic below. I only fitted one connector to the PCB pictured since it was a prototype.
Use of the bridge rectifier means I become agnostic on the power source used. AC or DC from a wall wart, 9V to 24V is fine.
Because the STM8S003 does not have a bandgap reference voltage I simply use a 3.08V reset chip to monitor the battery voltage and provide a go/no-go signal to the micro.
Picture of finished Prototype
Schematic
Software
Here is the barebones V2 code. It runs on a STM8003 flashed with STM8 eForth. I didn't bother trying to minimise the current drawn by the micro beyond that achieved by simply slowing down the clock, resulting in around 1mA of current drawn by the CPU.
For the version with the button fitted please contact me and I will upload it. I would need to tidy up my comments in the listing before uploading.
\ If Pwr? Pin is high turn off light after 20 seconds
\ If Pwr? is low turn off light after 5 minutes
RESET
NVM
Variable 'Ton \ time light stays on when power restored
\ Port C Pins
6 CONSTANT _Pwr?
7 CONSTANT _LedEn
\ Port D pins
2 CONSTANT _LowBatt?
: setup_pins ( -- )
\ Port C inputs are floating, no interrupts enabled
[ _LedEn PC_DDR ]C! \ Port c outputs
[ 0 PB_DDR _LowBatt? ]B! \ set as an input
[ 1 PB_CR1 _LowBatt? ]B! \ enable pull-up
;
: _LEDon ( --- ) [ 1 PC_ODR _LEDEn ]B! ;
: _LEDoff [ 0 PC_ODR _LEDEn ]B! ;
: LowBatt? [ PD_IDR _LowBatt ]B? ;
: Light?
Pwr?
if 1800 'Toff !
'Ton @
If _LEDon -1 'Ton +!
Else _LEDoff
Then
Else
90 'Ton !
'Toff @
If _LEDon -1 'Toff +!
Else _LEDoff
Then
Then
;
: MAIN
SETUP_PINS
[ $35 C, $1F C, $50 C, $C6 C, ] \ Clock CPU at 15.625kHz
BEGIN
LIGHT?
AGAIN
;
RAM
NVM
' MAIN 'Boot !
RAM
No comments:
Post a Comment