HOWTO get access to RTC prescaller RTC_TPR with PE's RTC_LDD?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HOWTO get access to RTC prescaller RTC_TPR with PE's RTC_LDD?

1,302 Views
ky3orr
Contributor II

Hi All,

 

I am writing a small application which will take an advantage of deep power down modes of my KL05.

I intend to use RTC to wake from low power mode on periodic basis.

 

As I plan to use LPO for driving RTC I need to set RTC_TPR to let say 32768-1000 to have one second interrupt generated correctly.

 

The thing is I don't see any method for setting/getting RTC prescaller value.

 

I am using KDS 2.0.0.

 

Thanks for any hints.

Labels (1)
Tags (4)
5 Replies

816 Views
adriancano
NXP Employee
NXP Employee

Hi,

The RTC_LDD component has a method called SetCompensationPeriodAndValue; this method sets the compensation period and value, it writes to the RTC_TCR register to set when the time prescaler register overflow. This method is only available in the Advanced view of the Component inspector.

Please refer to the attached document that is the RTC_LDD component user guide. This document can be also found in the KDS 2.0.0 installation folder following the path KDS_2.0.0\eclipse\ProcessorExpert\Help\ComponentUserGuides.


Hope this information can help you.

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

816 Views
ky3orr
Contributor II

Hello Adrian,

thank you for your support.

As I would like to take an advantage of having constant setup of the prescaler to 32768-1000 with possibility to fine-tune this later how shall I use Period and Value settings to achieve that?

From rtc library documentation I read that:

Cycles are added or subtracted from the prescaler register when the prescaler register equals 0x3FFF and then

increments.

Does it mean that on every overflow of the prescaler its starting value is being modified?

Does this updated starting value is remembered and is a base for later cycles additions/subtractions?

What would be the procedure for subtracting 1000 cycles from the prescaller before starting RTC (Value range is only signed char [-127,+128])?

Or should it be rather done in assembly because it is not possible to make use of RTC_TPR's full range in PE code?

How about Period setting: setting it to 1 second provides updates to the prescaler every second by cumulating Value offset or it is just doing every time Value change to the prescaler from the same base: 32768 cycles to overflow?

If Period is set to 0 issued offset is cancelled or remains until RTC is running?

What happens if Period =1 and Value = 0 and second ago Value was != 0. Prescaler modification remain or is being cancelled?

Sorry for all that questions, but those just are not to be answered after I've read RTC_LDD documentation.

best regards

0 Kudos

816 Views
adriancano
NXP Employee
NXP Employee

Hi,

I will try to solve your queries and explain how the mentioned method works, I hope that the explanations is good enough.

The SetCompensationPeriodAndValue method writes directly to the RTC_TCR register, here is the register view on the Reference Manual.

rtc tcr.jpg

Here you can see there are two fields named CIR and TCR, they have the default/reset value to zero.

cir field.jpg

The CIR field, corresponds to the Period parameter of the SetCompensationPeriodAndValue method, in the picture above you can see the explanation.

In other words the CIR field will control how often the compensation value will be set, this means that if you want to compensate the RTC value every 4 seconds you need to write Period = 4. In the words of the reference manual: “The compensation interval is used to adjust the frequency at which the time compensation value is used, that is, from once a second to once every 256 seconds.”

tcr field.jpg

The TCR field, corresponds to the Value parameter of the SetCompensationPeriodAndValue method, in the picture above you can see the explanation.

In other words, this value will control how many clock cycles form the 32.768 KHz clock will be needed to overflow the Prescaler Register. Normally the value is 32768 clock cycles, this means that the Preescaler Register will overflow every 32768 clock cycles. With the Value parameter value you can control the number of clock cycles adding or subtracting clock cycles for a fine compensation. In the words of the Reference manual: “The time compensation value is used to adjust the number of clock cycles between -127 and +128. Cycles are added or subtracted from the prescaler register when the prescaler register equals 0x3FFF and then increments.”

The section Time counter in the reference manual explains how the 32-bit seconds counter and the 16-bit prescaler register are related. The Seconds counter, as the name refers, increments every 1 second; but this increment happens every time that a falling edge of the 14 bit of the prescaler register occurs or Prescaler register = 0x3FFF that is the same.

You can select how often you do the compensation (CIR field) and how many clock cycles (TCR field) will take to the Prescaler register to reach 0x3FFF incrementing every time by one.

Having said this, I will try to answer your questions:

Q: Does it mean that on every overflow of the prescaler its starting value is being modified?

A: Yes, every time the Prescaler register reaches 0x3FFF the values written in the RTC_TCR[TCR] field will be updated, if a changed was done, and will be loaded to the compensation value. This means that the next time the new RTC_TCR[TCR] will be the valid one.

Q: Does this updated starting value is remembered and is a base for later cycles additions/subtractions?

A: As mentioned before if you do not change the RTC_TCR[TCR] values this will NOT be changed or reset.

Q: What would be the procedure for subtracting 1000 cycles from the prescaller before starting RTC (Value range is only signed char [-127,+128])? Or should it be rather done in assembly because it is not possible to make use of RTC_TPR's full range in PE code?

A: The range is from -127 to +128 because it is just a fine compensation value. Also it is because the RTC_TCR[TCR] filed is a 8 bit field and has a range of 255 valid numbers.

Q: How about Period setting: setting it to 1 second provides updates to the prescaler every second by cumulating Value offset or it is just doing every time Value change to the prescaler from the same base: 32768 cycles to overflow?

A: The explanation is above. The values of the CIR filed is related to the RTC_TSR register that increments every second. Then if you set Period to 1 second every time the RTC_TSR register increments the Compensation process will take effect.

Q: If Period is set to 0 issued offset is cancelled or remains until RTC is running?

A: The default value is 0 and this means, as the RM mentions, write zero to configure for a compensation interval of one second.

Q: What happens if Period =1 and Value = 0 and second ago Value was != 0. Prescaler modification remain or is being cancelled?

A: If Period is 1 RTC_TCR [CIR] = 1 and RTC_TCR[TCR] = 0. If a second ago  RTC_TCR[TCR] != 0 then the next time the Prescaler register reaches 0x3FFF the new value RTC_TCR[TCR] = 0 will be loaded and the time compensation value will be 00 = Time Prescaler Register overflows every 32768 clock cycles.


Hope this information can help you.

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

816 Views
ky3orr
Contributor II

Hello Adrian,

your description helped me with understanding what is really going on with compensation registers.

How about prescaler RTC_TPR register?

Can I make direct use of it, or this is the one being setup on every RTC_TCR[CIR] seconds by amount of RTC_TCR[TCR] cycles?

Or other way around: is there a way so RTC will increase its seconds correctly when supplied with LPO oscillator?

Thanks in advance for information on that.

Grzegorz

0 Kudos

816 Views
adriancano
NXP Employee
NXP Employee

Hi,

I apologize for the later response, answering to your questions:

1. Yes, the RTC_TPR register is being setup with the CIR and TCR fields according to the explanation given before. Processor Expert does not allow the manipulation of this register directly.

2. The LPO as the clock source of the RTC is not fore real time accuracy is just an option to wake up the device in Very Low power modes. Please refer to this thread, it has the information you need KL24 LPO 1 kHz as a clock source for RTC


Hope this information can help you

Best Regards,
Adrian Sanchez Cano
Technical Support Engineer
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos