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

Thoughts on further optimizing sleep power. #4

Open
joeatbayes opened this issue Nov 16, 2023 · 1 comment
Open

Thoughts on further optimizing sleep power. #4

joeatbayes opened this issue Nov 16, 2023 · 1 comment

Comments

@joeatbayes
Copy link

joeatbayes commented Nov 16, 2023

Your write-up and code are some of the best examples I have seen in either the Arduino or ESP ecosystem.

I have been working on my own power optimized designs. I didn't have a CPU module with low enough power consumption even with deep sleep so I used some other tricks. If you combine what I did with what you did it could provide even longer battery life.

Added a low-side mosfet switch to disconnect sensor power when sensors are not being actively used. Found this necessary for greedy sensors like magnetic field sensors and MPU6050. The CPU powers up the sensors by setting a IO pin HIGH to energize the gate on the N-channel mosfet. I use a 1 meg resistor gate to ground to force sensors off when the CPU is booting. As soon as I finish taking readings I turn of the sensors while the CPU may run a bit longer transmitting the data.

Added a DS3231 clock chip that includes alarm functionality that I use to facilitate power conservation. I wanted it for accurate multi-year time keeping but found that it added some features that make managing the CPU a lot easier like low-voltage reset. It is ultra low power and can run for years on a coin cell.

  • Add a low side n-channel mosfet switch that cuts ground connection between charger module and CPU module reducing power consumption down to the leakage value of the transistor. Call the Gate on this mosfet CPWR
  • The clock chip includes alarms that can be programmed to fire every second, every minute or every hour. When they fire they activate it's INT/SQW pin.
  • When the alarm fires it generates a pulse which energizes CPWR gate on the mosfet that restores power to the CPU. I use a capacitor to hold the CPWR HIGH long enough to allow the CPU to set a PIN to HIGH that keeps CPWR high until the CPU finishes working.
  • The clock can be connected to run direct from the TP4056 but I also used a coin backup because I don't want to loose time and date when the 18650 battery needs to be replaced. No need for a separate regulator for the clock chip because it is 5.5V tolerant.
  • Once the CPU finishes it's work, it sets that pin to LOW which drives CPWR low turning off the mosfet completely disconnecting the CPU until the clock pulse fires again.
  • A manual wake-up button energizes the CPWR mosfet gate to turn the CPU on but I can not always tell if the wake-up was because the button was pressed versus the alarm firing unless the user keeps their finger on the button long enough to boot and take a reading.
  • The clock chip must be in circuit between TP4056 and CPU power mosfet. Otherwise it's alarm pulse can not be used to energize the CPWR mosfet gate.

My sensors are not always in WiFi range so I write data to SPIFFS and send in batch once they can connect again. I extended this so I have a transmit interval that may be longer than my measure interval. Since it takes a little time with CPU active to negotiate the connection this can save a bit more power.

One downside of this approach is that any data you want to retain between wakeup events must be stored in SPIFFS because the CPU can not retain RTC variable storage when completely powered off. I read there is some NVM on this CPU but have not tried using it.

@TD-er
Copy link

TD-er commented Nov 16, 2023

You could also look into the Arduino "EPROM" library, which is just a mapping to some flash sectors.
Thus you must do the administration yourself on when to erase blocks and preferrably allocate multiple blocks so you can 'page swap' what block to use next.
SPIFFS can get corrupted when running low on power, so better use something that's so low-level you can control how to handle incomplete written blocks.

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

2 participants