Ethercat random jitter fix

  • grandixximo
  • grandixximo's Avatar Topic Author
  • Away
  • Senior Member
  • Senior Member
More
25 Dec 2025 07:37 - 25 Dec 2025 12:44 #340487 by grandixximo
Ethercat random jitter fix was created by grandixximo
If you have been using linuxcnc ethercat, you almost certainly have experienced jitter, the motor makes a weird noise, restarting lxcnc once or twice, and it works well, no amount of latency improvements ever fix this completly, just happens a bit less often.
Since I had sometime to kill this Christmas I put a lot of effort into pin pointing the cause of this issue, and fix it for good, I will share the code in the next few days, still doing some testing and refinements, but I wanted to share what I am at this time practically certain the cause was/is.
The issue is the servo thread syncs with the DC clock, but it is not in phase, each time linuxcnc starts the app-phase is randomly out of phase with the DC epoch time (Fixes value of "DC reference time" displayed by ethercat master), the fix was to remove app-phase from DC epoch, and drift the servo-thread to align with this time, that's all, this will make sure your packets are sent (with jitter) in phase with the DC epoch, and your sync0shift will actually allow for your jitter/latency.
I will do some more testing refine the code, and soon share the fix with the linuxcnc community,
Merry Christmas and Happy Holidays to all!
Last edit: 25 Dec 2025 12:44 by grandixximo.
The following user(s) said Thank You: maxi177, NWE

Please Log in or Create an account to join the conversation.

  • Hakan
  • Away
  • Platinum Member
  • Platinum Member
More
25 Dec 2025 08:48 #340488 by Hakan
Replied by Hakan on topic Found the main source of the jitter
Indeed, it is the servoloop that isn't in sync with the dc clock.

github.com/linuxcnc-ethercat/linuxcnc-et...s.md#master-settings

Please Log in or Create an account to join the conversation.

  • grandixximo
  • grandixximo's Avatar Topic Author
  • Away
  • Senior Member
  • Senior Member
More
25 Dec 2025 09:46 - 25 Dec 2025 10:08 #340491 by grandixximo
Replied by grandixximo on topic Found the main source of the jitter
I have used your syncToRefClock "true" option, the random jitter issue persisted. The issue is not just sync, it is also phase, by simply drifting to match the DC epoch, you can get in phase. Only after the fix I am NOW finally able to create the jitter at WILL by setting a sync0shift of 10~30us this is expected, as preempt_rt has 20-60us jitter, if you move the sync0shift window in the jitter you should get jitter, this was not the case with just syncToRefClock "true" the servo was in sync, but the phasing was random. I will further test tomorrow, but this is something that has escaped the community for a while.
Sync is also important, but phasing was completely overlooked, I think the current code assumes phase alignment happens automatically, this might be because of ethercat's docs not explaining this well, or because of how linuxcnc is structured the servo thread is started completely separate from the lcec, the servo thread phasing has to be done manually to match DC epoch, even if DC epoch was written by lcec, the moment when servo-thread addf's lcec is practically random, the phasing will be random. Not sure if you understand, I am very deep into testing this for days now, and I can assure you, I have it fixed now, but it was not before.
Last edit: 25 Dec 2025 10:08 by grandixximo.
The following user(s) said Thank You: maxi177

Please Log in or Create an account to join the conversation.

  • Hakan
  • Away
  • Platinum Member
  • Platinum Member
More
25 Dec 2025 19:19 #340502 by Hakan
Replied by Hakan on topic Found the main source of the jitter
I can only take credit for rediscovering the PLL code and write some lines of documentation.
Sasha Ittner made the PLL code back in 2018 and it hasn't changed since then. 

Will be interesting to see what you come up with.
The following user(s) said Thank You: grandixximo

Please Log in or Create an account to join the conversation.

  • endian
  • endian's Avatar
  • Away
  • Elite Member
  • Elite Member
More
25 Dec 2025 20:28 #340505 by endian
Replied by endian on topic Found the main source of the jitter
i am here just for subscribe and learn something more about PLL ... 
The following user(s) said Thank You: grandixximo

Please Log in or Create an account to join the conversation.

  • grandixximo
  • grandixximo's Avatar Topic Author
  • Away
  • Senior Member
  • Senior Member
More
27 Dec 2025 15:44 #340584 by grandixximo
Replied by grandixximo on topic Ethercat random jitter fix
github.com/linuxcnc-ethercat/linuxcnc-et...631ab668516b649fcaaf

Posted the PR
Will be happy to get some feedback, thanks
The following user(s) said Thank You: endian, onceloved, NWE

Please Log in or Create an account to join the conversation.

  • grandixximo
  • grandixximo's Avatar Topic Author
  • Away
  • Senior Member
  • Senior Member
More
29 Dec 2025 21:48 #340684 by grandixximo
Replied by grandixximo on topic Ethercat random jitter fix
The PR has been merged to linuxcnc-ethercat I have some testing modifications which I have not been able to test yet, will update here after I test myself, might be another PR before everything is proper.
The following user(s) said Thank You: endian

Please Log in or Create an account to join the conversation.

  • endian
  • endian's Avatar
  • Away
  • Elite Member
  • Elite Member
More
29 Dec 2025 21:55 #340687 by endian
Replied by endian on topic Ethercat random jitter fix
If you will test it .. please share some visual results before and after{for example scope printscreen) .. We are all interested in your pr I think !

thanks

Please Log in or Create an account to join the conversation.

  • grandixximo
  • grandixximo's Avatar Topic Author
  • Away
  • Senior Member
  • Senior Member
More
30 Dec 2025 08:30 - 30 Dec 2025 13:42 #340704 by grandixximo
Replied by grandixximo on topic Ethercat random jitter fix
The new PR is up, this fixes everything, i will post some pictures later
Edit:
Still got a few kinks to iron out, probably tomorrow for finalized PR
Last edit: 30 Dec 2025 13:42 by grandixximo.
The following user(s) said Thank You: endian

Please Log in or Create an account to join the conversation.

  • grandixximo
  • grandixximo's Avatar Topic Author
  • Away
  • Senior Member
  • Senior Member
More
31 Dec 2025 07:44 - 31 Dec 2025 07:45 #340758 by grandixximo
Replied by grandixximo on topic Ethercat random jitter fix
github.com/linuxcnc-ethercat/linuxcnc-ethercat/pull/465

new PR with pictures, which I don't want to repost here, look at explanation on github, I'm available for questions. code has been tested, everything should be way better now, and possibly can even use not so good hardware and achieve decent ethercat no grinding.
Last edit: 31 Dec 2025 07:45 by grandixximo.
The following user(s) said Thank You: endian

Please Log in or Create an account to join the conversation.

Time to create page: 0.080 seconds
Powered by Kunena Forum