RTC SDK example

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

RTC SDK example

4,684 次查看
anoop_radhakris
Contributor II

Hi, Iam using s32k146 microcontroller. I was testing the RTC example in SDK 0.8.6. In that example there is ISR for secondsISR, alarmISR and switch SW3 configured as interrupt. In secondsISR and alarmISR, green and red LEDs are toggled respectively. For testing, I commented the secondsISR  content. I observed the RED LED(alarm) toggle using oscilloscope. Actually the RED LED(alarm) must toggle for 5sec delay whenever the switch SW3 is pressed.But instead iam getting a delay of 7.20s. Iam pressing the switch immediately after the RED LED pin is toggled.I got the same observation for SDK 3.0.0. Iam sharing the configuration details as screenshot. I would like to know if compensation needs to be enabled. If so what is the appropriate value for it. It would be helpful if I receive a help in this regard.Thanks in advance. 

标记 (3)
8 回复数

4,130 次查看
anoop_radhakris
Contributor II

Hi Daniel,

Thanks for the reply. I would like to know two things

1)Actually I got a sample code for RTC from NXP forum.I tested that code and it was working fine(They are toggling the LED after ever 4sec. I measured using oscilloscope,it is giving exactly 4sec). I would like to know why sample code is able to give correct time and not SDK. I tried to configure SDK example as per sample code but did not get the correct result. Iam sharing the path for sample code below:

How to use RTC module with no SDK? 

2)Another thing I want to understand is,how to configure the compensation register(TCR).What should be appropriate value to be given to compensation register to reduce the error.For example right now for 5sec Iam getting 7.20 sec (tested using oscilloscope),so what value should be provided to compensation register so that we get a time nearer to 5 sec. 

0 项奖励
回复

4,130 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Just regarding the SDK example, it seems that the BTN interrupt is called when the BNT is released not pressed.

Although the PTC13 is configured for a rising edge interrupt in the PIN SDK driver, the interrupt is called on the falling edge.

pastedImage_1.png

pastedImage_2.png

pastedImage_3.png

pastedImage_5.png

I will look further into it.

BR, Daniel

4,130 次查看
anoop_radhakris
Contributor II

Thanks Daniel for reply. It would be helpful if you can comment on the sample code I was referring to and also about how to configure the Compensation register(TCR) in SDK(In terms of appropriate value) or any formula is there.I saw it for kinetics series.

Link to sample code:How to use RTC module with no SDK?

As per your earlier reply for RTC to give correct 1 sec it should be clocked with 32.768KHz. But In this sample code only 32KHz from LPO they are using,but still Iam able to get the correct time(measured using oscilloscope) that too without configuring the compensation register(TCR).

It would be helpful if the you can test this sample code using SDK 0.8.6 workspace and share the configuration details.I tried doing it but I did not get the expected result.

0 项奖励
回复

4,130 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi anoop.radhakrishnan.nair.007@gmail.com,

I have just tested the non-sdk example on an S32K146 EVB.

The code already enables RTC_CLK on PTD13.

I added CLKOUT (LPO) on PTD10 (PCR_MUX = ALT6, SIM_CHIPCTL = 6, SIM_CHIPCTL_CLKOUTEN = 1).

This is what I got:

pastedImage_2.png

129.2 kHz / 4 = 32.300 kHz

(1 / 32.3 kHz) * 32.768 = 1.014s

The LPO clock in this case is well out of the compensation range 32,641; 32,896 (32,768 - TCR, where TCR == 127 to -128).

Therefore, I cannot get exactly 1s with the compensation, although setting it to 32,641 would help.

The SDK 0.8.6 is outdated. 

Please use up-to-date RTM version.

You can enable RTCCLKOUT and CLKOUT (LPO) in the SDK as well.

pastedImage_3.png 

pastedImage_4.png

pastedImage_5.png

I found that there is one issue with the SDK.

Please load the project and halt the execution before the CLOCK DRV INIT function and read the PMC_LPOTRIM register. It should show the factory trimmed value.

pastedImage_6.png

Once the SDK CLOCK driver is initialized, it will change the TRIM value to the one configured in PE.

pastedImage_8.png

The non-SDK example does not do that, it uses the default TRIM value.

So, change the PE value to the factory trimmed value (0x1D in my case).

Hope it helps,

BR, Daniel

 
  

4,130 次查看
anoop_radhakris
Contributor II

Hi Daniel, Thanks for the reply.Few more clarification required with respect to your reply.

1)I assume that you have tested the non sdk using sdk 0.8.6. and by CLKOUT(LPO) you mean LPO_CLK(marked as 1 below) is that correct?

2)

pastedImage_1.png

Can you tell me the detailed clock configuration you have made in the SDK. Also for RTC is it required to check the LPO_CLK(marked as 1)?what I understand is, we need to check only the RTC_CLKOUT(marked as 2).RTC_CLKOUT will give 32.678KHz or prescalar output as per our configuration.Based on RTC_CLKOUT compensation need to be provided. I have marked the configuration which I understand as required for RTC with RED line.So only the Input Clock and Clock Out  need to be enabled in sdk for RTC testing...Please correct me if Iam wrong...

pastedImage_4.png

In sample  code they have configured for 32k RTC_CLK(required) and LPO32K_CLK(this I feel not required).

// Power-on cycle the MCU before writing to this register
 SIM->LPOCLKS |= (1 << 3) | (1 << 4);

3) 

pastedImage_3.png

In SDK, what I understand is, default configuration CLKOUT Select is SCG CLKOUT. You enabled CLKOUT Enable and changed CLKOUT Select to LPO CLK 128Khz only to check LPO_CLK..Is that correct? 

4)Finally I did not get trim value setting you have mentioned. How to select  0x1D in trimming value since drop down available is till only 15. 

It will be helpful if you can share the sdk workspace you tested for clear understanding...Waiting for your reply 

0 项奖励
回复

4,130 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

1.
I tested the alarm example from SDK RTM 3.0.1 and the non-SDK example.
It was routed like this, but it really does not matter.

pastedImage_1.png

2.
The modified SDK example is attached, I only enabled the CLKOUT on PTD10 and RTCCLK_OUT on PTD13.
You don’t need to output LPO clock, but since you are using it and because the RTC module output was wrong, I thought that it would be good if you could measure that.
Yes, RTC_CLKOUT is definitely better then toggling an LED.
But again, you won’t be able to compensate the LPO error.

You need to configure this MUX only:

pastedImage_2.png

3.
Yes,

4.
Please take a look at this table, 0x1D is then -3, the trim value differs part-to-part.
In the attached example, I set it to -3, but your chip can be trimmed to a different value.

pastedImage_3.png

BR, Daniel

4,130 次查看
anoop_radhakris
Contributor II

Hi Daniel, sorry for late reply. I will try with SDK example and come back to you for any assistance if required.

0 项奖励
回复

4,130 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi anoop.radhakrishnan.nair.007@gmail.com,

The RTM module in this SDK example is using the LPO 128kHz clock divided by 4 which should give 32KHz.

pastedImage_2.png

pastedImage_3.png

The RTM clock would need to be 32.768 kHz, to get exactly 1s RTM CLKOUT
(LPO clock would need to be 32.768 kHz * 4 = 131.072kHz).


The oscillator is not precise, as you can see S32DS rev.11.

pastedImage_4.png

It is tre-trimmed to around 128kHz (PMC_LPOTRIM), but one LPOTRIM[4:0] step gives about 3kHz difference.
And therefore, the LPO clock can differ significantly part-to-part.
You can measure the LPO frequency externally at a CLKOUT pin (see above SIM_CHIPCTL[CKOUTSEL]).

Please have a look at the Time Compensation Register description in the RM.
It can compensate 32,768kHz - TCR (where TCR is a twos complement sign extended value).

Using the RTC_CLKIN (external clock) is the only way to get 1s RTM CLKOUT.

BR, Daniel