Using RTC in MC9S08SH8 microcontroller to make a Clock Hour

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Using RTC in MC9S08SH8 microcontroller to make a Clock Hour

2,180件の閲覧回数
BairesRobotics
Contributor I

Hi all,   I'm using a Mc908SH8, and I have a issue with the RTC module that  count days, and I have an ERROR of 1 hour  y 1 day. I need please an example to correct this error.

 

I have use this register initialization.

   RTCSC    = 0x1F;

   RTCMOD   = 0x00;

 

The interrupt routine:

 

interrupt void isrRTClk(void){         // RTC interrupt one per second

   RTCSC |= 0x80;

   Seconds++;

   if(Seconds > 59){

      Minutes++; Seconds = 0; 

      if(Minutes > 59){

         Hours++; Minutes = 0;

         if(Hours > 23) Hours = 0;

      } 

   }

}

 

Thanks, and regards

Jorge  

ラベル(1)
0 件の賞賛
返信
6 返答(返信)

1,492件の閲覧回数
admin
Specialist II

Hi,

Can you please provide me the code to provide an interface between MC9s08sh8 and RTC.

thanks and regards

Vignesh.

0 件の賞賛
返信

1,492件の閲覧回数
bigmac
Specialist III

Hello Vignesh,

I have not tested it, but the RTC interrupt code initially given by Jorge in this post should work correctly, given a suitable accuracy for the clock source.

Regards,

Mac

0 件の賞賛
返信

1,492件の閲覧回数
celsoken
Contributor V

Dear Jorge,

 

Building a clock is easy if you work on a good time reference.

Be aware that due to cumulative errors, more than some PPMs are not acceptable.

A cheap reference is 32,768Hz xtals and these xtals are targeted to this application so PPM errors are fair enough.

SH8 architecture allows you to use directly these xtals.

 

I hope it helps,

 

Celso

 

0 件の賞賛
返信

1,492件の閲覧回数
bigmac
Specialist III

Hello Jorge,

 

To achieve a timekeeping accuracy of say, one second per day, the reference frequency error will need to be within 10 parts per million (ppm).  Using a watch crystal as an external reference would achieve this accuracy only if it is trimmed with a trimmer capacitor.  However, the method of adjusting the trim setting is likely to be by "trial and error" - not very convenient or quick.

 

With direct frequency measurement of the reference, the capacitive loading of the measurement probe will cause errors, and you would need a frequency counter with 0.1Hz resolution.  Setting the output of a TPM channel for a specific period, and using a counter with period measurement capability, and with the period averaged over a number of cycles, may give more successful results.

 

Another approach is not to trim the crystal at all, but to automatically apply a time correction whenever the accumulated error reaches, say one second.  The actual error, which might be 100 ppm or more, could be initially determined by measurement of TPM output period, as mentioned above, and would need to be stored as a non-volatile parameter.

 

Regards,

Mac

0 件の賞賛
返信

1,492件の閲覧回数
celsoken
Contributor V

I think Mac is right in general terms. As most the designs I'm involved with are targeted to automotive apps, I'd strongly suggest you use a fixed-type oscillator w/ NP0 caps. Trimmers sometimes have significant TCs, poor vibration specs  and sometimes drift w/ conformal coating.

 

As Mac said you'll need calibration. One usual method is to use a pulse generated by the uC (HW defined e.g. generated thru Output compares) read by an external ATE. The ATE can e.g. gate an OCXO with the uC signal so the resolution depends on your pulse width. So you can use this value to NV trim your clock.

 

I hope it helps,

 

Celso

0 件の賞賛
返信

1,492件の閲覧回数
tonyp
Senior Contributor II

The internal 1 KHz oscillator has a possible error (based on the QE128 datasheet, yours may differ) of about +/- 30%.

 

1 hour in a day is roughly 4%, so it's good enough.

 

To correct this error, use a different clock source.  The 1 KHz is only meant to give rough timing (eg., for delays, etc.), not for accurate clock keeping.

 

0 件の賞賛
返信