RTCC.setCalibration

Name

 * RTCC.setCalibration

Description
Adjusts the timekeeping of the Real Time Clock and Calendar (RTCC) by writing a value into the calibration fields (CAL<9:0>) of the RTC Control Register (RTCCON). This value is then added (or subtracted from) the RTCC timer once per minute. Calibration has the ability to eliminate an error of up to 260 ppm and provide a clock that is accurate to within 1 second per month.

Only works for 32-bit Pinguinos with a 32,768 kHz quartz crystal which allows the use of the built-in RTCC functionality of the PIC32, such as the Olimex PIC32 Pinguino OTG.

Syntax
void RTCC.setCalibration(int cal)
 * Parameters:
 * cal = the number of clock pulses to be added to or subtracted from RTCC once per minute (range -512 to +511).
 * Returns/Output;
 * [None]

The value of cal can be calculated from either the difference on the actual 32,768 kHz crystal frequency from 32,768 kHz or from the number of seconds the Real Time Clock is gaining or loosing over a given period.


 * cal = (Ideal Frequency (32,768) - Measured Frequency) x 60


 * cal = 22.76 x (Number of seconds lost per 24 hours)

If the RTC is gaining time or the measured frequency is greater than the ideal frequency of 32,768 then both the above equations should give a cal figure that is negative. If the RTC is lossing time or the measured frequency is less than the ideal frequency of 32,768 then both the above equations should give a cal figure that is positive.