Samstag, 3. September 2016

Power supply for µCs via LDOs

There are plenty of LDOs on the market - some cheap, some expensive, some with only three terminals, other with 5 or more. So how to decide upon a good LDO (Low DropOut regulator)? And why use a LDO when it literally burns energy within it's pass transistor? A switching regulator feels way more efficient as it only takes as much energy from the source as is needed on the output?

This all depends on your usecase. If you have no constraints in your power supply scheme like when using a USB power supply or a 12V switching power supply, you may use a switching regulator. It has a little ripple on the output voltage which may be disturbing in some cases, for example if you want to use an ADC. But it won't get too hot, and 12V down to 5V or 3.3V can be done quite efficient for medium loads.

Here's the point: It depends on your load. A switching regulator won't adapt as fast to changing loads, for example when a µC goes to deep sleep and suddenly wakes up. There the load will jump from a few µA p to 100mA or more. For the time when the µC is sleeping, the quiescient current of the switching regulator is usually many times higher than that of the µC. If the µC is sleeping long time and only wakes up every so often - or your wake-up load is below for example 10mA-, a LDO is the more efficient choice.

For my DIY clock and my mobile ESP8285-based sensor I wanted the most efficient LDO possible. The newest and most promising ICs are in form factors that are nearly impossible to solder by hand. So it had to be SOT23 size ICs. (N.b., old ICs like *7833 or *1117 have a high quiescient current of ~5mA, usually making then unusable with battery driven gear.)

Most efficient LDOs for DIY use.
For the 3.3V with a load of 250mAh and even more I found several ICs:
- HT73xx (7µA Iq)
- HT78xx (8µA Iq)
- XC6206 (2µA Iq)
- MCP1700 (2µA Iq)


I built up small PCBs which I could solder in front of my Clock and ESP.

They all delivered the load and voltage as expected. Differences became obvious, though.
The XC6206 is the cheapest of all those ICs. Unfortunately, it has a dropout voltage of max. 680mV at 200mA load. While this is great when your power comes from a USB supply, it means that a LiIon battery can be used only down to 4.0V! Also, the XC6206 becomes unstable very soon when driven by a LiIon battery with a voltage range of 3.0-4.2V. It is very sensible to load changes as well and starts to swing easily. I needed to provide a polarity protection as even short reverse polarization leads to a burnt chip.

Power consumption with different LDOs.
While the HT78xx (500mA max) and HT73xx (250mA max) also seemed to give stable performance, they didn't cope well with the load profile of sleeping 290s at <25 µA and then wake up for ~600ms at 70mA with short spikes of 250mA and more. Same behaviour shows with the clock which constantly switches between ~2mA and ~100µA. The datasheet has no graphs or values for the supply current with loads bigger than 40mA. The reason seems to be that the load on the battery significantly increases. The battery lost more than 15mV per day with these ICs. They're great when there is a wall plug involved or a huge battery and other big power hungry components, but for the ultra low current consumption I need they just don't cut it.

So the MCP1700 is the most stable and real economical LDO in this test field. Battery voltage drops about 5mV per day, leading to a runtime of roundabout half a year with my 900mAh LiIon battery.

My next tests are with lowering the voltage to 3.0V. The HT7330 showed the same behaviour as the HT78xx/HT73XX with 3.3V before and put a too big load on the battery. Interesting effect - after a runtime of more than one day, the HT78xx became much more stable and reduced the power consumption to values close to the MCP1700 ICs. I'm still waiting for MCP1700-302, I hope to shave off even more µAs to prolong the runtime with them.


Samstag, 20. August 2016

Further improving powersaving with ESP8266 and LUA / NodeMCU

I already optimized my NodeMCU firmware - LUA code to send data and then go to sleep after less than 10 seconds. That now takes a bit more than 1.2 seconds. That was a great leap forward to run a mbile sensor on a single 14500 LiIon cell with 900mAh for over a month.

The first improvement was done by moving the DeepSleep call from the Close Connection handler within the "http-code" to the On Receive handler. This led to deep sleep at less than 50µA after about 1.2-1.6 seconds.

Going to sleep after reiception of the data has been
acknowledged by the server.
















Today I tried to directly go to sleep after calling the send-command with the buffer of my data. This led to no data being sent at all - the sending is done asynchronously and the DeepSleep command just interrupts it before even being started.

The solution is a timer call. Maybe it's possible to shave off a few more ms, but I am sataisfied with the result so far.

Directly after the send-command add:
tmr.alarm(0,150,1,function() node.dsleep(deepsleep_time*1000) end)

So the ESP is going to sleep after 150ms after the send command. It works and successfully delivers the data to the server, so now the wakeup time is down to roundabout 0.6s. This means nearly doubling the runtime on a battery cell! (Another ~100ms are saved by using a ESP-01 with black PCB instead of ESP-12E, by the way.)

When calling deepsleep with a short timer after the send
command, the wakeup time becomes significantly shorter.

Update 24.09.2016: With trial-and-error I could go down to 120ms instead 150ms for the DeepSleep-timer-call. While this doesn't seem much, it is saving 5% of power. instead of 600ms, we now have 570ms of awake-time, summing up to 45,6mA used instead of 48mA. During the real 290s DeepSleep, the power used sums up to 7.25mA. Average power consumption is down to 181,88µA instead of 190,12µA.
Also, the LDO is now a MCP1700 with 3.0V output, which should give another reduction. It helps using the full voltage range from 4.2V down to 3.0V of the LiIon battery.

Samstag, 6. August 2016

Different response times with different ESP modules

While optimizing the ESP-based temperature and humidity sensors for my home I stumbled upon a weird issue: The different modules show different times to connect to Wifi and send the data. This was a real issue with tha battery driven sensor as there the data was always sent after roundabout 4 seconds. Looking with a 1R and the scope at it, it became clear that the connection/wake time is much longer, even more than 10 seconds.

ESP-12F on an adapter PCB.
A bit could be solved in software. Going to deepsleep after reiception has been confirmed (on:receive-handler) brought the wake-time down close to the self-timed values of the board. Using a static IP borught the self-measured time down to 0.3-0.4s, being really awake for about 1.2s. The timing code used on my other modules revealed something:

ESP-01 old version (512kByte flash, blue PCB): 9-61s
ESP-01 new version (1 MByte flash, black PCB): 3,1s
ESP-12E: 2.95-3.05s
ESP-12F: 4.1s

It doesn't matter at which distance the sensors are to the base station. The connection time is quite stable around those values, only the old ESP-01 boards really vary between those values, most of the times at 15s though. The modules use the same firmware and the same code (one variable differs between the sensors which is their name which gets sent).

It is clear that the first versions may have a different µC stepping and/or worse layout than the newer modules. But I would have expected the ESP-12F to outperform all other boards, which clearly isn't the case. Maybe someone knows the reason for this behaviour. Leave a comment if you do!

Samstag, 30. Juli 2016

ESP8266 NodeMCU / LUA - Reprogram with init.lua and deepsleep

Adding a snippet helps re-programming a ESP with
init.lua calling deep sleep without flashing the whole
firmware again..
If you name your main program init.lua on a ESP8266 with NodeMCU firmware and it uses deep sleep, you need to flash the whole firmware again to upload a new program version. But there is a nice workaround. When using Esplorer, you can put small scripts on the buttons called "Snippets". When connecting the USB-to-serial adapter, hitting "Open", you have a short time for pressing this snippet button and the commands will be executed.

This way it's not not necessary to re-flash the whole firmware, but just upload your new version and test on.

Click on the "Snippets" tab, choose the snippet you want to add on the left side, and add these two lines:
file.remove('init.old')
file.rename('init.lua','init.old')

You can also rename the button with a text that suits the task.

Sonntag, 17. Juli 2016

Home logging: Power save with ESP based sensors

Until now, the ESP based sensors were running as a tiny web server. This means they're at full power all the time, 80mA average according to the data sheet. With soldering a tiny wire to a pin on the ESP-01-modules it is possible to let the ESP sleep for some time - at less than 100µA usually. This greatly reduces power consumption and even makes battery based wifi sensors possible. The ESP is awake for collecting and sending data for a few seconds and then sleeps a long time.

For using deepsleep, ESP-01 needs a wire from Pin 8 (GPIO16)
to RESET. Magnifier glasses help with this modification.

I had to rewrite my data fetching logic for that. Instead of calling the web servers on the ESP modules, the modules now collect the data, send it to the Raspberry Pi and go to sleep for five minutes - more or less, the timer is quite inaccurate. 300 seconds tend to result in 280s, plus some seconds for connecting to Wifi, reading the sensor and connecting and sending the data to the server. Thus the rrd databases must accept the data more frequently, I had to rebuild them:


 rrdtool create /var/www/rrd/bedroom.rrd -s 280 DS:temp:GAUGE:600:-40:100 DS:hum:GAUGE:600:0:120 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460


To receive the data on the RasPi, a python CGI scipt helps:
http://pastebin.com/jXQRPKbt

The LUA script has several optimizations already which help it running faster (creating the send string with a table and table.concat for example) and let the ESP sleep earlier again. One enhancement is to compile the needed modules (Si7021.lua to Si7021.lc, delete the .lua afterwards). The main program can be compiled as well and renamed to init.lua for faster startup. A minor glitch in that program keeps the ESP awake unneccessary long - moving the deepsleep call from the on:disconnect handler to the on:receive one helps getting the wake-time down by several seconds.
For mobile ESPs until now the MCP1700 LDO behind a LiIon battery gives the best performance. Without the power LED, but a Si7021 connected the quiescent current during deep sleep is down to ~45µA. A DHT22 worked well over weeks, but the quiescent current is way higher and it is really imprecise and slow.