PSOC5 LP time_t displays Today is Wed Dec 31 23:59:59 1969 while same code works on PC

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

cross mob
Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

Hello,

 

I am facing a strange issue, where a simple C code to display the current date and time using the time_t type, to get and print the current date and time.

The issue is that the same code works properly on the PC whereas it doesn't when I program it to the PSOC5 LP and check the UART prints.

I have attached the screenshots which show the output of the code on the PC as below:

Y_r_0-1662553624683.png

And the below image corresponds to the UART log after the PSOC is programmed:

Y_r_1-1662553758836.png

I am also attaching the firmware programmed to the PSOC, if someone can use and help me figure what's going on here.

Thanks and Regards,
Yash

0 Likes
1 Solution
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Y_r,

pacr is correct.  Your PC uses the internet to ask a time server what the time is from the atomic clock.  Once it has the correct time, it uses it's crystal-based clocking to keep this time and date very accurate.  Your PC might ask the time server every hour or day to make sure the system time is correct to less than 1 sec/day.

Your PSoC which as RTC capabilities depend on a watch crystal to keep the time incrementing to be very accurate.  This is a relative accuracy.   Knowing the UTC or your local time information is basically called absolute accuracy.

The PSoCs RTC has no knowledge or means of connection to the world or local time servers to know the absolute accuracy of the time/date of your local or UTC.

Therefore you have to find a means to load the time/date into the PSoC.   I have used a UART-based comm program to do this.

Others use Wi-fi (to communicate to the world time servers) or BLE to obtain the latest time/date.

Another means to to provide a display and buttons (or keyboard) to increment/decrement time or date info.

Once the latest time/date is loaded, the RTC should keep very accurate time (< 1 sec error per day) AS LONG AS POWER IS APPLIED.

The PSoC has the ability to wire up a backup battery or capacitor.  This can preserve the RTC between power losses. 

If you get a reset (power up, watchdog,  low-voltage or other) your code needs to load the last known RTC value it might be correct.  This should be the default RTC-loaded value in your code.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
4 Replies
pacr_284376
Level 5
Level 5
100 replies posted 10 solutions authored 50 sign-ins

Your PC knows the current date and time.

Your PSOC5lp does not know the current date and time.

You will need additional hardware for that (lookup RTC=RealTimeClock) or you must enter date and time everytime you restart the processor.

The first PC I had (years ago) also didnt keep track of time, it asked everytime I started date and time.

Welcome to the world of embedded software

Patrick

0 Likes
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

Y_r,

pacr is correct.  Your PC uses the internet to ask a time server what the time is from the atomic clock.  Once it has the correct time, it uses it's crystal-based clocking to keep this time and date very accurate.  Your PC might ask the time server every hour or day to make sure the system time is correct to less than 1 sec/day.

Your PSoC which as RTC capabilities depend on a watch crystal to keep the time incrementing to be very accurate.  This is a relative accuracy.   Knowing the UTC or your local time information is basically called absolute accuracy.

The PSoCs RTC has no knowledge or means of connection to the world or local time servers to know the absolute accuracy of the time/date of your local or UTC.

Therefore you have to find a means to load the time/date into the PSoC.   I have used a UART-based comm program to do this.

Others use Wi-fi (to communicate to the world time servers) or BLE to obtain the latest time/date.

Another means to to provide a display and buttons (or keyboard) to increment/decrement time or date info.

Once the latest time/date is loaded, the RTC should keep very accurate time (< 1 sec error per day) AS LONG AS POWER IS APPLIED.

The PSoC has the ability to wire up a backup battery or capacitor.  This can preserve the RTC between power losses. 

If you get a reset (power up, watchdog,  low-voltage or other) your code needs to load the last known RTC value it might be correct.  This should be the default RTC-loaded value in your code.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi @Len_CONSULTRON and @pacr_284376 ,

Thanks for sharing your inputs about the topic. I understand the issue now.

As you have suggested, i do use an RTC in my setup, but my issue is to understand the easiest and efficient way to configure the RTC with the current time automatically as soon as the PSOC is programmed. 
To achieve this, would you have any recommandations?

 

Also. @Len_CONSULTRON , can you elaborate on the below line:
"I have used a UART-based comm program to do this."

=>> How did the UART program help configure the time in your use case? Did the user need to enter the current time over a UART terminal (which is then read and used)?

I also wanted to know if I can use the "__DATE__, __TIME__" processor directives which can give out the date and time the current firmware image was built at, to be able to configure the RTC?

Thanks and Regards,
Yash

0 Likes

Y_r

...

As you have suggested, i do use an RTC in my setup, but my issue is to understand the easiest and efficient way to configure the RTC with the current time automatically as soon as the PSOC is programmed. 
To achieve this, would you have any recommandations?


Think of an alarm clock or the clocks on most microwaves or stove appliances.

They have a display and buttons to increment or decrement the time and/or date.

These controls are used to make these changes after power up.


Also. @Len_CONSULTRON , can you elaborate on the below line:
"I have used a UART-based comm program to do this."

=>> How did the UART program help configure the time in your use case? Did the user need to enter the current time over a UART terminal (which is then read and used)?


I've created a UART interface where at power up, the UART is waiting for a time and date input using a terminal program.


I also wanted to know if I can use the "__DATE__, __TIME__" processor directives which can give out the date and time the current firmware image was built at, to be able to configure the RTC?

 


Yes.  The __DATE__ and __TIME__ can be used to limit the earliest time that the RTC can be set.

Len
"Engineering is an Art. The Art of Compromise."