dragino / LoRa_STM32

Source code for Dragino LoRa module base on STM32 Chip
76 stars 77 forks source link

Firmware shamelessly draining battery when using DS18B20 #16

Closed fabiengagne closed 3 years ago

fabiengagne commented 3 years ago

I am convinced that using a DS18B20 with this firmware will drain the battery in a record time, I doubt the 10 years claim.

The DS18B20_GetTemp_SkipRom() function calls DelayMs(750) which shamelessly runs the processor on NOP at full power for the entire duration of the sensor conversion time. While waiting for the sensor reading, firmware should make use of one of the processor's low-power mode.

See page 15 https://www.st.com/resource/en/datasheet/stm32l072v8.pdf The "Low Power Run" mode seems to be a good candidate at 8 uA and 3 usec wakeup time to normal run mode.

DominusFulguris commented 3 years ago

How often do you expect to be measuring the temperature?While I don't use the Dragino code base (so had to write my own low power state logic), and I agree that changing to a low power state during the 750mS wait would be preferable, I can say that the battery life is predominantly dictated by the sleep current between readings.For the sake of discussion, let's assume the following values:DelayMs() duration is 0.75 second Operating current is 8mALSN50 Battery capacity is 4000mAhSampling interval is 5 minutesSamples per day: 24 60 / 5 = 288mAh used by DelayMs() per day: 0.75 8 * 288 / 60 / 60 = 0.48 mAhFor one year, this is 175.2 mAh or 4.38% of battery capacity.

fabiengagne commented 3 years ago

I doubled checked your estimations and they are correct to a large extend. It may improve battery life by 1 year at most, at 5 minutes interval with one sensor (my case). Consideration should be taken with several sensors per node.