How to configure internal RTC module in MK60FN1M0VLQ12 controller to give time in milli seconds ?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to configure internal RTC module in MK60FN1M0VLQ12 controller to give time in milli seconds ?

1,877 次查看
rajkumar_yerraj
Contributor II

Hi,

Greetings for the day !

I am working on MK60FN1M0VLQ12 controller, enabled the internal RTC with RTC Oscillator operating at 32.768KHz. I am able to get time in seconds resolution but i need to get time with milli seconds.

May you tell how to configure the internal RTC to give time with milliseconds like (HH:MM:SS:ss)

Thank you.

Rajkumar

标签 (1)
标记 (1)
0 项奖励
回复
3 回复数

1,595 次查看
mjbcswitzerland
Specialist V

Hi Rajkumar

RTC_TPR counts at 32kHz rate so if you read it you can get the time to 30.5us resolution (and x 1000/327628) gives it in ms.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
Kinetis K60:
- http://www.utasker.com/kinetis/TWR-K60N512.html
- http://www.utasker.com/kinetis/TWR-K60D100M.html
- http://www.utasker.com/kinetis/TWR-K60F120M.html
- http://www.utasker.com/kinetis/ELZET80_NET-KBED.html
- http://www.utasker.com/kinetis/ELZET80_NET-K60.html

http://www.utasker.com/docs/uTasker/uTasker_Time.pdf with complete Gregorian calendar, time zone management, daylight-saving and alarms

0 项奖励
回复

1,595 次查看
rajkumar_yerraj
Contributor II

Hi Mark,

I have read from the RTC_TPR register and it is giving some random value in thousands.

May you help how to read it correctly.

I have attached a screenshot of my code and result. Please check it and let me know how to make it work to read milli seconds.

Value loaded into the TPR register is 0x8000U which is equivalent to 32768 as RTC Oscillator operates on 32.768KHz.

Thank you.

Raj Kumar.

0 项奖励
回复

1,595 次查看
mjbcswitzerland
Specialist V

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

0 项奖励
回复