Pages

Showing posts with label Backup Lighting. Show all posts
Showing posts with label Backup Lighting. Show all posts

Sunday, 4 February 2024

Automatic Backup Lighting - V2.0 Amendments

Some small changes:

use a LED to indicate the presence of a charging voltage

replace the LM317's in the charging circuit with a 5V regulator feeding a 3.4V regulator. Current limiting is now via a resistor between the 5V rail and the 3.4V regulator.

Used hardware to control if charging circuit is connected to battery instead of software.


Saturday, 30 December 2023

Automatic Backup Lighting - V2.0 Details

 

 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


Rough but it works really well.

 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 'Toff \ time light is on when power fails
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


Saturday, 7 October 2023

Automatic Backup Lighting - V2.0

After several months of not needing backup lighting we suffered a week of regular power interruptions due to an equipment failure on the grid feeding our suburb. While very inconvenient it did highlight how useful automatic backup lighting can be. 

I have made the following changes since V1.0:

  1. switched to LiFePO4
  2. swapped to a STM8S003 running STM8eForth
  3. tried a variety of Leds. 

LiFePO4 Batteries

Switching to the LiFePO4 battery was a mixed blessing. The run time is impressively long though I could have achieved this with a different Li-Ion battery. And potentially the life in cycles means the backup lights might last for at least my lifetime.

For a while I had more lights than I could keep on charge. So I was forever having to manually connect and disconnect. Once I forgot to do this and the battery dropped below 3.0V. Which meant the micro wouldn't trigger the charging circuit and the cell kept going flat even though I thought it was on charge. The result was a ruined LiFePO4 battery. A change in hardware fixed this.

Most of all I slept easy knowing there would be no spontaneous combustion risk, unlike a li-ion battery which has a very small risk of bursting into fire.

STM8S003 running STM8eForth

This is almost perfect. Only a few cents more expensive than an ATTINY device and presently has better  availability. The ability to reprogram or adjust parameters via a serial cable as needed was a huge improvement over the ATTINY development landscape of assembly language and write / burn cycles.

The only downside was a battery voltage below 3V means it goes into reset which prevents the battery charging since the micro was controlling a pass transistor. That's been fixed. The presence of a charging voltage now turns on the pass transistor and the micro is not involved. The micro merely senses the charging voltage is present and controls the lighting accordingly. 

It meant I could alter things like on and off periods very easily by connecting the light to a serial port. And the button could be programmed to do one thing while on charge and another when there was no power as I thought up new applications. 

The CPU clock is now down to 15kHz which means the micro draws only 0.5mA. So once the battery voltage falls through 3.1V and the light is held off, the battery can run for a long time before the micro goes into reset and halts. Once power is restored and the battery voltage rises everything goes back to how it should be.

Leds

This proved to be the most frustrating part of V2.0 due to tolerances. By which I mean the led driver, supposedly turns off at 27V but in practice it can be lower due to tolerances. Using 3 high intensity leds with a 9V rating doesn't mean they clamp to a 27V level. It depends on the current being forced into the leds. More current means a higher voltage.

Once I realised this was why sometimes a board would work and other times it refused to it was a lot smoother sailing!


Conclusion

I think I have all the bugs resolved now. In the New Year I hope to write up this project in more detail.

A really bright backup light can prove immensely useful. And being able to unplug the light to use as an inspection lamp or similar has been proved to be very useful. The only thing I would change if it were possible would be to use a LiFePO4 battery more like the form factor shown below. The large cylindrical LiFePO4 cell constrains the sort of case I can use.