<div dir="ltr">We just implemented option 2, and so far it seems to work perfectly now :)<br><br>Cheers,<br>Jeroen<br><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 22, 2014 at 12:33 AM, Graeme Foot <span dir="ltr"><<a href="mailto:Graeme.Foot@touchcut.com" target="_blank">Graeme.Foot@touchcut.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<u></u><u></u><u></u><u></u>
<div link="blue" vlink="blue" lang="EN-GB">
<div>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">Which time you use doesn't matter so much as long as it's stable and you get minimal jitter.<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">With RTAI on startup Linux calculates a cpu frequency and calibrates the timer against it. Between cold starts Linux will generally
get the same value, but if you do a soft restart it will often calculate a different value. It also only calculates to the nearest micro second. different boxes with the same hardware specs may also get different values. If you need a consistent time base
then you need to calibrate this value for your hardware and set it explicitly on startup. If you are using RTAI you can do the following (allowing you to specify a value to 1 nano second):<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">MODULE_DIR=`/usr/realtime/bin/rtai-config --module-dir`<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">insmod "${MODULE_DIR}/rtai_hal.ko" rtai_cpufreq_arg=<calibrated_value><u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">see:
<a href="https://www.rtai.org/userfiles/documentation/documents/RTAI_User_Manual_34_03.pdf" target="_blank">
https://www.rtai.org/userfiles/documentation/documents/RTAI_User_Manual_34_03.pdf</a> or similar<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">I don't know if other realtime Linux implementations do a similar thing.<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">But regardless of how well you calibrate your pc clock there will eventually be drift between the PC and the EtherCAT modules. So how
does the EtherCAT DC system avoid this?<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">1) assume the PC cycle time is correct and use it as the master time. (EtherLabs master default option)<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">In this case you need to:<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">- call ecrt_master_application_time() to tell the EtherLabs master what the current PC time is<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">- call ecrt_master_sync_reference_clock() to tell the master DC slave to sync to the current PC time<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">- call ecrt_master_sync_slave_clocks() to tell the remaining DC slaves to sync to the master slaves time<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">This option has a lot of jitter which the EtherCAT slaves often don't like, especially if the cycle times are somewhat different. If
you soft reboot and haven't calibrated then expect a different cycle time.<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">2) assume the first
<u></u><u></u>EtherCAT<u></u> <u></u>
DC<u></u><u></u> slave cycle time is correct and use it as the master time. (TwinCAT default option)<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">In this case you need to:<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">- call ecrt_master_reference_clock_time() to get the DC slave master time, calculate any drift from your PC cycle and adjust your PC
cycle to suit<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">- call ecrt_master_sync_slave_clocks() to tell the remaining DC slaves to sync to the master slaves time<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">- call ecrt_master_application_time () with a "psudo" time that matches the DC slaves time (I generally just use "last_time + cycle_time"
as it’s the first thing I do on wakeup)<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">So in summary:<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">ecrt_master_sync_slave_clocks() is always required to sync the DC slave to the master DC slave, then it is up to you whether you want
to use option 1 or 2 above.<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">Hope this helps,<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">Graeme.<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy">PS: I use option 2. I had all sorts of problems with option 1.<u></u><u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<p class="MsoNormal"><font color="navy" face="Arial"><span style="font-size:10.0pt;font-family:Arial;color:navy"><u></u> <u></u></span></font></p>
<div>
<div class="MsoNormal" style="text-align:center" align="center"><font face="Times New Roman" size="3"><span style="font-size:12.0pt" lang="EN-US">
<hr align="center" size="2" width="100%">
</span></font></div>
<p class="MsoNormal"><b><font face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma;font-weight:bold" lang="EN-US">From:</span></font></b><font face="Tahoma"><span style="font-size:10.0pt;font-family:Tahoma" lang="EN-US"> <a href="mailto:etherlab-users-bounces@etherlab.org" target="_blank">etherlab-users-bounces@etherlab.org</a>
[mailto:<a href="mailto:etherlab-users-bounces@etherlab.org" target="_blank">etherlab-users-bounces@etherlab.org</a>] <b><span style="font-weight:bold">On Behalf Of
</span></b>Jeroen Proveniers<br>
<b><span style="font-weight:bold">Sent:</span></b> Wednesday, 21 May 2014 20:49<br>
<b><span style="font-weight:bold">Cc:</span></b> <u></u><a href="mailto:etherlab-users@etherlab.org" target="_blank">etherlab-users@etherlab.org</a><u></u><br>
<b><span style="font-weight:bold">Subject:</span></b> Re: [etherlab-users] DC sync and arrival times of datagrams</span></font><span lang="EN-US"><u></u><u></u></span></p>
</div><div><div class="h5">
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><font face="Times New Roman" size="3"><span style="font-size:12.0pt">Interestingly, the master thinks it sends 5000 datagrams per second, as the "ethercat master" command shows.<u></u><u></u></span></font></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><font face="Times New Roman" size="3"><span style="font-size:12.0pt">I took timestamps using debug level 2, and the scheduling is correct, sometimes the delta between datagrams is 203us, but the next delta is
197 then. Average is a nice 200us.<u></u><u></u></span></font></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><font face="Times New Roman" size="3"><span style="font-size:12.0pt">It turned out the ACPI_PM timer we use as a timebase is apparently way off, about 5% (the slave only receives about 4700 datagrams per second).
We changed it to HPET (with which we have had issues in the past I heard) and it's basically spot on now.<br>
<br>
I have to see how we get the master to use actually use slave #0 as reference clock (it is set as reference but somehow not used I think).<u></u><u></u></span></font></p>
</div>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:12.0pt">Cheers,<br>
Jeroen<u></u><u></u></span></font></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><font face="Times New Roman" size="3"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>
<div>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:12.0pt">On Mon, May 19, 2014 at 12:25 PM, Jeroen Van den Keybus <<a href="mailto:jeroen.vandenkeybus@gmail.com" target="_blank">jeroen.vandenkeybus@gmail.com</a>> wrote:<u></u><u></u></span></font></p>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:12.0pt">It looks like the master process isn't scheduling itself properly. To<br>
check, have the master log the timestamps you're using to synchronize<br>
the slaves (whatever you use as argument of<br>
ecrt_master_application_time()). If all is well, you should be sending<br>
timestamps with, on average, EXACTLY the cycle time (what you<br>
programmed to generate SYNC0 in the slaves) as time difference.<br>
<br>
Beware of rounding errors when scheduling the master process, as well<br>
as different timebases.<br>
<font color="#888888"><span style="color:#888888"><br>
<br>
<span>J.</span></span></font><u></u><u></u></span></font></p>
</div>
<p class="MsoNormal"><font face="Times New Roman" size="3"><span style="font-size:12.0pt"><u></u> <u></u></span></font></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br></div></div></div>