Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize power consumption #7

Open
biemster opened this issue Sep 25, 2022 · 155 comments
Open

Minimize power consumption #7

biemster opened this issue Sep 25, 2022 · 155 comments

Comments

@biemster
Copy link
Owner

The current code is based on the SDK v3.1.1.2 lowPower beacon example, which seems to last on a coin cell for a couple/few weeks. There is also a git repo with a power optimized firmware here: https://github.com/ThuanLeUte/ble-st17h66_fw_power_consumption, and there might be other ideas to lower power consumption (like putting the chip in deep sleep and just wake up for a single broadcast every 5 sec).
First it's necessary to actually measure the power consumption of the different firmwares, and then start experimenting with the code to get it lower.

@biemster
Copy link
Owner Author

@vadimkozhin did you ever analyse the power draw with the rigol on your bench?

@vadimkozhin
Copy link

did you ever analyse the power draw with the rigol on your bench?

@biemster Yes. It is aligning with datasheet - 4.7mA during transmit. For now I can't get anything less from a chip, so I decided just plug in the new batt and leave it to check if it lasts more then a week...

So far it works from 16.08. It transmits once in 5 sec.

@biemster
Copy link
Owner Author

Thanks! Did you also measure the current when idle?

@vadimkozhin
Copy link

It is... the same. I've not done precise measurements, just watch it on my power supply. It jumps from 4.7 to 5.2 approx.

@biemster
Copy link
Owner Author

I hope I will be able to improve on that, since the tags I got usually had the battery in place, and were switched on by pressing the button. I guess those tags are lying on the shelf sometimes for a month or more, which would drain the battery in that case.

@vadimkozhin
Copy link

Yes, according to datasheet there is a sleep mode with less current, but it is deactivated only with a hardware pin e.g. with button preset.
image

There is (according to datasheet) couple of interesting options, but I cannot succeed to activate them, with provided SDK samples. Good luck with experiments! :)

@biemster
Copy link
Owner Author

Thinking about it, 5mA on a 230 mAh 2032 should only give you 40 hours of running, so I guess it is idling already on a lower power mode?

@vadimkozhin
Copy link

5mA on a 230 mAh 2032 should only give you 40 hours of running, so I guess it is idling already on a lower power mode?

Exactly my thoughts! So that's why I decided just plug in the battery and see what will happen after a week or two. So far it is on since 16.08, so yes, definitely idling. May be need to find a way to accurately measure a batt consumption.

@biemster
Copy link
Owner Author

biemster commented Sep 26, 2022

I had to replace the battery in one of my tags already for the second time, so I'm getting about a month or so, give or take a week. That's shorter than I was hoping.. The 1uA sleep mode with RTC will be my goal, do you think the datasheet means with external RTC?

@biemster
Copy link
Owner Author

So I put in two fresh batteries when I opened this ticket, but they both seem to have died already 4 days ago. That puts it on just over two weeks with an advertisement every 3 seconds, which is a bit disappointing I must say.
Maybe I should prioritize this.

@vadimkozhin
Copy link

Mine is two months and still appears on the map. 8 sec interval. Will wait till it drain the battery.

@biemster
Copy link
Owner Author

Well done! I'll have to think out a way to accurately measure the power draw first. All I have at the moment is a basic multimeter from Lidl, I should be able to do better than that. Also the 2032s I'm using are not of the best quality, so my measurement could have been a bit biased.

@biemster
Copy link
Owner Author

@vadimkozhin do you by any chance know how long it takes the mcu to send out the advertisement packet?

@vadimkozhin
Copy link

do you by any chance know how long it takes the mcu to send out the advertisement packet?

Unfortunately not. The tag is "traveling" at the moment :) If you still will be interested in this interval, ping me in a week or so, then tag will be again in my hands and I can measure actual interval with oscilloscope.

@olivluca
Copy link

I don't know if it's useful or not, but maybe looking at this project and asking @pvvx could give you some ideas: the battery lasts around 1 year. Looking at the datasheet the telink chip is more efficient (deep sleep 1uA with ram retention vs. 4uA for the st17h66, transmission 4.8mA vs 8.6mA) but OTOH it has to manage a display and the temperature/humidity sensor.

@biemster
Copy link
Owner Author

I've been eyeing that project for a while as well, especially since the 17h26 seems to be a clone of the telink used in those thermometers. @pvvx seems to be very able with such material, good idea to ask him for suggestions.

@pvvx
Copy link

pvvx commented Oct 21, 2022

I didn't get good results with the available examples from the SDK for PHY62xx and AiThinker on PB-02-Kit modules (PHY6212).


The best example is with AT-BLE-UART:
Before the test, enter the commands:
AT+BLEMAC=234567123456
AT+BLEADVINTV=2560
AT+RST
reboot...
AT+SLEEP=0

Adv-Interval: 2560*0.625 = 1600 mc.
The result of measuring the current along the 3.3V line only to the module:
The current averaged over 140 seconds is 40.7 μA.
image
The current in sleep mode is about 19..20 uA, which is a lot.
Usually the sleep current is highly dependent on the software implementation and not on the directions in the datasheet...

@biemster
Copy link
Owner Author

Thanks @pvvx ! That's very useful info. With 40uA average you'd get 230 days out of a 230mAh button, that's considerably better than the two weeks I'm getting now, and it could even be stretched to a year with a longer adv interval.
I'm still thinking out how to do the power measurement, and get a nice plot like yours, without breaking the bank on new equipment. (although I could just take an interval of 10+ seconds, and measure the sleep current with my DM as well I just realize..)
I assume you made this plot with a scope?

@pvvx
Copy link

pvvx commented Oct 22, 2022

With 40uA average you'd get 230 days out of a 230mAh button, that's considerably better than the two weeks I'm getting now, and it could even be stretched to a year with a longer adv interval.

These are very bad indicators.
For a key on a typical BLE SoC with advertisement every 3 seconds, the total average consumption should be less than 10 uA.

In active mode for most BLE SoCs (Telink, nRF, ERF):
wake-up (1..2 ms) and advertising transmission (2 ms) - average current 5..9 mA

In sleep mode with RTC and active 32 kilobytes of RAM - 2..3 uA.

( 7mA * 3ms + 0.003mA * 2997ms ) / 3000ms = 0.009997 mA = 10uA

I'm still thinking out how to do the power measurement, and get a nice plot like yours, without breaking the bank on new equipment. (although I could just take an interval of 10+ seconds, and measure the sleep current with my DM as well I just realize..) I assume you made this plot with a scope?

https://github.com/pvvx/UBIA/tree/master/PowerProfiler

For best sampling results (up to 50..100kHz):
GY-169(INA169) + oscilloscope https://aliexpress.con/item/4000107917726.html
or INA199 + oscilloscope

  • Replace the shunt resistor with a switchable set with a maximum resistance of 100 ohms.

PS: Without PowerProfiler, there is no point in programming BLE.

@biemster
Copy link
Owner Author

biemster commented Oct 22, 2022

Just ordered a GY-169 INA219

@pvvx
Copy link

pvvx commented Oct 24, 2022

For a key on a typical BLE SoC with advertisement every 3 seconds, the total average consumption should be less than 10 uA.

Module TB-03F, TLRS8253, test_adv_power1: period adv 3 sec, RF TX 0 dB, ADV_TYPE_NONCONNECTABLE_UNDIRECTED.
Average power 5.8 uA at 3.3V.

image

Module TB-03F, TLRS8253, test_adv_power3: period adv 3 sec, RF TX +3 dB, ADV_TYPE_NONCONNECTABLE_UNDIRECTED.
Average power 6.1 uA at 3.3V.

image

@biemster
Copy link
Owner Author

Those are great numbers @pvvx ! I should definitely target sub 10uA seeing those results.

@pvvx
Copy link

pvvx commented Oct 26, 2022

With 40uA average you'd get 230 days out of a 230mAh button

The documentation for PHY62x2 does not indicate power consumption in sleep mode with active-retention RAM. And measurements with examples available in the SDK give disappointing readings - 10..20 uA, depending on the retention RAM size.

ST17H66B2 datasheet: 4uA @ Sleep Mode with 32KHz RTC and all SRAM retention
image
Not known which memory block has a specific leak in the sleep (0.6V).

@biemster
Copy link
Owner Author

This is more complicated than I thought. I was hoping there would just be a function in the SDK power manager to call, with an enum or so to specify the sleep mode.
What do you mean by "a memory block with a specific leak in the sleep (0.6V)"?

@pvvx
Copy link

pvvx commented Oct 26, 2022

hal_pwrmgr_RAM_retention(RET_SRAM0|RET_SRAM1|RET_SRAM2);
hal_pwrmgr_RAM_retention(RET_SRAM0);

During sleep, the LDO switches to 0.6 V and the leakage currents to different SRAM blocks are different.

@biemster
Copy link
Owner Author

biemster commented Oct 28, 2022

That seems to be present in the current code already on L140. I'm wondering why sleep is broken in this implementation, I hope the INA219 arrives soon and I can start experimenting.

@biemster
Copy link
Owner Author

I didn't get good results with the available examples from the SDK for PHY62xx and AiThinker on PB-02-Kit modules (PHY6212).

@pvvx There is a newer version of this SDK including the sources of rf.lib where some of the sleep code is located available here:
https://github.com/duanmubingshuai/test
Maybe those can help you get better results?

@pvvx
Copy link

pvvx commented Oct 28, 2022

I tested on the PB-02-Kit by cutting the power wire of the module on the PCB.
But on other outputs of the module, leaks are possible...
A lot of consumption was due to taken examples from the SDK.
Rewriting everything to my version turned out better:
PHY6212_PB-02_tst-adv-nc

The reason for the high consumption of PHY6212:

  1. The program is placed in RAM. A large amount of RAM is constantly fed. Current in Sleep 5.6+ uA at 64KB.
  2. Long time to wake up the chip from sleep. From 2 ms to the start of transmission of advertising packets.
  • If you don't change pGlobal_config[MAX_SLEEP_TIME] to a value greater than the advertising interval, the chip will unnecessarily wake up for a couple of ms and sleep again every cycle of the advertising interval. This leads to an increase in the average current consumption.
    (There is a patch for GCC: https://github.com/biemster/st17h66_FindMy/blob/main/lib/rf/patch.c#L7712 )

This is PHY6212, and ST17H66 is most likely similar to PHY6252. ST17H66 and PHY6252 have a cache for executing code from FLASH. PHY6212 does not.
There are different SDKs for PHY6252 and PHY6212:
http://wiki.phyplusinc.com/doku.php?id=menu:sdk
PHY62XX SDK v3.1.1 (适用PHY6222/PHY6252)
PHY62XX SDK v2.1.1 (适用PHY6212)


PHY6252 used "section_xip_code" (LR_ROM_XIP 0x11020000 0x020000)
https://github.com/biemster/st17h66_FindMy/blob/main/FindMy/scatter_load.sct#L49
But there are no such sections for GCC: https://github.com/biemster/st17h66_FindMy/blob/main/FindMy/RTE/Device/ARMCM0/phy6202.ld

@biemster
Copy link
Owner Author

Got my INA219 today! I don't have an STM32 or TLSR lying around so I can't use the PowerProfiler directly, but I have some ESP's, pico's and arduinos to spare so I'm confident I can build something workable. @pvvx 's repo is a great resource for this, so it shouldn't be long!

@biemster
Copy link
Owner Author

biemster commented Nov 17, 2022

So now I read the INA219 inputs have a bias current of 20 uA, making measurements at that level very inaccurate :(
I guess it's back to the drawing board then..

I should have listened better to @pvvx and buy an INA169 which has an input bias current of 10 uA, although how much of a difference would that make?
The INA199 has an input bias current of 28 uA, even worse than my 219.
On the other hand the INA326 has an input bias current of 2 nA (nano!), but I can't find any modules from my favorite overseas supplier. Wait that's not a power monitor.
Any suggestions are more than welcome!

@pvvx
Copy link

pvvx commented Feb 4, 2023

Finally came in the mail "iSearching"...
pvvx.github.io/iSearching

@pvvx
Copy link

pvvx commented Feb 4, 2023

does any of you maybe have a setup with a debugger attached, to run a quick check on where it blocks?

How will Jtag work during the Sleep SoC if the chip is powered down?
Jtag (SWD) are not suitable for debugging BLE chips.

@biemster
Copy link
Owner Author

biemster commented Feb 4, 2023

How will Jtag work during the Sleep SoC if the chip is powered down?

😄 that was just to debug the interrupts, they where not working during normal operation either. But I fixed that now biemster/st17h66_blinky#2!

The only issue left for blinky now, is that when the soc goes to sleep it seems to turn off the RTC as well, or the interrupts, or both. Or it is actually waking up, but in a uninitialized state.
image
(considering the 1uA draw I measure, the RTC should still be running?)
When that is fixed, I'm going to instead of blink the light, send an advertisement on the phy.

@pvvx
Copy link

pvvx commented Feb 13, 2023

Is this the correct board pinout?
image
image
https://pvvx.github.io/iSearching/

@biemster
Copy link
Owner Author

Is this the correct board pinout?

That looks about right yes. (I only every use p9 and p10, and p3 (and batt))

@pvvx
Copy link

pvvx commented Feb 13, 2023

And how are things with OTA on native firmware?
PhyOTA v2.2.1, PhyApp 1.2.1 is not working.

@biemster
Copy link
Owner Author

I've seen some references of OTA in the SDK, but I never looked into that at all. Would be quite handy though, although that would require the whole BLE stack and SDK right?

@pvvx
Copy link

pvvx commented Feb 13, 2023

Yes, the entire BLE stack will be needed.
But different bootloader combinations are also possible.
On this key fob, I want to make a switch in HA and a label with the RSA code to open the gate, and so on...

@biemster
Copy link
Owner Author

That's a very interesting idea! I'm also planning to use them as a simple wireless button, I'll open a repo for this soon. Didn't think much about security though, which would be necessary.

@biemster
Copy link
Owner Author

@natschil seems to have gotten Zigbee working: biemster/st17h66_RF#7, so I will likely adopt that for my HA switches and ditch BLE in further work.

@natschil
Copy link

natschil commented Mar 1, 2023

I don't want to hijack the discussion, but I'm having some issues flashing after de-soldering the buzzer - has anyone had the same problem? Previously I was able to flash with UART connected to P9 and P10 on the back of the board..

Edit: it seems that without the buzzer, the board can be powered over the UART pin, so to really reset it it is necessary to disconnect both uart and power.

@vadimkozhin
Copy link

Some updates, for those who interested. Tag still works. Can see it from the app. Deployed Aug 16, 2022.

@biemster
Copy link
Owner Author

Edit: it seems that without the buzzer, the board can be powered over the UART pin, so to really reset it it is necessary to disconnect both uart and power.

yes thanks for reporting this, I'm having issues regularly with this as well when running the flasher

@biemster
Copy link
Owner Author

Some updates, for those who interested. Tag still works. Can see it from the app. Deployed Aug 16, 2022.

That's amazing, it's on a 5s advertisement interval right? I really should add battery level reporting to the status byte.

@vadimkozhin
Copy link

For those who interested: my tag stop transmit on 26.04. So, the tag works from Aug 16, 2022 till Apr 26, 2023. Traveled across EU and stable transmits 24/7, no any freezes or bugs detected during about 8 months.

@biemster
Copy link
Owner Author

biemster commented May 2, 2023

Aww poor thing! But that's a great achievement, I hope some of mine will reach that too.
I very much need to wrap up this power minimization effort, and choose between the SDK code and the st17h66_RF code, especially since quite a few people put significant effort in it.
I hope I'll get some time off work soon for this, and thanks for the update!

@biemster
Copy link
Owner Author

biemster commented May 2, 2023

@vadimkozhin I've been pondering sending a couple out in some sort of art / social experiment, just to see where they travel, has your tag been in a similar project since it traveled a lot?

@vadimkozhin
Copy link

vadimkozhin commented May 2, 2023

@biemster I've pass the tag to my friends who has leave for business or travel during last months. Cyprus, Italy, Luthuania, Poland, Netherlands and Germany so far. Works and transmits each time perfectly. I've contact them during travels, and compare the locations. Very accurate results, up until the side ot the street. Amazing!

One thing that suprises and scares a bit — carriers never recieves a single standart Apple warning about 'tag is following you'. I'm having also an original airtag atttached to my dog, but registered not on my id, and it alarms each time when I walk with the pet...

@biemster
Copy link
Owner Author

biemster commented May 2, 2023

That's amazing indeed! And scary! I don't have an iDevice, so I can't corroborate, but I definitely thought that this single key implementation would light up every iPhone that was carried along..

@Itheras
Copy link

Itheras commented May 2, 2023

The alerts work for me but with a diminished sensitivity which I don't consider bad . If I am around the block walking I get no alerts but if I am driving for some distance after a certain amount of time I get an alert.

@vadimkozhin
Copy link

@Itheras Yes, for me is the same. Seems like if the tag which is not registered on same id as the phone travels some distance together the alert appears.

But if the registerd phone travels with this setup, not registerеd phone does not recieve an alert, which is completely fine. And first case is also ok. It prevents attaching the tag to person and spy on them without any notice.

@olivluca
Copy link

olivluca commented May 3, 2023

I didn't manage to reprogram the tag yet, but my use case would be to attach it to my car and bicycle, hence I wouldn't want the potential thief to be alerted if he has an iphone.

@vadimkozhin
Copy link

@olivluca I agree. I just mention it, but is it a bug or a feature depends from the use case 😁

@Itheras
Copy link

Itheras commented May 3, 2023

I agree is my experience that the decreased sensitivity make it more suitable for that use. You still get alerts but they behave differently, if attached to a vehicule it takes a longer round trip in a short period for it to trigger in a bicycle it probably won't trigger since it seems the distance is a mayor factor in it triggering. a few miles at least 15+. also even if detected the fact that there is no buzzer to try and locate may spook the thief in to just abandoning what is stolen . in my experience it still has anti stalking functionality but the changed behavior give you more time to track the stolen asset before it gets detected.

@johnbaker26222
Copy link

johnbaker26222 commented Jun 2, 2023

It’s possible to reduce the size with a dremel tool smaller than the CR2032. Then attach power wires to the VDD cap and use conductive glue to the battery since solder won’t stick. Then harden it all up with epoxy.
https://postimg.cc/gXHNzQz2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants