2024-05-08 12:05 PM
Hello.
I am trying to save variables to flash when there is power loss that i detect using PVD. I got PVD to work correctly and trigger interrupt at 2.9V, but now i cannot find the right examples to see how to save the variables quickly to flash. I have about 5ms from 2.9V-2V to to save them, how many and how big(uint32_t?) do you think i can save. Those variables are my timer counters and some user defined settings. When the power is back, can the program start to run forward where it left off?
Thank you.
2024-05-08 01:09 PM - edited 2024-05-08 01:16 PM
The right question is how much time the MCU needs to save the data, and how much time the power supply will last until the voltage drops below the minimum. Let's start from the former.
If there are no ready examples, improvise, based on the common sense. For one, you know that erasing takes long time, so it is excluded. The flash area for the emergency save must be already erased and ready. Etc,etc.
Then write a test and measure the required time. Then check that the power supply indeed provides this time. If not - add a super-cap or something else.
> When the power is back, can the program start to run forward where it left off?
If power is totally off for prolonged time, all SRAM will be lost. If the voltage only drops below normal, for short time, you can try to enter a low power state and hope that RAM data survives when the normal voltage is back. In any case the MCU will reset. Can you consider a backup battery for this project?
Good luck.
2024-05-08 01:19 PM - edited 2024-05-08 01:25 PM
Hi,
just from ds :
So in 5ms can write 71 x 16b .
Including some "safety margin" i guess : 30 x int16 should be possible without problems.
+
>When the power is back, can the program start to run forward where it left off?
No. You would have to store the cpu registers + the stack + your "to save variables" -> too much.
2024-05-09 11:16 AM
I am trying to do the same thing and am glad I found your fresh post.
How did you get to this information? Did you get it from the dataset, reference manual, etc?
@Thesek1 wrote:I have about 5ms from 2.9V-2V to to save them.
2024-05-09 11:22 AM
Write flash into a collapsing supply is probably the quickest ways to brick a device.
The charge pump is trying get 7.0 - 12.0 VPP for programming.
If at all possible use the NVRAM / BKP memory to stash things you need to retain.
2024-05-09 09:28 PM
Hello. I calculated that. Between my power source and 3.3Vin, i have a diode, so that no current can flow back into the circuit when power off. At 3.3V i have my known capacitance available, i also know my current draw of the board that i am powering. After that, you can use simply equation for capacitor discharge voltage curve, there are many calculators on the internet for that.
2024-05-09 09:30 PM
Hello. Than you for your answer. So the battery backup will be a better solution, because i need my program to start back where it left of when the power is back on. Using battery backup, i can do that more correctly right?
2024-05-09 09:31 PM
Hello, thank you for the answer. So using the battery backup on VBAT pin, i will be able to restore the program where it left of more easily?
2024-05-09 09:31 PM
I also want to restore the program where it left off. Is the battery backup on VBAT better option?
2024-05-09 11:08 PM
Sure - but only 20 bytes:
Why you choose the almost oldest and cheapest cpu for this ??