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
Hi,
Can you please provide me the code to provide an interface between MC9s08sh8 and RTC.
thanks and regards
Vignesh.
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
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
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
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
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.