PSoC3 timer seconds counter

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
WolfgangCS
Level 3
Level 3
25 replies posted 50 sign-ins First solution authored

Hello,
I would like to implement on PSoC Creator with a PSoC 3 a timer that counts the seconds passed since the device was turned on, saving this value in a numeric variable, and that if there was a shutdown this value would not be reset (maybe saving it in EEPROM?). After a restart the counter should continue to count the seconds from the last previous value.
In practice, as if it were the switch-on time of the device expressed in seconds.
Do you have any advice for me please? Is there any feature that already implements this functionality on PSoC 3?
Thank you very much for your availability
Greetings

0 Likes
1 Solution
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @WolfgangCS 

You can use EEPROM to store the value of the counter periodically. In case of reset, when the device starts again you can restart the counter. While saving the value to EEPROM you can add the current value of the counter to the previously stored value in EEPROM and then save the newly calculated value to EEPROM.

We don't have an example showing the exact functionality but the following code example should be helpful:

1. EEPROM Design: This code example demonstrates how to data can be written and read from EEPROM in the case of PSoC 3. The code example can be downloaded from PSoC Creator by clicking on to File > Code example and selecting the following options:

Ekta_0-1629737478128.png

2.  You can use the Timer to keep a track of the timer after the device turns on.

Could you please let me know if you plan to periodically save the value EEPROM in order to keep the track of the seconds passed?

Best Regards
Ekta

View solution in original post

2 Replies
Ekta_N
Moderator
Moderator
Moderator
750 replies posted First like given 250 solutions authored

Hello @WolfgangCS 

You can use EEPROM to store the value of the counter periodically. In case of reset, when the device starts again you can restart the counter. While saving the value to EEPROM you can add the current value of the counter to the previously stored value in EEPROM and then save the newly calculated value to EEPROM.

We don't have an example showing the exact functionality but the following code example should be helpful:

1. EEPROM Design: This code example demonstrates how to data can be written and read from EEPROM in the case of PSoC 3. The code example can be downloaded from PSoC Creator by clicking on to File > Code example and selecting the following options:

Ekta_0-1629737478128.png

2.  You can use the Timer to keep a track of the timer after the device turns on.

Could you please let me know if you plan to periodically save the value EEPROM in order to keep the track of the seconds passed?

Best Regards
Ekta

KyTr_1955226
Level 6
Level 6
250 sign-ins 10 likes given 50 solutions authored

What Ekta posted above is good information and resources on how to write the PSoC EEPROM and how to track your time passed.  I think I see what he's getting at with the followup question:

You will need to consider how often you will be saving the time value, and if there is an acceptable amount of "loss" of seconds in the count between power cycles.  If periodic, you may want to write some code that automatically cycles the EEPROM address to avoid wearing out the rows (I believe at <55C you get around 100k guaranteed erases/writes before problems can occur).  Spreading out writes between different locations can extend out the useful life of the EEPROM significantly.  This is called "Wear Leveling " (check that link, it's a Cypress AppNote on the topic that could be quite helpful).

Another way to go about this would be to only save the value on power loss, but in order to do that, you would need to have some sort of hold-up circuit for VDD and would also want some kind of signal to let you know immediately when your main power drops out.  For example, on a recent design I did the firmware for,  the FAULT pin of the 12V regulator is going to a PSoC GPIO (with an associated interrupt) to immediately alert my application that there is an imminent power loss (or general issue with V_IN).  When a loss of main power occurs, the hold-up circuitry will keep the PSoC above minimum VDD for about 200ms, which is more than enough time to save any critical information before shutdown occurs.

This would let you only erase/write to EEPROM on a loss of power, and would almost for sure be less often than if you were to do saves periodically.