Author Topic: No restart after brown-out, using low power technique  (Read 220 times)

AgroMe

  • Newbie
  • *
  • Posts: 9
No restart after brown-out, using low power technique
« on: September 21, 2020, 05:14:33 PM »
Hi all,

I am powering the Moteino Trace Antena product with the 7 farad cap much like the original post by Felix.
The application is for a remote irrigation unit which powers up with the sun (or grow light) and works with the light energy using a photo cell.
When the plants go to sleep, so does the controller, but I want to save enough power so I can send a couple of readings at night (future).
The logic I tried is to power down everything, including the brown-out circuitry until the voltage drops close to the brownout.
If it goes too low, then I just shut off everything except the brown-out to make sure the controller will boot when the lights come back on.
The problem is that if the capacitor actually discharges completely, the Moteino will not restart. But if the voltage never drops below the brownout, the power down seems to be working.

The code is something like this:

Code: [Select]
if(photoCell < LIGHTS_OFF){
    if(lowPowerMode){
      /* if the voltage is too low we need to keep BOD and let the circuitry do it's job */
      if(ourVoltage<CPU_CUTOFF){
        LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_ON);
      }
      else{
        /* else try to save as much power by disabling the BOD */
        LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
      }
      /* FUTURE: send a few reports at night */
      return;     
    }
}

What am I doing wrong? When the capacitor is empty, the V goes up slowly but I thought the brown-out circuitry can handle this and wait until the voltage is high enough to do a RESET. But apparently it's not working for me, not sure why :-(

TIA!
Alex

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6357
  • Country: us
    • LowPowerLab
Re: No restart after brown-out, using low power technique
« Reply #1 on: September 21, 2020, 06:22:37 PM »
The problem is that if the capacitor actually discharges completely, the Moteino will not restart.
That's not a problem, it's a fact.

You DONT WANT a brown to happen, BOD keeps the AVR in reset.
If you leave the BOD ON, then while in reset it will drain your capacitor fast. Also, BOD itself being active will eat a nice chunk of current from your tiny capacitor charge that keeps it going.
The BOD is there to prevent the MCU from working erratically, at a voltage that is grossly out of spec for the given speed.

So .... make sure you have a proper power budget that will keep your Moteino running (well - sleeping) through the night, and through a night and N dark days, etc, without browning out.
On the other hand, the BOD is a safety thing. If you fully expect BODs to happen, then it's better to have it, or the atmega can start jumping around randomly including into the bootloader, erasing flash and doing other catastrophic things to the atmega's memory.


AgroMe

  • Newbie
  • *
  • Posts: 9
Re: No restart after brown-out, using low power technique
« Reply #2 on: September 21, 2020, 10:22:13 PM »
Thanks for the prompt reply!

Quote
You DONT WANT a brown to happen, BOD keeps the AVR in reset.

Correct, the whole point of the code logic above is to allow it to shutdown gracefully using the BOD.
Why doesn't it re-start properly when the lights come on and the capacitor is fully charged again?
I have tested this and it only runs after I manually reset, and sometimes even pull the Moteino out completely and plug back in.
So what prevents it from starting after the voltage is above the brownout limit ???

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6357
  • Country: us
    • LowPowerLab
Re: No restart after brown-out, using low power technique
« Reply #3 on: September 22, 2020, 01:39:18 PM »
So what prevents it from starting after the voltage is above the brownout limit ???
I think it's probably a brownout :-)

Basically your cap recharges and it reaches just above BOD limit. Then the thing starts and draws more current than the cap can supply, dipping it below BOD again. So it's in this limbo state as it's trying to charge up, but the solar cell alone can't supply the current, and the cap is charged but not enough to sustain the startup current required.

AgroMe

  • Newbie
  • *
  • Posts: 9
Re: No restart after brown-out, using low power technique
« Reply #4 on: September 22, 2020, 03:17:28 PM »
Actually I've measured this and the cap charges fully; perhaps I should have mentioned this in the original post. Was actually wondering if it could be the radio (holding the interrupt perhaps??). I haven't had time to put a scope on it because I wanted to set-up like a lab way to test this instead of working directly on the grow with all the plants etc. So I decided to post the question just in case someone had seen this before or had any idea why it does not start after the V if fully charged. I'm pretty sure I tested reset manually at least once but IIRC it not always started the Atmel. That's why I started suspecting it could be the radio interrupt.