- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The returned value is in BCD format, so you'll have to convert it when you want to make calculations with it.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The returned value is in BCD format, so you'll have to convert it when you want to make calculations with it.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Look into the RTC datasheet, there are conversion functions listed: RTC_P4_ConvertBCDToDec ().
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks but now with that function is jumping from 40 to 81, from 140 to 181 and so on...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Consider looking at the values before and after conversion in hex. will make things clearer!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The RTC component has a BCD to Dec conversion routine.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
RTC uses 32 bit wide values for time, not 8 bit wide ones.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When working with seconds only, did you already see the API RTC_GetUnixTime() and its description?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Bob,
sorry for the late reply. The API RTC_GetUnixTime() was exactly what I was looking for. Thanks for the support,
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome, Peter.
Bob
PS: Where in Germany are you located? I live near Bremen.