#13 Accuracy of PI-controller in servo.c


Accuracy of PI controller that calculates actual clock frequency adjustment needed to synchronize clocks can be improved with trivial change to achieve <20ns synch with hardware support.

Currently the resolution of PI controller is limited by the way the error value is integrated using following method

ptpClock->observed_drift += ptpClock->offsetFromMaster.nanoseconds / ptpClock->observed_drift*rtOpts->ai;
adj = ptpClock->offsetFromMaster.nanoseconds/rtOpts->ap + ptpClock->observed_drift;

If offsetFromMaster < rtOpts->ai nanoseconds, the error is not accumulated into observed_drift and cannot be used to tune the PI-controller.

If the code is changed to
ptpClock->observed_drift += ptpClock->offsetFromMaster.nanoseconds;
adj = ptpClock->offsetFromMaster.nanoseconds/rtOpts->ap + ptpClock->observed_drift/rtOpts->ai;

Accuracy is greatly improved. I've managed to get accuracies down to 5-10 ns with 5 syncs/second with pretty inexpensive microcontroller that has PTP hardware support.


  • Jan Breuer

    Jan Breuer - 2013-09-17
    • status: open --> pending
    • Group: --> v1.0_(example)
  • Jan Breuer

    Jan Breuer - 2013-09-17

    Resolved by servo using double precision numbers

  • Wojciech Owczarek

    • status: pending --> closed
    • assigned_to: Wojciech Owczarek
    • Group: v1.0_(example) --> v2.3.0

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks