RTC_GetTime API Issue

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello colleagues, 

I am facing a fail in my GetTime measurement with your RTC module. I read the time at the beginning of my project and store it as StartTime variable. I use the ADC interrupt and I perform the measurement Seconds=RTC_GetTime()-StartTimeTime each 200ms. The measurement is performed perfectly from 0-16 seconds, then jumps to 23 and measures correctly till 32, then jumps again to 39 and so on. When variable Seconds is at 64, it jumps to 231... I don't know whether it is a clock issue or simply I need a kind of hexadecimal conversion. I attached both my UART log and the archived project so you can easily reproduce it. It is reproducible with the PRoC Eval Kit (project attached). 

Looking forward to your feedback, 

   

Peter

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The returned value is in BCD format, so you'll have to convert it when you want to make calculations with it.

   

 

   

Bob

View solution in original post

0 Likes
14 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The returned value is in BCD format, so you'll have to convert it when you want to make calculations with it.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hello Bob,

   

Thanks for the quick response. Is a predefined function to convert BCD to integer available? Or do I need to do it by myself?

   

Rgds

   

Peter

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Look into the RTC datasheet, there are conversion functions listed: RTC_P4_ConvertBCDToDec ().

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks but now with that function is jumping from 40 to 81, from 140 to 181 and so on... 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Consider looking at the values before and after conversion in hex. will make things clearer!

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Before conversion is jumping from 64 (0x40) to 231 (0xE7) and after conversion is jumping from 40 (0x28) to 81 (0x51). So nothing is clearer 😞 I am using %lu and %ld (my printed variable is uint32) in the sprintf function to check if this is just a display issue but I got the same results. I also tried to define my printed variable as Int instead of uint32 and I got the same result as well.

   

        sprintf(MyBuffer, "Seconds: %lu\r\n", Seconds);
        UART_PutString(MyBuffer); 

   

I have also used a open Software code in the Internet and I got the same issue, from 40 to 81 is always jumping the value.

   

Is there a kind of BCD to pure integer (uint32) conversion function? If you know how to solve the issue, I would really avoid to reinvent the wheel here 😄   

   

Rgds,

   

Peter

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a program that works and reads the clock Component.  It has more information than you need but it should give you some information on how the RTC works,

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

The RTC component has a BCD to Dec conversion routine.

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is the RTC program made for your chip.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

RTC uses 32 bit wide values for time, not 8 bit wide ones.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanks for sharing the code Bobgoar. It looks like the functions RTC_GetSecond, RTC_GetMinutes and so on are working as expected and convert BCD to Decimal in a correct way and not as RTC_P4_ConvertBCDToDec function which doesn't really convert BCD to Decimal.  

   

With the below code I am obtaining the total seconds as I wanted. I would prefer to use just one function for that instead of 4 but it seems to require additional coding and calculations.

   

        Seconds =   86400*RTC_GetDay(RTC_GetTime())+
                    3600*RTC_GetHours(RTC_GetTime())+
                    60*RTC_GetMinutes(RTC_GetTime())+
                    RTC_GetSecond(RTC_GetTime())-StartSeconds;

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

When working with seconds only, did you already see the API RTC_GetUnixTime() and its description?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Hello Bob,

   

sorry for the late reply. The API RTC_GetUnixTime() was exactly what I was looking for. Thanks for the support,

   

Peter

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are always welcome, Peter.

   

 

   

Bob

   

PS: Where in Germany are you located? I live near Bremen.

0 Likes