1N5817 Schottky Diode, 5V1 Zener Diode and a 470uH radial inductor
A few blogs ago I wrote about using a QX5252 solar light IC to run lights on minimal current from a single rechargeable AA NiMH battery. I had many such devices strewn all over the house and was haphazardly monitoring their efficiency over the last few months. Some lights were finished after about an hour, whilst others soldiered on with varied success through the night, depending it seems on the components chosen for the circuit (and the generation of the code running the whole show).
In the original design and in consultation with many sources, including the datasheet of the QX5252, I had chosen a 5V1 zener, a 1N4007 diode and a low value (e.g. 47uH) inductor as per the following circuit diagram.
It was clear from long term observations that a couple of outstanding devices were able to take up minimal solar energy during the day and shine all night and beyond with little signs of flagging. I grabbed these superior devices and looked closely at the values that I had chosen for some of the more critical components.
The zener was 5V1 as tested, but in the long lasting lights it seems that I had chosen a low forward voltage drop Schottky diode 1N5817 in place of the 1N4148, which in turn had replaced the 1N4007 from the original circuit. Amazingly the inductor was a hefty 470uH. That is significantly above the highest recommended inductance in the datasheet which tops out at 330uH to give a limited current of only 11mA.
Having seen how efficient the circuit was at lighting a 1W LED to prevent the night stumbles, I started wondering if it was good enough to supply an ATTiny13a full of "candley goodness" as per a recent blog post.
Under normal circumstances I would have said not - but in this case the ATTiny13a could be running at a miserly 128kHz (so only ~400μA required by the actual microcontroller). Also recently I re-wrote the candley code using hyper efficient AVR assembler with hopefully not too many wasted cycles.
As well, the super-duper LEDs I use seem to require far less than their stated 60mA - which makes sense as they are cycling up and down with PWM taking out much of the required power - and fair enough too as they are "candle" night lights, not search lights!
I took the poor performing lights and stripped off their inductors, zeners and diodes and replaced them with a 5V1 zener, 1n5817 Schottky and 470uH radial inductor to match the observed super lights. Then I burnt the bootloader to 128kHz and replaced the C-code with assembler all with a handy in-situ programmer.
What a revelation - all "candles" are now burning all night on minimum daylight - recharging the single AA NiMH battery with just a few murky ergs fighting their way through the thick clouds down here in Tasmania. Lovely!
I've been making stupid electronic clocks for a couple of years now, and they all work fine - but looking around for improvements (!?) I'm thinking about ditching the external DS3231 RTC module and maybe going it alone with an AVR humming along with an external clock signal provided by a crystal.
Cutting down on parts (maybe...)
I've obtained a few different crystal/oscillator types which I will look at over the next few blogs, but I might start with a 1MHz unit which arrived a few days ago. Unfortunately I couldn't find a great deal of useful information about its use, so I just plugged it in according to datasheets of similar products and hooked up my god-awful DSO138, forgetting (again) that it has a limitation of 200kHz. Following the same protocols as per a previous blog, I was able to hook up a couple of CD4017 decade counters and using them as frequency dividers I found that the oscillators do indeed kick over at 1MHz. The dividers were chained together and when around 9V is supplied they reduce the oscillator's signal by 10x10 to give 10kHz - which the DSO138 can measure.
Bang on 10.000kHz - nice one unbranded oscillator
Now while it is great to have a reliable clock signal, the real fun would be hooking it up as an external timer for an AVR such as the ATTiny85 and then...er...blink an LED? Firstly, as I'm using the ATTiny85 I'll need a suitable core to bolt onto the Arduino IDE. So off to Spence Konde's (aka Dr. Azzy) github resource to procure ATTinyCore. There is no 1MHz external clock option in the list - so firing up a text editor I added an entry in boards.txt as follows:
Then I'll need some simple reliable code which makes for pretty lights via an RGB breakout board:
After confirming that the code works on the ATTiny85 with regular internal 8MHz timing, I connected up my USBasp to a programming shield and wired in the 1MHz output from the oscillator to pin 2 (XTAL1), not forgetting a shared ground wire as well.
Selecting the required (new) external 1MHz clock frequency, followed by "Burn Bootloader", and then "Upload using Programmer", gave the much admired RGB LED goodness at 1 cycle per second as timed by the external oscillator. Good one!
I think that I will test this signal with a display to give the time of day, and check it periodically to see if it drifts over days/weeks. Then I can see if the 1.000MHz engraving on the top of the oscillator is justified! Note that I did mess up a few times during this discovery process (which has happened too many times before and is really the genesis of this blog - "I've got to document this stuff!"). This memory lapse resulted in a bricked ATTiny85, but I was able to bring it back from the dead with an awesome 12V HVPP fuse resetting thingy from Tindie. I don't believe that the process of changing the clock source is dangerous per se, but I did forget that when you are planning to use an external clock source, you need that source connected to the XTAL pins during fuse setting and uploading (see connections on diagram above and video below). Once I remembered that - all went well. I am still not sure if the 22pF capacitors on XTAL1 and XTAL2 are required when I am using a single external clock source, but it seems that they didn't cause any problems - so why not?
Late one night ( ¯\_(ツ)_/¯ ) I spotted a STM8S103F3P6 breakout board on Aliexpress that seemed too cheap to be real (~AU90 cents). So of course I ordered 5 of them. When they arrived I plugged them into my computer using a micro-usb adapter and ... nothing. So the price is now starting to make sense. The micro-usb connector is only for power, not data.
Little board, lotsa power
Still, there must be a way to talk to this chip, and at least get some quality blinky action going on. I happen to have an ST-Link programmer left over from an exploration of the famous STM32 "Blue Pill" from a year or so ago. After a bit of searching online, I was directed to SDuino which promised "within a few minutes you are ready to compile and upload your first STM8S-based project" which sounded great!
After downloading and installing the STM8 board manager and specifying the ST-LINK programmer, I was able to successfully blink and fade an LED and all was right with the world.
Success?
Or was it? Really this thing would only be useful if I did some interesting project - not the standard blinky. So I thought maybe I might attach a button to one of the pins, and then have the board turn on an RGB LED in a sort of lazy traffic light indicator when the button is pushed. Push the button, stop the traffic, sprint across the road. Way too much head-scratching later (documentation and examples are a bit thin on the ground for this device), and we have the following code...
Originally I was going to put the little one to sleep and wake it up for traffic light action, but alas I could not find any decent manuals, example code, forums, etc. where I could see how to do this, so I settled on the looped checking for button code you see above. It's not great, and I'm not really happy to the have the chip buzzing away checking a digital read constantly (now that will drain a battery), so I will continue the quest for putting this little guy to sleep to save power - but for now it works fine.
I like traffic lights, especially when they're green
I've looked at the LM317 linear voltage regulator in this blog, but at the same time wondered about the efficiency and ease of use of a switching voltage regulator. The linear regulator has the most stable output, but the switching regulator is the most efficient. When I eventually get around to building a power supply unit, I am thinking that a combination of the two makes the most sense. For example you could bring the voltage down from something like a laptop power supply (31V DC) to just a couple of volts above the required voltage, and then regulate the final target with a linear regulator to the required (smooth) output. Most switching regulators that I have purchased seemed to be based on the LM2576 IC - a strange looking 5 legged beast that arrived awhile back, but hasn't been pressed into service yet...until now. The LM2576 IC is "monolithic" which means to say the internal structure has a circuit which has most of the components so very few external components are required to make the circuit work as intended.
Block diagram of the IC from the datasheet
The datasheet and many online resources suggest the following circuit:
So with that in mind I wired up a prototype for testing. It was also an opportunity to test some simple voltage indicators that I had purchased which will hopefully be used in the final PSU design (e.g. monitoring the output of the switching and linear regulators).
I didn't have any 2000uF capacitors in a suitable voltage (e.g. 25V or greater - but now I have ordered 50V 2200uF), so I paralleled a couple of 1000uF units instead (note that paralleled capacitors add capacitance, the opposite of resistor addition). I also could not fit the 1N5822 into the holes of the breadboard (!), so I used a 1N5819 Schottky diode which should be good to 40V and 1A, as opposed to the 40V 3A recommended. It works great! Now I just need to put it onto a PCB and wrap it up in a suitable box.