2023-07-30 10:27 PM
I am using STM32F103ZGT6
I have initialize code From STMCubeMx with settings-> PLL -ON , HSE -ON , LSE- ON for Internal RTC
I have written code to retain date for internal RTC. I want the event when RTC switches from VDD to VBAT , as per my application requirement I want to store Time at which power offs and Time at which power come , Accordingly I want show how many hr or min or sec power was off .
I have checked the Datasheet it is written that Power Down Reset(PDR) occurs when VDD shifts to VBAT I have tried with that flag in the code but didn't work
Can you suggest me some solution for this
2023-07-31 12:06 AM
When the power fails, there will be no power for the application to record data. Wouldn't it be simpler to use some means of temporary energy storage, perhaps a capacitor, or a small battery, so that the processor has time to perform tasks, in conjunction with a monitoring input pin to detect the lack of energy?
For example, when an emergency light is powered from the socket (220V), the light is off, because a detector (transistor Q1) monitors the socket input (indirectly, because the socket voltage was converted to a different value, in this case 6V) and when there is a power failure, the light turns on (the base of the transistor receives a current bias that allows current to flow from the collector to the emitter).
(Image source: https://www.eleccircuit.com/mini-emergency-light-circuit/)
In the case of the microcontroller, it could use an input pin with interruption. When there is a power failure, the pin changes state, the interruption occurs and the microcontroller registers the timedate.
On the other hand, when the power comes back, the microcontroller will turn on for the first time, so it can register the moment it was initialized, and then it goes into an infinite loop of waiting with nothing being done, or it could go into hibernation, so as not to waste energy for nothing.
Note that the example of the emergency light is just didactic, it would be necessary to adapt the voltages to the operating range of the microcontroller (STM32 generally operates with 3.3V).
2023-07-31 08:55 AM
Hello
Just continously write RTC time/date to some backup data registers, for example in 1 second interval. Then, when power is set off, the time of power loss stays on the backup register.
When device boots, check the backup register and calculate the difference to RTC value -> you got the down time. Then start saving RTC value again.
Br J.T
2023-07-31 09:05 AM
I am trying to store time but not able to store it in backup register whenever I read the backup register (any backup register) I am getting current time only not the time at power loss or not the time which I Stored.
2023-07-31 09:06 AM
Thank you for your reply
2023-07-31 09:19 AM
Perhaps show us how you try it, somebody might spot the problem ?
2023-07-31 09:22 AM
Thank you so much .
I don't have system with me right now and her time is 10p.m now I can't go the office right now. I will message you in detail tomorrow morning.(here).
Thank you again for quick reply
2023-08-03 02:36 AM
2023-08-03 12:04 PM
Hello
Re-think your code, especially what you must do and in which order. I think you should divide the upper part in two. First when program starts -> check the down time once. And then in loop update the time to backup data registers. Also, now the RTC_StoreTime doesnt read the RTC time at all, you just declare variable, but not read the current time to sTime.
But you will get it working :thumbs_up:
Br J.T
2023-08-03 01:54 PM
@JTP1 wrote:Hello
Just continously write RTC time/date to some backup data registers, for example in 1 second interval. Then, when power is set off, the time of power loss stays on the backup register.
When device boots, check the backup register and calculate the difference to RTC value -> you got the down time. Then start saving RTC value again.
Br J.T
Just an observation, considering a 24Cxx EEPROM, with 1 million writes, in just approximately 11 days memory failure can occur (It would be necessary to rotate the addresses to avoid expiring the memory cell lifetime).
1 day: 86 400 seconds.
30 days: 2 592 000 seconds.