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.
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:
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.
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.
I will look further into it.
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.
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:
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.
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.
Once the SDK CLOCK driver is initialized, it will change the TRIM value to the one configured in PE.
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,
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?
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...
In sample code they have configured for 32k RTC_CLK(required) and LPO32K_CLK(this I feel not required).
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
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.
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:
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.
The RTM module in this SDK example is using the LPO 128kHz clock divided by 4 which should give 32KHz.
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.
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.