Raj
In the uTasker project I can read the date and time with 1ms resolution (here is example output):
show_time
19.12.2018 22:46:41.981
show_time
19.12.2018 22:46:42.139
show_time
19.12.2018 22:46:42.446
show_time
19.12.2018 22:46:42.746
show_time
19.12.2018 22:46:42.991
show_time
19.12.2018 22:46:43.229
show_time
19.12.2018 22:46:43.812
The (partly pseudo) code to do the time reading is like this:
FOREVER_LOOP() {
usTimeStamp = (unsigned short)((RTC_TPR * 1000)/32768);
// Now read the RTC time
usMSValue = (unsigned short)((RTC_TPR * 1000)/32768);
if (usMSValue >= usTimeStamp) {
break;
} // else repeat due to pre-scaler overflow taking place
}
return usMSValue;
Notice that there is a race state that needs to be avoided, when the pre-scaler overflows between reading it and the second count otherwise there will be a 1s error. The loop ensures that this is caught and the read repeated..
Regards
Mark
http://www.utasker.com/docs/uTasker/uTasker_Time.pdf