Fix drift calculation in PI servo with large values.
When the drift value is adjusted by the newly measured frequency offset, multiply the frequencies instead of adding the measured offset to the old value to get accurate result even when updating a large drift. [ RC: use a simpler form of the frequency update calculation. ] Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com> Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
e63a6ea89b
commit
2ca067dcac
3
pi.c
3
pi.c
|
@ -107,7 +107,8 @@ static double pi_sample(struct servo *servo,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
s->drift += (s->offset[1] - s->offset[0]) * 1e9 /
|
/* Adjust drift by the measured frequency offset. */
|
||||||
|
s->drift += (1e9 - s->drift) * (s->offset[1] - s->offset[0]) /
|
||||||
(s->local[1] - s->local[0]);
|
(s->local[1] - s->local[0]);
|
||||||
if (s->drift < -s->maxppb)
|
if (s->drift < -s->maxppb)
|
||||||
s->drift = -s->maxppb;
|
s->drift = -s->maxppb;
|
||||||
|
|
Loading…
Reference in New Issue