<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (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:"MS Gothic";
        panose-1:2 11 6 9 7 2 5 8 2 4;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Aptos;}
@font-face
        {font-family:"\@MS Gothic";
        panose-1:2 11 6 9 7 2 5 8 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
p.xmsonormal, li.xmsonormal, div.xmsonormal
        {mso-style-name:x_msonormal;
        margin:0cm;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
p.xmsolistparagraph, li.xmsolistparagraph, div.xmsolistparagraph
        {mso-style-name:x_msolistparagraph;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        font-size:12.0pt;
        font-family:"Aptos",sans-serif;}
span.EmailStyle26
        {mso-style-type:personal-reply;
        font-family:"Aptos",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        mso-ligatures:none;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:459959273;
        mso-list-template-ids:749869928;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1
        {mso-list-id:847602766;
        mso-list-template-ids:-1851081952;}
@list l1:level1
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l2
        {mso-list-id:907955254;
        mso-list-template-ids:-403910378;}
@list l2:level1
        {mso-level-start-at:2;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level2
        {mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level3
        {mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level4
        {mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level5
        {mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level6
        {mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level7
        {mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level8
        {mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l2:level9
        {mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3
        {mso-list-id:1914049331;
        mso-list-template-ids:1809451622;}
@list l3:level1
        {mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level2
        {mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level3
        {mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level4
        {mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level5
        {mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level6
        {mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level7
        {mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level8
        {mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l3:level9
        {mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l4
        {mso-list-id:2033264090;
        mso-list-template-ids:-984447286;}
@list l4:level1
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level2
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level5
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level8
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l4:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></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]-->
</head>
<body lang="EN-NZ" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Hi Circle,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Any time the IOCTL interface gets updated the EC_IOCTL_VERSION_MAGIC constant in ioctl.h should be updated to ensure your application and the master are using the same interface. 
 The GavinL patches updates the version magic number in patch: base/0000-version-magic.patch.  This covers all of the interface changes due to the various patches.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">The user side lib (e.g. via RTDM) checks the kernel side EC_IOCTL_VERSION_MAGIC value against its own in ecrt_open_master() to ensure they have been compiled against the same interface
 / source base.  If you are getting "ioctl() version magic is differing: %s: %u, libethercat: %u.\n" messages then it means your build and/or installation is not working correctly.  Check the two values returned in the error message to figure out which one
 is incorrect (kernel side or user side).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US">Graeme.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal">> <b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Circle Fang
<a href="mailto:circlefang@live.com">circlefang@live.com</a> <br>
</span>> <b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Sent:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Wednesday, 7 May 2025 11:25<br>
</span>> <b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">To:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Graeme Foot
<a href="mailto:Graeme.Foot@touchcut.com">Graeme.Foot@touchcut.com</a><br>
</span>> <b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Cc:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">
<a href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a><br>
</span>> <b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Subject:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Re: DC synchronization demo about etherlab master<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal">><o:p> </o:p></p>
<div>
<p class="MsoNormal">> hi Graeme, <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> thanks for the whole thing, now i totally understand the whole logic about the dc sync as well as "sync master to ref". I applied those three patches but it seems doesn't work. Or maybe it's because i didnt correctly install something
 i dont know(fresh build, make install, make modules_install), even it doesnt report ioctl errors like i mentioned in a previous mail. Anyway, now i am trying to fix the initial huge m_dcDiff by rebuild/reinstall new release of the etherlab master. do you have
 any advices about the unmatched ioctl version problem when call ecrt_request_master?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">> thanks again for all your help, i think these mails surely also help a lot of people like me.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">> Best regards<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">> Circle<o:p></o:p></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:black"> Graeme Foot <<a href="mailto:Graeme.Foot@touchcut.com">Graeme.Foot@touchcut.com</a>><br>
<b>Sent:</b> Tuesday, May 6, 2025 7:00:14 AM<br>
<b>To:</b> Circle Fang <<a href="mailto:circlefang@live.com">circlefang@live.com</a>><br>
<b>Cc:</b> <a href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a> <<a href="mailto:etherlab-users@etherlab.org">etherlab-users@etherlab.org</a>><br>
<b>Subject:</b> RE: DC synchronization demo about etherlab master</span> <o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal"><span style="font-size:11.0pt">Hi Circle,</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Re #1)</span><o:p></o:p></p>
<ul style="margin-top:0cm" type="disc">
<li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">ecrt_master_application_time() stores the PC time in the master.</span><o:p></o:p></li><li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">The ref slave clock is set to the masters time (plus its transmission delay) on activation.</span><o:p></o:p></li><li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">ecrt_master_sync_slave_clocks() syncs subsequent slaves clocks to the ref slave, and returns the ref slave time.</span><o:p></o:p></li><li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">ecrt_master_reference_clock_time() gets the ref slaves time “slaveTime” (minus its transmission delay) from the previous ecrt_master_sync_slave_clocks() 
 call, so returns the slave time, at the time of the send, of the previous send</span><o:p></o:p></li><li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><span style="font-size:11.0pt">“ecMaster->m_dcTime” caches the time sent to ecrt_master_application_time() of the previous send</span><o:p></o:p></li></ul>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-size:11.0pt">So we can compare the difference between “(uint32_t)ecMaster->m_dcTime” and “slaveTime” and if there’s no drift or jitter between the master and slave clocks we should get a value
 of zero.  The rest of the code is attempting to filter out the jitter and calculate a drift compensation.  Note: we are comparing the lower 32 bits of the times.</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-size:11.0pt">“</span><span style="font-family:"Calibri",sans-serif;color:black">why are we using pc time - reference time to caculate m_dcDiff (m_dcTime -slaveTime, even it's named by m_dcTime,
 i think it's still a term of pc time)?”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">if there’s no drift and the ref slave clock has been set to the master clock on activation then the master and slave time should match.  If there’s drift,
 we need to adjust the master time to compensate.  (So it is comparing the PC clock time to the slave time to figure out the drift.)</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">“However time of SYNC0(0x990) is changing quite regularly”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">if dc is enabled on the slave it is incremented by the cycle period every cycle (by the slave).  If it’s a 32bit dc clock the time value rolls over every
 4.2second odd, if it’s a 64bit dc clock you see the whole time value.  For DC to remain synced (and enable dc sync0) it only needs a 32bit dc clock, but if you want proper timestamping of events, you need the 64bit clocks.</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">“0x990 is always like xxxxxxxxxx500000 (500000 is sync0_shift), why don't we try to make slaveTime to, like 0-phase-aligned”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">Once dc is set up sync0 0x990 on the slave just keeps ticking over based on the slaves clock.  The slaves clock is synced to the ref slaves clock.  Your
 application can choose when sync0 occurs on the slave with respect to the cycle but has no other control over it.  However your application must call ecrt_master_send() once every cycle so that the frames reach the slave before the cycles sync0 time is triggered. 
 Other than that you can choose when to call ecrt_master_send().  In your realtime cycle you can choose when to wake up and perform your calculations.  That wakeup event it triggered in relation to the PC’s clock.  So to wake up in relation to the ref slaves
 clock, you need to sync your application (PC) time to the ref slaves time.</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">“BTW, is the write cmd to register 0x990 only sent once at the beginning”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">yes</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Re #2) </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">“I didn't get the "first master diff" in syslog”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">I output all my app messages to the syslog via “rtai_lxrt(BIDX, SIZARG, PRINTK, &arg);”.  Via std out is fine too.</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">“And it's quite big”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">It should be small (within max jitter or so).  If it’s big to start with, it indicates the initial master time is not being set correctly in the ref
 slave on master activation.  If it becomes big then your drift compensation isn’t working.</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black"> </span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">“I don't know why you are saying m_dcDiff should be around 0”:</span><o:p></o:p></p>
<p class="xmsonormal" style="margin-left:18.0pt"><span style="font-family:"Calibri",sans-serif;color:black">As per above, m_dcDiff is the difference between the time master time when the frame was sent and the time at the ref slave.  If the initial slave time
 is set up correctly and you have no drift between the master and slave clocks (or account for the drift) then m_dcDiff should jitter around 0.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Looking at your logs:</span><o:p></o:p></p>
<ul style="margin-top:0cm" type="disc">
<li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l4 level1 lfo2"><span style="font-size:11.0pt">Your syslog logs are showing unmatched and corrupted frames.  You need to sort that out first.  Try contact cleaner on the RJ45 / EBus connections. 
 Also, try higher quality shielded twisted pair cables.  You need to get it to zero comms errors.</span><o:p></o:p></li><li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l4 level1 lfo2"><span style="font-size:11.0pt">You need to get wireshark logs that include the response.  You could use the “ethercat pcap” command if you have patch “features\pcap\0001-pcap-logging.patch”. 
 You could also install a physical switch between your master and the first slave and use another computer as the sniffer (with all protocols disabled on that devices eth port).  Because EtherCAT is a broadcast frame you shouldn’t need to do anything special
 with the switch.</span><o:p></o:p></li><li class="xmsolistparagraph" style="margin-left:0cm;mso-list:l4 level1 lfo2"><span style="font-size:11.0pt">Your crc log is a little weird.  There’s no crc or physical errors, but there are a lot of forwarded errors (more than the max count).  Maybe there’s
 problems on the master to first slave link.</span><o:p></o:p></li></ul>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt">Graeme.</span><o:p></o:p></p>
<p class="xmsonormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> </span><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Circle
 Fang </span><a href="mailto:circlefang@live.com"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">circlefang@live.com</span></a><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">
<br>
</span><span style="font-family:"Calibri",sans-serif">> </span><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Sent:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Saturday, 3 May 2025
 20:10<br>
</span><span style="font-family:"Calibri",sans-serif">> </span><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">To:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Graeme Foot
</span><a href="mailto:Graeme.Foot@touchcut.com"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Graeme.Foot@touchcut.com</span></a><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"><br>
</span><span style="font-family:"Calibri",sans-serif">> </span><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Cc:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">
</span><a href="mailto:etherlab-users@etherlab.org"><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">etherlab-users@etherlab.org</span></a><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif"><br>
</span><span style="font-family:"Calibri",sans-serif">> </span><b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">Subject:</span></b><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">
</span><span style="font-size:11.0pt;font-family:"MS Gothic"">回复</span><span lang="EN-US" style="font-size:11.0pt;font-family:"Calibri",sans-serif">: DC synchronization demo about etherlab master</span><o:p></o:p></p>
</div>
</div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">></span> <o:p></o:p></p>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
Hi Graeme,</span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
Basically I didn't figure out the following two things yet.</span></span><o:p></o:p></p>
</div>
<div>
<ol style="margin-top:0cm" start="1" type="1">
<li class="xmsonormal" style="color:black;mso-list:l3 level1 lfo3"><span style="font-family:"Calibri",sans-serif">why are we using pc time - reference time to caculate m_dcDiff (m_dcTime -slaveTime, even it's named by m_dcTime, i think it's still a term of
 pc time)? I think they could drift together, like both delayed for hundreds of microseconds, since reference time(slaveTime) is strong-related to pc time of ecrt_master_send (get m_dcTime  then call ecrt_master_send).  However time of SYNC0(0x990) is changing
 quite regularlly. so in this way even m_dcDiff is small enough, dc sync error may still occurs becuase both m_dcTime and slaveTime may go beyond the time of 0x990. And I'm wondering why not try to sync master time to SYNC0 (probably with a sync0_shift interval).
 In my test, when i watch the 64bit of 0x990, it is just sync0_shift-phase-aligned, I mean 0x990 is always like xxxxxxxxxx500000 (500000 is sync0_shift), why don't we try to make slaveTime to, like 0-phase-aligned(it could be a little complicated since slaveTime
 is 32-bit, and i still don't figure out how to do this yet, maybe change ecrt_master_reference_clock_time to 64-bit), which means time of ecrt_master_send and both slaveTime is always drifting around 0-phase of SYNC0/0x990(I mean make 64-bit slaveTime always
 xxxxxxxxxabcdef wherein abcdef is around 0). BTW, is the write cmd to register 0x990 only sent once at the beginning?</span><o:p></o:p></li></ol>
</div>
<div>
<ol style="margin-top:0cm" start="2" type="1">
<li class="xmsonormal" style="color:black;mso-list:l2 level1 lfo4"><span style="font-family:"Calibri",sans-serif">I didn't get the "first master diff" in syslog, but I do get this from the cmd line which I run the application. And it's quite big. I am not clear
 about this but I think this is OK. Since the 0-phase-aligned m_dcTimeStart passed into ecrt_master_application_time at the beginning is used to caculate the real dc start time(which written to 0x990) about 100cycles beyond in the future (EC_DC_START_OFFSET=100ms,
 eventually with sync0_shift phase-aligned), and our first wakeup time is 50 cycles in the future, even it's 0-phase-aligned. I don't know why you are saying m_dcDiff should be around 0. </span><o:p></o:p></li></ol>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
I did 2 test, the first one is using your way, and the second is using my way(i don't know it's right or not, but m_dcDiff is always drifting around 0). please see attched logs. As for wireshark logs, only frames sent from master are captured. In those test,
 no motion task, only check the recived datagrams, adjust pc time, and send pdos, so the task is quite light-weight, and MSW(mode switch of xenomai) is always 0. However, from wireshark, sending time is getting odd occasionaly. one more earlier test (not recorded)
 is quite stable, as it's running for 24 hours without any errors, even motion task is running.</span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
The error of "Failed to get reference clock time"  is something like resource un-available, because i called this even for the first time (no datagram received yet). sometimes in the middle of test for a short time, but no dc sync error occurs. And it's not
 easy to reproduce.</span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
In addition, SMI, power-saving, and a lot of other features that may affect realtime task, are disabled. fixed cpu frequency is also set. and /proc/xenomai/stat is ok(no MSW).</span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
It seems my problem has nothing to do with problems by dc patches as mentioned before, since i don't see the difference before/after patches applied. </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
I am sorry this cost you so much time, and I am really really grateful about this.</span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
Best Regards,</span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">> <span style="color:black">
Circle   </span></span><o:p></o:p></p>
</div>
<div>
<p class="xmsonormal"><span style="font-family:"Calibri",sans-serif">><span style="color:black"> </span></span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>