<?xml version="1.0" encoding="UTF-8"?>
<net name="MtrCtrl" type="iopt-flow">
  <event id="SyncPos" x="210" y="190" mode="input"/>
  <signal id="Pos" x="210" y="245" mode="input" type="range" min="0" max="3599" frac="0" value="0" dynamic="none">
    <comment text="0.1 degrees" off_x="0" off_y="20"/>
  </signal>
  <signal id="Speed" x="210" y="290" mode="input" type="boolean" min="0" max="1" frac="0" value="0" dynamic="none">
    <comment text="rpm" off_x="0" off_y="20"/>
  </signal>
  <signal id="Sec" x="215" y="405" mode="input" type="range" min="0" max="2147483647" frac="0" value="0" dynamic="none"/>
  <signal id="uSec" x="215" y="450" mode="input" type="range" min="0" max="999999" frac="0" value="0" dynamic="none"/>
  <event id="Ack" x="815" y="190" mode="output"/>
  <arc id="a007" type="read" source="SyncPos" target="Ack"/>
  <component id="c1" class="timers/SysTime.xml" x="355" y="350" width="110" height="60" rot="0" implementation="iopt-flow" target="external">
    <name off_x="-55" off_y="-35" text="LocalSysTime"/>
    <source_model file="files/SysTime.xml"/>
    <input id="c1.Upd" name="Upd" type="event" off_x="-55" off_y="-10"/>
    <output id="c1.Sec" name="Sec" off_x="55" off_y="-10" type="range" min="0" max="2147483647"/>
    <output id="c1.uSec" name="uSec" off_x="55" off_y="10" type="range" min="0" max="999999"/>
  </component>
  <operation id="o002" x="550" y="365" rot="0" shape="arrow" size="40">
    <name off_x="-35" off_y="-40" text="Delay_ms"/>
    <input off_x="-40" off_y="-24" name="Sec" id="o002.Sec" type="range" min="0" max="2147483647" dynamic="all"/>
    <input off_x="-40" off_y="-8" name="uSec" id="o002.uSec" type="range" min="0" max="999999" dynamic="all"/>
    <input off_x="-40" off_y="8" name="Sec_B" id="o002.Sec_B" type="range" min="0" max="2147483647" dynamic="all" frac="0"/>
    <input off_x="-40" off_y="24" name="uSec_B" id="o002.uSec_B" type="range" min="0" max="999999" dynamic="all" frac="0"/>
    <output off_x="40" off_y="0" name="out" id="o002.out" type="range" min="-1" max="10000" dynamic="none" frac="0">
      <expression>
        <operand type="sub-expression">
          <operand type="signal" idRef="Sec"/>
          <operator type="sub"/>
          <operand type="signal" idRef="Sec_B"/>
        </operand>
        <operator type="mul"/>
        <operand type="literal" value="1000"/>
        <operator type="add"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="uSec"/>
          <operator type="sub"/>
          <operand type="signal" idRef="uSec_B"/>
        </operand>
        <operator type="div"/>
        <operand type="literal" value="1000"/>
        <text>(Sec - Sec_B) * 1000 + (uSec - uSec_B) / 1000</text>
      </expression>
    </output>
  </operation>
  <arc id="a005" type="read" source="Sec" target="o002.Sec_B"/>
  <arc id="a006" type="read" source="uSec" target="o002.uSec_B"/>
  <operation id="o007" x="700" y="275" rot="0" shape="arrow" size="48">
    <name off_x="-43" off_y="-48" text="CalcSyncRefPos"/>
    <input off_x="-48" off_y="-32" name="SyncPos" id="o007.SyncPos" type="event" dynamic="all"/>
    <input off_x="-48" off_y="-16" name="Pos" id="o007.Pos" type="range" min="0" max="3599" dynamic="all" frac="0"/>
    <input off_x="-48" off_y="0" name="Speed" id="o007.Speed" type="boolean" min="0" max="1" dynamic="all" frac="0"/>
    <input off_x="-48" off_y="16" name="Delay_ms" id="o007.Delay_ms" type="range" min="-1" max="10000" dynamic="all" frac="0"/>
    <input off_x="-48" off_y="32" name="RefPos" id="o007.RefPos" type="range" min="0" max="3599" dynamic="all" frac="0"/>
    <output off_x="48" off_y="0" name="out" id="o007.out" type="range" min="0" max="3599" dynamic="none" frac="0">
      <expression>
        <operand type="sub-expression">
          <operand type="signal" idRef="Pos"/>
          <operator type="add"/>
          <operand type="signal" idRef="Speed"/>
          <operator type="mul"/>
          <operand type="signal" idRef="Delay_ms"/>
          <operator type="mul"/>
          <operand type="literal" value="3600"/>
          <operator type="div"/>
          <operand type="sub-expression">
            <operand type="literal" value="1000"/>
            <operator type="mul"/>
            <operand type="literal" value="60"/>
          </operand>
        </operand>
        <operator type="mod"/>
        <operand type="literal" value="3600"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="SyncPos"/>
          <operator type="and"/>
          <operand type="signal" idRef="Delay_ms"/>
          <operator type="more"/>
          <operand type="literal" value="0"/>
          <operator type="and"/>
          <operand type="signal" idRef="Delay_ms"/>
          <operator type="less"/>
          <operand type="literal" value="2000"/>
        </operand>
        <text>(Pos + Speed * Delay_ms * 3600 / (1000 * 60)) MOD 3600 WHEN (SyncPos AND Delay_ms &gt; 0 AND Delay_ms &lt; 2000)</text>
      </expression>
      <expression>
        <operand type="sub-expression">
          <operand type="signal" idRef="RefPos" delay="1"/>
          <operator type="add"/>
          <operand type="signal" idRef="Speed"/>
          <operator type="mul"/>
          <operand type="literal" value="3600"/>
          <operator type="div"/>
          <operand type="sub-expression">
            <operand type="literal" value="1000"/>
            <operator type="mul"/>
            <operand type="literal" value="60"/>
          </operand>
        </operand>
        <operator type="mod"/>
        <operand type="literal" value="3600"/>
        <text>(RefPos[-1] + Speed * 3600 / (1000 * 60)) MOD 3600 OTHERWISE</text>
      </expression>
    </output>
    <comment text="RPM to 1ms displ." off_x="0" off_y="20"/>
  </operation>
  <arc id="a008" type="read" source="SyncPos" target="o007.SyncPos"/>
  <arc id="a009" type="read" source="o002.out" target="o007.Delay_ms"/>
  <signal id="RefPos" x="815" y="275" mode="output" type="range" min="0" max="3599" frac="0" value="0" dynamic="none">
    <comment text="Units: 0.1deg." off_x="0" off_y="20"/>
  </signal>
  <arc id="a011" type="read" source="o007.out" target="RefPos"/>
  <arc id="a012" type="read" source="Pos" target="o007.Pos"/>
  <arc id="a013" type="read" source="Speed" target="o007.Speed"/>
  <arc id="a014" type="read" source="RefPos" target="o007.RefPos" view="symbolic"/>
  <arc id="a001" type="read" source="SyncPos" target="c1.Upd"/>
  <arc id="a002" type="read" source="c1.Sec" target="o002.Sec"/>
  <arc id="a003" type="read" source="c1.uSec" target="o002.uSec"/>
</net>
