[Etherlab-users] Using DC to syncronise to reference slave clock

Gavin Lambert gavin.lambert at tomra.com
Tue Mar 1 00:01:14 CET 2022


The only difference between ARMW and FRMW is the addressing mode for the slave; there is absolutely no reason this would cause synchronization issues, provided that both select the same slave as reference clock.  (The only "advantage" of ARMW over FRMW is that you can be a bit lazier with the former if declaring that your first slave is always your reference clock - and indeed you do want your reference clock to be earlier in the network than any slaves where you care about their times.)

There's fundamentally two different ways to try to sync the master clock and slave reference clocks.  The first is to use the ecrt_master_sync_reference_clock or ecrt_master_sync_reference_clock_to calls, which will try to keep the clocks fully aligned, essentially by trying to make the slave clocks drift approximately the same as the master's.  The second is to instead only call ecrt_master_reference_clock_time or ecrt_master_64bit_reference_clock_time (the latter requires extra steps) to only read the reference clock's existing time and then perform your own (usually virtual) adjustment to the master clock as needed.  Most of the examples only demonstrate the former; the rtai_rtdm_dc example is the only one that demonstrates the latter.  Which way makes more sense depends on which clock you expect to be "better", as well as whether you need the slaves to have something close to the "real" wall-clock time (only matters for 64-bit DC slaves) or if a relative close-to-zero clock is sufficient for their needs (usually true).

Separate to this is the timing loop for your master packets.  When using the former method you typically just try to send at a steady timestamp based solely on the master clock.  When using the latter, you can still do that if you don't mind jitter and drift, but it's better to try to realign your master cycle based on the reference clock (the rtai_rtdm_dc example demonstrates this as well - be careful you didn't accidentally eliminate that when converting to userspace calls; system2count is critical here).

It's also critically important to consider which values you're using in the ecrt_slave_config_dc call - make sure they match your vendor's recommendations for your intended cycle interval.  In particular, selecting a good shift value may reduce the effect of jitter, where reasonably tight.  (Also bear in mind that sync0 and sync1 cycle/shift times are not treated equivalently.)

Bear in mind that you usually want your packets arriving at a different time from the Sync0 trigger on the slave, allowing for capture and processing delays plus jitter.  It may be useful to connect a scope to observe the relative timing of each event.

I vaguely recall there being a userspace variant of the example code posted to the list a few years back, but I didn't manage to find it in a basic search.

Gavin Lambert

Senior Software Developer TOMRA Fresh Food



[cid:TOMRAFresh_final_size_times_two_2_99d242b2-ba06-4c25-ab26-020cca7ee6dd.png]
 [cid:TF-FB-icon_b77c57e4-4990-4f9d-b3a2-8e6ab45df7f2.jpg] <https://www.facebook.com/TOMRAFreshFood>  [cid:TF-LinkedIn-icon_d54c4829-dcb9-450c-9187-34b26e85ebaa.jpg] <https://www.linkedin.com/company/tomra-fresh-food/>  [cid:TOMRA-Vimeo_4673038e-313a-491f-b3a4-0b39ace6df88.jpg] <https://vimeo.com/tomrafreshfood>  [cid:TOMRAinstagram_45b30c55-490a-4f32-8fd3-998c152e3494.jpg] <https://www.instagram.com/tomrafood/>
 Compac Technologies Ltd | 4 Henderson Place | PO Box 13 516 | Onehunga 1061 | New Zealand

 Phone: +64 96 34 00 88 | https://www.compacsort.com
The information contained in this communication and any attachment is confidential and may be legally privileged. It should only be read by the person(s) to whom it is addressed. If you have received this communication in error, please notify the sender and delete the communication.
From: Celil Can Anik
Sent: Tuesday, 1 March 2022 03:11
To: etherlab-users at etherlab.org
Subject: Re: [Etherlab-users] Using DC to syncronise to reference slave clock

Hi again,

I still work on running Mitsubishi JET servo drives. We managed to run with DC synchronized to slave reference clock. When we check Wireshark data, "System Time Register" 0x910 is transferred with FRMW command. But engineers from Mitsubishi had told us Beckhoff Ethercat master is using ARMW command for "System Time Register" 0x910. Honestly, I don't have any idea why, but they claim this command difference causes synchronization problem. What do you think about this topic?

Also, I checked the source, but couldn't found usage of ARMW command. Is there any example for ARMW command?

Best regards,
Celil





Hi,



How should we use DC to synchronize to the slave reference clock? I implemented it by looking at the rtai_rtdm example. But it's not working as desired.



I guess I'm missing something. I would expect to change my sleep times to synchronize to slave clock. I couldn't see something like that.



* How can I stop drifting my send time relative to slave clock?



* Also, how can I measure the time I'm sending relative to cycle start of the slave clock? Can I just modulo the value returned by ecrt_master_reference_clock_time() to the cycle time?



For a little background:



We are using EtherCAT master for several years. We are using PREEMPT_RT patch with ubuntu 16.04, kernel 4.9.178. We had downloaded Gavin Lambert's unofficial patch sets a few years ago.



Normally we are using master PC as the master clock. This option is mentioned as option a in various mails in the mail list.



With this method we successfully integrated many servo motor drives from several vendors. We are generally using 1ms and 2ms cycle times on different machines.



We have recently added Mitsubishi Jet EtherCAT series to our database. Although this drive is working fine under lab conditions, somehow it gave synchronization errors from time to time at the machine. There are 4 drives and several IOs from Beckhoff on the bus.



Mitsubishi engineers claim that, the problem occurs because we are not synchronized to the slave reference clock. And ask us to change our mechanism to synchronize the master PC to the reference slave. This method is also described as the option b in mail list.



So I copied the related blocks from rtai_rtdm example in the examples folder. I modified RTAI specific functions to user space functions. At our lab we are testing two Jet drives connected to our master PC. The drives are changing to OP mode and I can control the position and speed.

There is no error in dmesg messages. Also no error on the display of the drives. But I hear knocking sounds in every few minutes while rotating.

It seems my send time is drifting relative to slave clock. But I don't see how can I stop drifting.



Best regards,



Celil


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20220228/1cec4d78/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TOMRAFresh_final_size_times_two_2_99d242b2-ba06-4c25-ab26-020cca7ee6dd.png
Type: image/png
Size: 13399 bytes
Desc: TOMRAFresh_final_size_times_two_2_99d242b2-ba06-4c25-ab26-020cca7ee6dd.png
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20220228/1cec4d78/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TF-FB-icon_b77c57e4-4990-4f9d-b3a2-8e6ab45df7f2.jpg
Type: image/jpeg
Size: 10123 bytes
Desc: TF-FB-icon_b77c57e4-4990-4f9d-b3a2-8e6ab45df7f2.jpg
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20220228/1cec4d78/attachment-0004.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TF-LinkedIn-icon_d54c4829-dcb9-450c-9187-34b26e85ebaa.jpg
Type: image/jpeg
Size: 10214 bytes
Desc: TF-LinkedIn-icon_d54c4829-dcb9-450c-9187-34b26e85ebaa.jpg
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20220228/1cec4d78/attachment-0005.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TOMRA-Vimeo_4673038e-313a-491f-b3a4-0b39ace6df88.jpg
Type: image/jpeg
Size: 1540 bytes
Desc: TOMRA-Vimeo_4673038e-313a-491f-b3a4-0b39ace6df88.jpg
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20220228/1cec4d78/attachment-0006.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TOMRAinstagram_45b30c55-490a-4f32-8fd3-998c152e3494.jpg
Type: image/jpeg
Size: 10303 bytes
Desc: TOMRAinstagram_45b30c55-490a-4f32-8fd3-998c152e3494.jpg
URL: <http://lists.etherlab.org/pipermail/etherlab-users/attachments/20220228/1cec4d78/attachment-0007.jpg>


More information about the Etherlab-users mailing list