<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,</p>
<p><br>
</p>
<p>Thats one of the older forum postings and is code for an older version of the master (revision 2266).  The changeset I sent is for master revision 2526 (still old but I haven't needed to move on yet).</p>
<p><br>
</p>
<p>Have a look at this one:</p>
<p><a href="http://lists.etherlab.org/pipermail/etherlab-users/2016/003026.html" class="OWAAutoLink" id="LPlnk215996" previewremoved="true">http://lists.etherlab.org/pipermail/etherlab-users/2016/003026.html</a><br>
</p>
<p><br>
</p>
<p>Note: there is a bug in the <span style="white-space: pre-wrap; font-size: 12pt;">ecMod_syncDistClock() funciton from that post. It should probably instead be (changed line in bold):</span></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;"><br>
</span></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;"></p>
<pre style="white-space: pre-wrap;">int32_t ecMod_syncDistClock(
        void *this            /**< pointer to module etherCATModule_s */
        )
{
  etherCATModule_s *ecMod = this;
  uint32_t          masterTime;

  // cache lower 32 bits of prev master time and get now
  masterTime      = (uint32_t)ecMod->m_dcTime;
  ecMod->m_dcTime = app_getTimeNS();


  // use the dc ref slave to adjust the masters time base

  // get lower 32 bit of clock time from reference slave (after first scan)
  if (ecMod->m_getDCDiff)
  {
    int      res;
    uint32_t slaveTime;
    res = ecrt_master_reference_clock_time(ecMod->master, &slaveTime);

    switch (res)
    {
      case 0 :
      {
        // calc time diff
        ecMod->m_dcDiff = masterTime - slaveTime;
      } break;

      default :
      {
        // no ref clock found or datagram failure
        ecMod->m_dcDiff = 0;
      }
    }
  }
  else
  {
    ecMod->m_dcDiff    = 0;
    ecMod->m_getDCDiff = true;
  }

  // call to sync slaves to ref slave
  // (which is used for ecrt_master_reference_clock_time)
  ecrt_master_sync_slave_clocks(ecMod->master);

<b>  // set master time in nano-seconds
  ecrt_master_application_time(ecMod->master, ecMod->m_dcTime);
</b>

  return 0;
}</pre>
<br>
</span>
<p></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;"><br>
</span></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;"><br>
</span></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;">Graeme.</span></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;"><br>
</span></p>
<p><span style="white-space: pre-wrap; font-size: 12pt;"><br>
</span></p>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Jiarui Lian <jerry@bertec.com><br>
<b>Sent:</b> Friday, 13 January 2017 04:57<br>
<b>To:</b> Graeme Foot<br>
<b>Subject:</b> not found Re: Patch for Distributed Clock?</font>
<div> </div>
</div>
<div>
<div style="font-family:arial,helvetica,sans-serif; font-size:12pt; color:#000000">
<div>Hi, Graeme:<br>
</div>
<div><br>
</div>
<div>I couldn't found the following functions in your patch:<br>
</div>
<div>(as you mentioned in: http://lists.etherlab.org/pipermail/etherlab-users/2012/001642.html)<br>
</div>
<div>1) ecrt_master_setup_distributed_clock()</div>
<div>2) ecrt_master_sync_slave_clocks_diff()</div>
<div>3) I have changed the ref_sync_datagram to 4 bytes instead of 8.</div>
<div><br>
</div>
<div>Did you send the wrong patch, or you change the function names?<br>
</div>
<div>Thanks!<br>
</div>
<div><br>
</div>
<div>Jerry<br>
</div>
<div><br>
</div>
<hr id="zwchr">
<div><b>From: </b>"Graeme Foot" <Graeme.Foot@touchcut.com><br>
<b>To: </b>"Jiarui Lian" <jerry@bertec.com><br>
<b>Cc: </b>"etherlab-users" <etherlab-users@etherlab.org><br>
<b>Sent: </b>Wednesday, January 11, 2017 5:05:53 PM<br>
<b>Subject: </b>Re: Patch for Distributed Clock?<br>
</div>
<br>
<div>
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p>Hi,</p>
<p><br>
</p>
<p>I've attached an hg changeset of the patches I use.  You can get the DC related ones from it.  If you look in the etherlab-dev forum you will also find Gavin's patchsets which will be more up to date.</p>
<p><br>
</p>
<p>Do a search for "etherlab-users dc" (or similar) to find posts related to how to set up distributed clocks.  eg:</p>
<p><a href="http://lists.etherlab.org/pipermail/etherlab-users/2016/003014.html" class="OWAAutoLink" id="LPlnk349485" target="_blank" previewremoved="true">http://lists.etherlab.org/pipermail/etherlab-users/2016/003014.html</a><br>
</p>
<p><br>
</p>
<p>But to answer you question:</p>
<p><br>
</p>
<p>A system requires one master clock that all other clocks in the system sync to.  That clock can either be the clock in the EtherCAT master or it can be a clock on one of the slaves (the dc reference slave).  Separate to that, all dc slaves on the bus need
 to be synced to a reference slave clock.  This should be the first slave on the bus that supports dc.  The EtherLAB master will automatically select this for you, or with the patch you can select it yourself.</p>
<div><br>
</div>
Generally the EtherCAT master clock has too much jitter to provide a nice stable system, so instead I use option two where my dc reference slave is the master clock and I adjust the EtherCAT master clock to it (this is the default option used by TwinCAT).
<div><br>
</div>
<div>Also note (as described in the post I linked to above), there are two levels of dc support in slaves.  DC clock level support (alot of simple IO slaves have this) and the ability to sync the IO to the dc clock (generally only more advanced slaves support
 this).  The DC reference slave only requires the DC clock level of support.</div>
<div><br>
</div>
<div>In your case, if your AX5206 slave is the first slave it can be both the reference slave and the DC clock master.</div>
<div><br>
</div>
<div>Regards,</div>
<div>Graeme.</div>
<div><br>
</div>
<div>PS: Our system uses various IO modules and amps.  Our dc reference slave is often our first IO module (an EL1008).  </div>
<div><br>
<br>
<div style="color:rgb(0,0,0)">
<div>
<hr style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><span color="#000000" face="Calibri, sans-serif" style="font-size:11pt; color:#000000; font-family:Calibri,sans-serif"><b>From:</b> Jiarui Lian <jerry@bertec.com><br>
<b>Sent:</b> Thursday, 12 January 2017 06:39<br>
<b>To:</b> Graeme Foot<br>
<b>Subject:</b> Patch for Distributed Clock?</span>
<div> </div>
</div>
</div>
<span size="2" style="font-size:small"><span style="font-size:10pt">
<div class="PlainText">Hi, Dear Mr. Graeme Foot:<br>
<br>
I am studying IgH-EtherCAT-Master to control AX5206, and I saw your post in 2012:<br>
        <a href="http://lists.etherlab.org/pipermail/etherlab-users/2012/001642.html" id="LPlnk529161" target="_blank" previewremoved="true">
http://lists.etherlab.org/pipermail/etherlab-users/2012/001642.html</a><br>
<br>
* Would you mind to send a copy of the patch to me? <br>
* And a question, when you said: "pick a ref slave and update my master time based on the ref slave time."<br>
  Does your system consist of at least two slaves with DC capability?<br>
     Master(Jitter) ---- Slave.1 (DC, Ref-to-Master) ---- Slave.2(DC, Ref-to-Slaves) ---- MoreSlaves                       
<br>
  In my case, I have only one slave with DC:<br>
     Master(Jitter) ---- Slave.1(AX5206, DC) --- MoreSlaves<br>
  Any suggestion to me?<br>
<br>
<br>
Thanks, your help is appreciated!<br>
<br>
Sincerely,<br>
Jerry<br>
Bertec Corp.<br>
</div>
</span></span></div>
</div>
</div>
<br>
</div>
</div>
</div>
</div>
</div>
</body>
</html>