<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
Hello Graeme,<br>
<br>
Am 23.03.2012 21:27, schrieb Graeme Foot:
<blockquote
cite="mid:887907165610B145B013C33A6D1C2229801CD2@hagar.touchcut.local"
type="cite">
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]-->
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";
color:black;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Consolas","serif";
color:black;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Arial","sans-serif";
color:navy;}
span.EmailStyle20
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";
color:black;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:21.0cm 842.0pt;
margin:2.0cm 2.0cm 2.0cm 2.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">I’ve
just been going through tidying up my Linux image and came across
/etc/ethercat.conf.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">The
documentation refers to using the /etc/init.d/ethercat script and
/etc/sysconfig/ethercat as its configuration file.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">However
I also found /etc/ethercat.conf which is called from
usr/sbin/ethercatctl. Are these ones obsolete?<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
</div>
</blockquote>
You are right, they are obsolete.<br>
<br>
Greatings<br>
<br>
Andreas<br>
<blockquote
cite="mid:887907165610B145B013C33A6D1C2229801CD2@hagar.touchcut.local"
type="cite">
<div class="WordSection1">
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);">Graeme.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 11pt; font-family: "Calibri","sans-serif"; color: rgb(31, 73, 125);"><o:p> </o:p></span></p>
<div>
<div
style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;">
<p class="MsoNormal"><b><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US">From:</span></b><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US"> <a class="moz-txt-link-abbreviated" href="mailto:etherlab-users-bounces@etherlab.org">etherlab-users-bounces@etherlab.org</a>
[<a class="moz-txt-link-freetext" href="mailto:etherlab-users-bounces@etherlab.org">mailto:etherlab-users-bounces@etherlab.org</a>] <b>On Behalf Of </b>Graeme
Foot<br>
<b>Sent:</b> Thursday, 22 March 2012 12:44 p.m.<br>
<b>To:</b> <a class="moz-txt-link-abbreviated" href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a><br>
<b>Cc:</b> Ralf Rösch<br>
<b>Subject:</b> Re: [etherlab-users] Patch for Distributed Clock<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB">I just noticed yesterday that I had forgotten to
initialise the dc_ref_slave variable, so it would sometimes get an opps
on startup. I have also added the extern "C" define to ec_rtdm.h
(provided by Ralf Wiegand).<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US">Ralf Rösch (below) </span><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB">has also asked for a bit more detail as to how I'm using
the reference slave as the dc clock master so I've also added another
example (examples/rtai_rtdm_dc). Let me know if it fails or something
is not clear enough (I've built it without errors but haven't had a
chance to test it, fingers crossed).<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB">I have attached the updated patch.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB">Graeme.<o:p></o:p></span></p>
<p class="MsoNormal"><span
style="font-size: 10pt; font-family: "Arial","sans-serif"; color: navy;"
lang="EN-GB"><o:p> </o:p></span></p>
<div>
<div class="MsoNormal" style="text-align: center;" align="center"><span
style="color: windowtext;" lang="EN-US">
<hr size="2" width="100%" align="center"></span></div>
<p class="MsoNormal"><b><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US">From:</span></b><span
style="font-size: 10pt; font-family: "Tahoma","sans-serif"; color: windowtext;"
lang="EN-US"> Ralf Rösch <a moz-do-not-send="true"
href="mailto:[mailto:ralf.roesch@rw-gmbh.de]">[mailto:ralf.roesch@rw-gmbh.de]</a>
<br>
<b>Sent:</b> Thursday, 22 March 2012 09:30<br>
<b>To:</b> Graeme Foot<br>
<b>Subject:</b> Re: [etherlab-users] Patch for Distributed Clock</span><span
style="color: windowtext;" lang="EN-US"><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-bottom: 12pt;"><span lang="EN-GB">Hi
Graeme,<br>
<br>
thanks a lot for your great job.<br>
I would like to implement your way of syncing DC under RT PREEMPT.<br>
Do you have a more detailed example for using your method.<br>
I do not understand completely your description below. <br>
The best explanation would be piece of source code.<br>
May be you can collect the relevant sections 1) .. 4) of your source?<br>
<br>
Thanks a lot in advance<br>
Ralf<o:p></o:p></span></p>
<pre><span lang="EN-GB">Roesch & Walter___________________________________________<o:p></o:p></span></pre>
<pre><span lang="EN-GB">Industrie-Elektronik GmbH * Tel.: +49-7824 / 6628-0<o:p></o:p></span></pre>
<pre><span lang="EN-GB">Wörtelweg 2b/c * Fax: +49-7824 / 6628-29<o:p></o:p></span></pre>
<pre><span lang="EN-GB">D-77963 Schwanau * <a
moz-do-not-send="true" href="mailto:ralf.roesch@rw-gmbh.de">mailto:ralf.roesch@rw-gmbh.de</a><o:p></o:p></span></pre>
<pre><span lang="EN-GB">Germany * WWW: <a
moz-do-not-send="true" href="http://www.rw-gmbh.de">http://www.rw-gmbh.de</a><o:p></o:p></span></pre>
<pre><span lang="EN-GB">Amtsgericht Freiburg i.Br. HRB 391345<o:p></o:p></span></pre>
<pre><span lang="EN-GB">Geschäftsführer: Dipl.Ing.(FH) Ralf Rösch, Dipl.Ing.(FH) Martin Walter<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">GnuPG key: 52ECD70F 2010-09-04 [expires: 2012-12-31]<o:p></o:p></span></pre>
<pre><span lang="EN-GB">Fingerprint: 8415 9113 5F05 D579 6685 D5AD 5CE7 5429 52EC D70F<o:p></o:p></span></pre>
<p class="MsoNormal"><span lang="EN-GB">On Thu Mar 15 2012 02:09:49
GMT+0100, Graeme Foot <a moz-do-not-send="true"
href="mailto:GraemeF@touchcut.com"><GraemeF@touchcut.com></a>
wrote: <o:p></o:p></span></p>
<pre><span lang="EN-GB">Hi,<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">As part of my dabbling into getting my distributed clock stable I have<o:p></o:p></span></pre>
<pre><span lang="EN-GB">made a couple of changes.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">I have attached two patches:<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- etherlabmaster-1.5-2266-a_rtdm_dc.patch -> all my rtdm and dc changes<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- etherlabmaster-1.5-2266-c_dc_clock_fix.patch -> just the dc clock<o:p></o:p></span></pre>
<pre><span lang="EN-GB">changes<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">My primary problem was an unstable master clock source. In tracking<o:p></o:p></span></pre>
<pre><span lang="EN-GB">down what the problem was I also checked out what TwinCat was doing.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">TwinCat has three distributed clock modes:<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- (default) Master time/cycle updated to match ref slave time<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- Ref slave time updated to match Master time<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- Master time and Ref slave time updated to match an external clock<o:p></o:p></span></pre>
<pre><span lang="EN-GB">source<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">TwinCat also allows you to choose which slave to use as the ref slave.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">TwinCat uses datagrams:<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> ARMW 0x0 0x910 (sync slaves to ref)<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> APWR 0x0 0x910 (sync ref to master)<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">and replaces the second datagram with a NOP when its not required.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">The EtherLabs master uses datagrams:<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> APWR 0x0 0x910 (sync ref to master)<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> FRMW 0x1 0x910 (sync slaves to ref)<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">with no sync ref to master when its not required. (ARMW vs FRMW<o:p></o:p></span></pre>
<pre><span lang="EN-GB">shouldn't make any difference.)<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">In my system I have two issues:<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- My master clock (although it is now stable) gets a jitter of +-5000ns<o:p></o:p></span></pre>
<pre><span lang="EN-GB">(though usually +-2000ns) between the call to get the system time and<o:p></o:p></span></pre>
<pre><span lang="EN-GB">when the frame is actually sent out to the slaves. This will be, I<o:p></o:p></span></pre>
<pre><span lang="EN-GB">assume, due to various code paths being called during the master_send.<o:p></o:p></span></pre>
<pre><span lang="EN-GB">- My Beckhoff CX1100-0004 coupler does not seem to be a stable ref<o:p></o:p></span></pre>
<pre><span lang="EN-GB">slave.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">So what I've done is decided to use the default TwinCat method where I<o:p></o:p></span></pre>
<pre><span lang="EN-GB">pick a ref slave and update my master time based on the ref slave time.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">What the patch includes:<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">1) ecrt_master_setup_distributed_clock()<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">Lets you set the masters application time and choose a ref slave (or<o:p></o:p></span></pre>
<pre><span lang="EN-GB">NULL) in one call.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">2) ecrt_master_sync_slave_clocks_diff()<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">Sets the masters application time and returns the time difference<o:p></o:p></span></pre>
<pre><span lang="EN-GB">between the last master app time and the last ref slaves time (in one<o:p></o:p></span></pre>
<pre><span lang="EN-GB">call).<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">This gets called instead of ecrt_master_application_time();<o:p></o:p></span></pre>
<pre><span lang="EN-GB">ecrt_master_sync_reference_clock(); and ecrt_master_sync_slave_clocks(),<o:p></o:p></span></pre>
<pre><span lang="EN-GB">although these calls still work in their current fashion.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">3) I have changed the ref_sync_datagram to 4 bytes instead of 8.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">From my reading of the ET1100 Hardware Data Sheet and looking at the<o:p></o:p></span></pre>
<pre><span lang="EN-GB">TwinCat datagrams the ref_sync_datagram should only sync the low 4 bytes<o:p></o:p></span></pre>
<pre><span lang="EN-GB">of the time.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">4) I have changed ec_master_find_dc_ref_clock() to use either the user<o:p></o:p></span></pre>
<pre><span lang="EN-GB">specified ref-slave (if found and compatible) or the first compatible<o:p></o:p></span></pre>
<pre><span lang="EN-GB">slave (if user ref slave not specified or not found or compatible).<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">5) I have changed ec_master_find_dc_ref_clock() to also update the<o:p></o:p></span></pre>
<pre><span lang="EN-GB">ref_sync_datagram with the ref slave address.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">Previously, if the first slave was not DC compatible (although unlikely)<o:p></o:p></span></pre>
<pre><span lang="EN-GB">then the ref_sync_datagram and sync_datagram would not refer to the same<o:p></o:p></span></pre>
<pre><span lang="EN-GB">slave and DC would fail to stay synced to the master.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">How I'm using it (Note: I'm using my rtdm versions):<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">1) During setup I'm calling ecrt_master_setup_distributed_clock() and<o:p></o:p></span></pre>
<pre><span lang="EN-GB">supplying my desired reference slave (via its slave_config).<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">2) During realtime operation, directly before calling<o:p></o:p></span></pre>
<pre><span lang="EN-GB">ecrt_rtdm_master_send() (to reduce timing jitter) I'm getting the system<o:p></o:p></span></pre>
<pre><span lang="EN-GB">time then calling ecrt_rtdm_master_sync_slave_clocks_diff() and caching<o:p></o:p></span></pre>
<pre><span lang="EN-GB">the returned time difference.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">3) After ecrt_rtdm_master_send() I'm using the cached time difference to<o:p></o:p></span></pre>
<pre><span lang="EN-GB">calculate a cycle period adjustment. I then use the cycle period<o:p></o:p></span></pre>
<pre><span lang="EN-GB">adjustment to set a system time offset every period. Whenever I read<o:p></o:p></span></pre>
<pre><span lang="EN-GB">the system time throughout the application I apply the system time<o:p></o:p></span></pre>
<pre><span lang="EN-GB">offset.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">Instead of using rtai's rt_wait_period I instead use rt_sleep_until<o:p></o:p></span></pre>
<pre><span lang="EN-GB">using the offset system time for the next wakeup time.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">I calculate my cycle period adjustment by averaging the time diff over<o:p></o:p></span></pre>
<pre><span lang="EN-GB">1000 periods. I've found any filter shorter than that gets too much<o:p></o:p></span></pre>
<pre><span lang="EN-GB">variation. I also add or subtract 1ns per period based on the current<o:p></o:p></span></pre>
<pre><span lang="EN-GB">cycles time diff to allow for any immediate variation requirements and<o:p></o:p></span></pre>
<pre><span lang="EN-GB">general drift.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">4) If I have multiple masters (which I currently don't) then the first<o:p></o:p></span></pre>
<pre><span lang="EN-GB">master will act this way and all subsequent masters will use the current<o:p></o:p></span></pre>
<pre><span lang="EN-GB">method (by sending the master time to the ref slave).<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">One thing to note is that the time difference returned by<o:p></o:p></span></pre>
<pre><span lang="EN-GB">ecrt_rtdm_master_sync_slave_clocks_diff() is often one period out. (ie<o:p></o:p></span></pre>
<pre><span lang="EN-GB">the time diff returned is ~1000000ns on a 1000000ns period.) The code<o:p></o:p></span></pre>
<pre><span lang="EN-GB">is:<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"> // adjust slave time back to send time (ie remove transmission delay)<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> uint32_t slaveTime = EC_READ_U32(master->sync_datagram.data) - <o:p></o:p></span></pre>
<pre><span lang="EN-GB"> master->dc_ref_clock->transmission_delay;<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> uint32_t masterTime = (uint32_t)master->app_time;<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> <o:p></o:p></span></pre>
<pre><span lang="EN-GB"> *time_diff = masterTime - slaveTime;<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"> // set new app time<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> ecrt_master_application_time(master, app_time);<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">This gets the time difference between the ref slaves time (adjusted for<o:p></o:p></span></pre>
<pre><span lang="EN-GB">transmission delay) from the returned sync datagram and the previous<o:p></o:p></span></pre>
<pre><span lang="EN-GB">master app time. It then sets the new master app time.<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">In my application I don't care if I'm one or more cycles out, I just<o:p></o:p></span></pre>
<pre><span lang="EN-GB">care that the cycles stay in sync. So I adjust my returned time diff to<o:p></o:p></span></pre>
<pre><span lang="EN-GB">the nearest cycle by:<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"> timeDiff = ((timeDiff + (scanTimeNS/2)) % scanTimeNS) -<o:p></o:p></span></pre>
<pre><span lang="EN-GB">(scanTimeNS/2);<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">Florian, a question for you, does this mean that the slaves might be<o:p></o:p></span></pre>
<pre><span lang="EN-GB">being set with a System Time Offset one period out? This could account<o:p></o:p></span></pre>
<pre><span lang="EN-GB">for why the "Slave did not sync after 5000 ms" error occurs now and<o:p></o:p></span></pre>
<pre><span lang="EN-GB">then. <o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">To calculate my calibrated cpu frequency to match the ref slaves clock I<o:p></o:p></span></pre>
<pre><span lang="EN-GB">record the system time from when I start to get time diffs. After some<o:p></o:p></span></pre>
<pre><span lang="EN-GB">time has passed I then perform the following calculation:<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"> int64_t diffTime = currentTime - startTime;<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> int64_t adjTime = diffTime + timeOffset;<o:p></o:p></span></pre>
<pre><span lang="EN-GB"> int64_t cpufreq = nano2count(1000000000);<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"> cpu_freq = (int64_t)((double)cpufreq * (double)adjTime /<o:p></o:p></span></pre>
<pre><span lang="EN-GB">(double)diffTime);<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB"><o:p> </o:p></span></pre>
<pre><span lang="EN-GB">Regards,<o:p></o:p></span></pre>
<pre><span lang="EN-GB">Graeme.<o:p></o:p></span></pre>
<p class="MsoNormal"><span lang="EN-GB"><br>
<br>
<br>
<br>
<o:p></o:p></span></p>
<pre><span lang="EN-GB">_______________________________________________<o:p></o:p></span></pre>
<pre><span lang="EN-GB">etherlab-users mailing list<o:p></o:p></span></pre>
<pre><span lang="EN-GB"><a moz-do-not-send="true"
href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a><o:p></o:p></span></pre>
<pre><span lang="EN-GB"><a moz-do-not-send="true"
href="http://lists.etherlab.org/mailman/listinfo/etherlab-users">http://lists.etherlab.org/mailman/listinfo/etherlab-users</a><o:p></o:p></span></pre>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
etherlab-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.etherlab.org/mailman/listinfo/etherlab-users">http://lists.etherlab.org/mailman/listinfo/etherlab-users</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">Mit freundlichem Gruß
Andreas Stewering-Bone
--
------------------------------------------------------------------------
Dipl.-Ing.(FH) Andreas Stewering-Bone
<a class="moz-txt-link-abbreviated" href="mailto:andreas.stewering-bone@igh-essen.com">andreas.stewering-bone@igh-essen.com</a>
Tel.: +49 201 / 36014-15
Ingenieurgemeinschaft IgH
Gesellschaft für Ingenieurleistungen mbH
Heinz-Bäcker-Str. 34
D-45356 Essen
Amtsgericht Essen HRB 11500
USt-Id.-Nr.: DE 174 626 722
Geschäftsführung:
- Dr.-Ing. S. Rotthäuser,
- Dr.-Ing. T. Finke,
- Dr.-Ing. W. Hagemeister
Tel.: +49 201 / 360-14-0
<a class="moz-txt-link-freetext" href="http://www.igh-essen.com">http://www.igh-essen.com</a>
------------------------------------------------------------------------
</pre>
</body>
</html>