STM32: optimized clock speed adjustment

This commit is contained in:
Pavel Kirienko
2014-04-12 20:29:57 +04:00
parent 77b1cb1320
commit 67f92628a8
@@ -158,16 +158,24 @@ void adjustUtc(uavcan::UtcDuration adjustment)
*/
if (adjustment.isPositive())
{
if (utc_correction_usec_per_overflow_x16 < MaxUtcSpeedCorrectionX16)
if (utc_correction_usec_per_overflow_x16 < 0)
{
utc_correction_usec_per_overflow_x16++;
utc_correction_usec_per_overflow_x16 += 4;
}
else if (utc_correction_usec_per_overflow_x16 < MaxUtcSpeedCorrectionX16)
{
utc_correction_usec_per_overflow_x16 += 1;
}
}
else
{
if (utc_correction_usec_per_overflow_x16 > -MaxUtcSpeedCorrectionX16)
if (utc_correction_usec_per_overflow_x16 > 0)
{
utc_correction_usec_per_overflow_x16--;
utc_correction_usec_per_overflow_x16 -= 4;
}
else if (utc_correction_usec_per_overflow_x16 > -MaxUtcSpeedCorrectionX16)
{
utc_correction_usec_per_overflow_x16 -= 1;
}
}