DolphinV4 API  1.6.1.0
Calibration of the timers

The ULP timer oscillators error can be reduced using the calibration values stored in the chip MOD area. The calibration values act as a correction to the timer deviation from the ideal timing:

WatchdogTimer calibration:
The example below shows how to use the 16 bit integer calibration value stored in the mod area by the factory. The timer correction factor is gModArea.val.u16CalibWatchdog/WATCHDOG_CALIB_CONST. The constant WATCHDOG_CALIB_CONST is used to speed up the end value calculation. The division with WATCHDOG_CALIB_CONST is interpreted by the compiler as shifting, because 2048 = 2^11. Valuable time is saved in comparison to a float division.

//calculating and setting up a calibrated watchdog timer period of 10 seconds
u32WatchdogPeriode = 10 * 100; // 10s * 100 watchdog clock ticks/s
u32WatchdogPeriode = (uint32)(u32WatchdogPeriode*gModArea.val.u16CalibWatchdog)/WATCHDOG_CALIB_CONST;
result = pwr_setSleepTimer(WATCHDOG_TIMER, u32WatchdogPeriode, 0);

FlywheelTimer calibration:
The example below shows how to use the 32 bit float calibration value:

//calculate timer periode for 10 seconds
u32FlywheelPeriod = (uint32)(CONV_TIME_TO_COUNTER(10, SEC, FLYWHEEL_CLK)* gModArea.val.f32CalibFlywheel);
result = pwr_setSleepTimer(FLYWHEEL_TIMER, u32FlywheelPeriod, 0);

ShortTermTimer calibration:
The example below shows how to use the 16 bit integer calibration value: Instead of a division with 32bit float a 16 bit value together with a constant SHORT_TERM_CALIB_CONST is used to speed up the end value calculation. The division with SHORT_TERM_CALIB_CONST is interpreted by the compiler as shifting, because 2^11 = 2048, so valuable time is saved in comparison to a float division.

//enter Short Term sleep between subtelegrams



Note:
When a timer is calibrated the maximum period can't be always reached. This should be especially considered when using the CONV_TIME_TO_COUNTER macro: with the calibration factor the timer register width can overflow. Be aware if using very small values there is a certain rounding error.
You can find an example of a timer calibration in Autarkic Sensor Example example