VBAT, How does it work, on the Photon

I have seen a couple explanations so far. It works without software sleep modes, it only works with software sleep modes. Since my Photon has not yet arrived, I can’t test it, so lets get the scoop from the pros .

  1. does it need any software sleep modes to work?
  2. Does it “switch in” or just gradually start supplying power when needed?
  3. VBAT does not supply power to charge the battery/Cap on the pin (you have to do that yourself)?
  4. VBAT only provides power for the RTC and backup memory, the WI FI and processing is not powered by VBAT?
  5. After power is restored to 3v3, does the processor start up on the line of code where it left off, or where?
  6. Any other information pertinent that I did not mention.

@peekay123 explains:

Thanks, that clarifies a lot.

So, if I understand it, VBAT has no use yet?
If I need a battery backup (UPS) now, I should put a battery on my 5v (Vin) pin ?

Now my remaining question (Once the "special" 4KB space is implemented), What happens after the 3v3 is restored?

peekay123
Elite
31m
@Jack, VBAT is a common function of most microprocessors, including some Atmel processors (think Arduino). None support the functionality you are looking for. The pin is design to assist in configurations where power may be turned off but program “state” needs to be preserved without using eeprom for example. With careful design of supporting hardware, your desired configuration can be achieved, just not using VBAT. So in this respect, I respectfully completely disagree that VBAT is completely useless. wink

Then if not useles on the Photon, how is it useful? Why would I put my battery on VBAT rather than putting my batery on the 5volt line, or even the 3v3 line?

@Jack, remember that VBAT maintains the RTC and the portion of RAM. This is very useful for many applications. However, it is not always necessary as you pointed out.

Again, I will point out that if your system is meant to be turned “off”, a battery on VBAT may be useful if keeping the RTC and key RAM after reset is important. This is different if you use a battery as a UPS where you never want power to be turned off. I hope you can see the difference.

Can you keep the RTC and RAM after a RESET? I think not. I may not be correct in my assumption tho. I thought a RESET cleared all memory, and started over. Am I wrong on that?

@Jack, reset does not cause memory to be “cleared” but you can’t depend on it’s content being maintained EXCEPT for the special VBAT area. This is one of the purposes of the VBAT function. Obviously, even the battery on VBAT could fail so the ultimate method is in eeprom but it will degrade if too many write cycles are done.

If you want to read up on the details of the STM32F205 and all its glory (including VBAT), take a look at this reference manual. :grinning:

1 Like

Is that to say, if i hit the reset button, all the variables are retained? And the processor will start running on the line of code after the one that was just executing? I think not. Sorry to disagree, but

Hi @Jack

I really suggest you read the STM32F205 reference manual that @peekay123 linked to above. It explains it pretty well and the Vbat parts are only 1-2 pages.

The values of the RTC and some special registers and the special SRAM section are all held during the main power outage by supplying Vbat. Your code can squirrel away a token value of your choosing in the special registers that says what your code was doing last and your code can be written to pick up where it left off when you come out of reset. Notice I say “your code” since the burden is on you as the programmer to make this work. The processor is just providing a place for you to store some values that your program can use when it boots up.

The values your write could be things like the current time zone or the last user setting or whether or not the last operation completed successfully. They could be the last real-time that you completed an operation so you know how long you have been offline. Hopefully that helps you see what the feature could be used for.

1 Like

Sorry, but I still do not understand how VBAT can be used with success.
Has anyone used it with success? I think not.
I don’t want to read specs from some web page, I want to know how it really works.
Sorry if I am blunt, but… inquiring minds want to know…
As far as I can tell now, it does not do any useful function. Prove me wrong please.
@zachary

The key difference between placing a battery on VBAT vs on the 5V line is that when asleep, the VBAT supply only powers the RTC and the special RAM. This it can do with a far lower current than you need to keep the entire chip running. So, for a given capacity battery or supercap, it will keep the RTC running and the special RAM intact for a far longer time than if it were powering the entire chip.

That is the advantage - it does require software support to exploit this feature, it is not like an MSP430 that just keeps all RAM intact and picks up where it left off when it exits sleep mode. There are many other chips that behave similarly to the '207 chip inside the photon, it is a reasonably common feature in low power MCUs (some will only preserve a few registers, and not an entire page of RAM.)

I hope this explains it better, when combined with the previous descriptions.

3 Likes

@AndyW just to clarify because I know this will confuse @Jack, again, VBAT will only kick in when power to the processor is removed and not when it is put in sleep mode as you suggest. :smile:

@peekay123, I am confused usually, but I do understand that. My first of several questions is, what happens once the 3v3 is restored. Does the system do a reset, or does it start running again where it stopped?

It’s good you’re asking questions, but seriously read the reference manual that was linked earlier and then http://lmgtfy.com/?q=VBAT+Pin and I think you will begin to understand the previous answers to your questions. If you refuse to consult the manual, you’re gonna have a bad time.

1 Like

@Jack, the removing power to the CPU and the applying it again IS a reset condition and it does NOT run from where it was.

Wow, I think I have been insulted for being stupid.
No one says how VBAT works on the Photon, but they insult me for not knowing?

It’s not possible to continue running from the current location after entering low power mode because that would mean preserving the entire contents of ram, including the stack.

The code will continue from the beginning, but since you have the backup RAM preserved, then you can use that to make smart decisions about where to resume from.

I’ll give some pseudocode but must stress that this is not implemented yet - we would like feedback from the community about the best ways to use the backup RAM.

// retained variables use a new keyword `retained`
retained int step = 0; 
retained int counter = 0;

void setup() {
   if (step==0) {
       doStep1();
       step = 1;
   }
   
   if (step==1) {
       doStep2();
       step = 2;
   }
   
   // etc..
}

void loop()
{
    Serial.println(counter++);
    // this will continue counting from where it left off 
    // when main power is removed and then restored

}

I hope this is clarifying and doesn’t add more confusion!

2 Likes

@Jack and all, i will be temporarily locking this topic until we come back with concrete examples about VBAT so that you have a full understanding of what this pin is for.

I think the name VBAT might be misleading you from its functionality but let’s wait for the example from the Particle team! :smiley: ping @BDub @christine

4 Likes