RTC frequency compensation in K60 micro controller

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

RTC frequency compensation in K60 micro controller

2,344 Views
akhil
Contributor III

Hi all,

We have noticed  some shifts (lags/ advances) in RTC time in K60 micro controller.

The crystal that we used have a frequency tolerance of 20ppm. The time shift is different in different boards(same configurations).

The  data sheet of K60 contains the details of RTC frequency compensation.

Then, how to implement the different frequency compensation for different boards. Is there any sample source code to implement the same?

Please share your comments on this.

Thanks

Akhil

Labels (1)
Tags (3)
0 Kudos
Reply
6 Replies

1,579 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

As my colleague had mentioned, the AN4949 provides the RTC compensation theory.

Below is the RTC compensation test code for your reference:

/**************************************************************************/

//srtc compensation function test

void srtc_comp()

{

  volatile uint32 TSR_VAL, TPR_VAL;

  int i=2;

  int current;

 

  printf("Start checking srtc time compensation function...\r\n");

 

  printf("Enable osc\n");

  RTC_CR |= RTC_CR_OSCE_MASK;

  printf("Compensation Interval of 1 seconds with Compensation value of 32641 cycles\r\n");

  current = 1;

  //RTC_TCR = 0x00000080;  //should be short ~3.5 seconds in 1020 counts

  //RTC_TCR = 0x000000BF;    //should be short ~1.7 seconds in 1000 counts

  RTC_TCR = 0x00000000;    //should be dead on after 1000 counts

  //RTC_TCR = 0x0000003f;   // should be fast ~1.7 seconds after 1020 counts

  //RTC_TCR = 0x0000007f;    //should be fast ~3.5s after 1000 counts

  RTC_TSR = 0x00000001;

  RTC_SR |= RTC_SR_TCE_MASK;

 

  //Check for 15 seconds that the TPR register never increments to 32642

  while(1)

  {

      //TPR_VAL = RTC_TPR;

      //TSR_VAL = RTC_TSR;

     

      if(/*(RTC_TPR >= 32767) &&*/ (current != RTC_TSR))

      {

          printf("%i\n", i);

          i+=1;

          current = RTC_TSR;

      }

  }

   

}

Wish it helps.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,579 Views
akhil
Contributor III

Hi Hui,

Thank you for the response.

I have understood the details of frequency compensation. But I would like to know, how the actual frequency error(in ppm) is calculated for a particular crystal dynamically in the firmware.  The issue we are facing is that the actual frequency of each crystal(same make) is different.

Regards

Akhil

0 Kudos
Reply

1,579 Views
Paul_Tian
NXP Employee
NXP Employee

Hi, Akhil

The RTC compensation function is only used to adjust RTC counter based on known offset. But it is not the calibration function.

Best Regards

Paul

0 Kudos
Reply

1,579 Views
Vagni
Contributor IV

I read the AN4949 application note, but I still don't understand how to set RTC_TCR register for compensation in a K6x cpu.

The CIR field set the compensation interval in seconds (from 1 to 256 s): every compensation interval the prescaler value is adjusted for one cycle with the value of the TCR field (+128 / -127) from the 32768 nominal value, right?

Now, I can measure the RTC_CLKOUT signal frequency, which differs quite always from the 32768 Hz nominal value; but how to calculate the right values for CIR and TCR fields?

If I measure RTC_CLKOUT = 32767.0000 Hz, should I set CIR = 0 and TCR = 1 ?

But what if I measure RTC_CLKOUT with a fractional part, i.e. 32767.1234 or 32768.8765 Hz ?

Regards

0 Kudos
Reply

1,579 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi,

The RTC counter clock is coming from external 32KHz crystal. The external 32KHz crystal will decide the RTC accuracy.

The 32KHz crystal frequency shift need with coherence in the same temperature range.

Otherwise it is hard to set the temp compensation in RTC module.

Wish it helps.


Have a great day,
Ma Hui

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,579 Views
Paul_Tian
NXP Employee
NXP Employee

Hi, Akhil

There is an application note for your reference. http://cache.freescale.com/files/microcontrollers/doc/app_note/AN4949.pdf

Best Regards

Paul

0 Kudos
Reply