<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://gres.uninova.pt/iopt-flow/show-pf.xsl" type="text/xsl" ?>
<net name="SpeedCtrl" type="iopt-flow">
  <signal id="RefInput" mode="input" type="range" x="90" y="320" min="0" max="1023" microstep="0" nano-step="0"/>
  <signal id="SpeedPosMode" mode="input" type="boolean" x="89" y="272" microstep="0" nano-step="0"/>
  <signal id="RefPos" mode="output" type="range" x="888" y="273" min="0" max="1023" microstep="0" nano-step="2"/>
  <operation id="SRefPosP6" x="673" y="223" size="30">
    <name text="RefPos" off_x="-30" off_y="-30"/>
    <input id="SRefPosP6.P6" name="P6" type="range" off_x="-30" off_y="-20"/>
    <input id="SRefPosP6.RefInput" name="RefInput" type="range" off_x="-30" off_y="5"/>
    <output id="SRefPosP6.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="1">
      <expression>
        <operand type="sub-expression">
          <operand type="signal" idRef="RefInput"/>
          <operator type="mul"/>
          <operand type="literal" value="16"/>
        </operand>
        <operator type="mod"/>
        <operand type="literal" value="1024"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P6"/>
        </operand>
        <text>(RefInput * 16) MOD 1024 WHEN (P6)</text>
      </expression>
      <expression>
        <operand type="literal" value="0"/>
        <operator type="otherwise"/>
        <text>0 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="S_RefPosP6" type="read" source="6" target="SRefPosP6.P6"/>
  <arc id="S_RefPosP_in1" type="read" source="RefInput" target="SRefPosP6.RefInput" view="symbolic"/>
  <operation id="SRefPosP8" x="672" y="324" size="30">
    <name text="RefPos" off_x="-30" off_y="-30"/>
    <input id="SRefPosP8.P8" name="P8" type="range" off_x="-30" off_y="-20"/>
    <input id="SRefPosP8.RefPos" name="RefPos" type="range" off_x="-30" off_y="-7.5"/>
    <input id="SRefPosP8.Speed" name="Speed" type="range" off_x="-30" off_y="5"/>
    <input id="SRefPosP8.Counter" name="Counter" type="range" off_x="-30" off_y="17.5"/>
    <output id="SRefPosP8.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="1">
      <expression>
        <operand type="sub-expression">
          <operand type="signal" idRef="RefPos" delay="1"/>
          <operator type="add"/>
          <operand type="signal" idRef="Speed" delay="1"/>
        </operand>
        <operator type="mod"/>
        <operand type="literal" value="1024"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P8"/>
          <operator type="and"/>
          <operand type="sub-expression">
            <operand type="signal" idRef="Counter" delay="1"/>
            <operator type="equal"/>
            <operand type="literal" value="0"/>
          </operand>
        </operand>
        <text>(RefPos[-1] + Speed[-1]) MOD 1024 WHEN (P8 AND (Counter[-1] = 0))</text>
      </expression>
      <expression>
        <operand type="signal" idRef="RefPos" delay="1"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P8"/>
          <operator type="and"/>
          <operand type="sub-expression">
            <operand type="signal" idRef="Counter" delay="1"/>
            <operator type="diff"/>
            <operand type="literal" value="0"/>
          </operand>
        </operand>
        <text>RefPos[-1] WHEN (P8 AND (Counter[-1] &lt;&gt; 0))</text>
      </expression>
      <expression>
        <operand type="literal" value="0"/>
        <operator type="otherwise"/>
        <text>0 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="S_RefPosP8" type="read" source="8" target="SRefPosP8.P8"/>
  <arc id="S_RefPosP_in1" type="read" source="RefPos" target="SRefPosP8.RefPos" view="symbolic"/>
  <arc id="S_RefPosP_in2" type="read" source="Speed" target="SRefPosP8.Speed" view="symbolic"/>
  <arc id="S_RefPosP_in3" type="read" source="Counter" target="SRefPosP8.Counter" view="symbolic"/>
  <operation id="max_RefPos" size="30" x="794" y="274">
    <name text="max(RefPos)" off_x="-30" off_y="-30"/>
    <input id="max_RefPos.P6" name="P6" type="range" off_x="-30" off_y="-8.333333333333332"/>
    <input id="max_RefPos.P8" name="P8" type="range" off_x="-30" off_y="8.333333333333336"/>
    <output id="max_RefPos.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="2">
      <expression>
        <operand type="signal" idRef="P6"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P6"/>
          <operator type="more-or-equal"/>
          <operand type="signal" idRef="P8"/>
        </operand>
        <text>P6 WHEN (P6 &gt;= P8)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="P8"/>
        <operator type="otherwise"/>
        <text>P8 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="max_RefPos_out" type="read" source="max_RefPos.out" target="RefPos"/>
  <arc id="max_RefPos_in1" type="read" source="SRefPosP6.out" target="max_RefPos.P6"/>
  <arc id="max_RefPos_in2" type="read" source="SRefPosP8.out" target="max_RefPos.P8"/>
  <signal id="Counter" mode="output" type="range" x="896" y="43" min="0" max="16" microstep="1" nano-step="1"/>
  <operation id="calc_Counter" x="890" y="120" size="40">
    <name text="Counter" off_x="-35" off_y="-40"/>
    <input id="calc_Counter.Counter" name="Counter" off_x="-40" off_y="-25" type="range"/>
    <input id="calc_Counter.CountEvt" name="CountEvt" off_x="-40" off_y="25" type="event"/>
    <output id="calc_Counter.out" name="out" off_x="40" off_y="0" type="range" microstep="1" nano-step="1">
      <expression>
        <operand type="signal" idRef="Counter" delay="1"/>
        <operator type="add"/>
        <operand type="literal" value="1"/>
        <operator type="when"/>
        <operand type="signal" idRef="CountEvt"/>
        <text>Counter[-1] + 1 WHEN (CountEvt)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="Counter" delay="1"/>
        <operator type="otherwise"/>
        <text>Counter[-1] OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="Counter_drv" type="read" source="calc_Counter.out" target="Counter"/>
  <arc id="Counter_out" type="read" target="calc_Counter.Counter" source="Counter"/>
  <arc id="calc_Counter_1" type="read" source="CountEvt" target="calc_Counter.CountEvt"/>
  <signal id="Speed" mode="output" type="range" x="737" y="58" min="-50" max="50" microstep="0" nano-step="1"/>
  <operation id="SSpeedP8" x="652" y="57" size="30">
    <name text="Speed" off_x="-30" off_y="-30"/>
    <input id="SSpeedP8.P8" name="P8" type="range" off_x="-30" off_y="-20"/>
    <input id="SSpeedP8.RefInput" name="RefInput" type="range" off_x="-30" off_y="5"/>
    <output id="SSpeedP8.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="1">
      <expression>
        <operand type="signal" idRef="RefInput"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P8"/>
          <operator type="and"/>
          <operand type="sub-expression">
            <operand type="signal" idRef="RefInput"/>
            <operator type="less"/>
            <operand type="literal" value="512"/>
          </operand>
        </operand>
        <text>RefInput WHEN (P8 AND (RefInput &lt; 512))</text>
      </expression>
      <expression>
        <operand type="signal" idRef="RefInput"/>
        <operator type="sub"/>
        <operand type="literal" value="1024"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P8"/>
          <operator type="and"/>
          <operand type="sub-expression">
            <operand type="signal" idRef="RefInput"/>
            <operator type="more-or-equal"/>
            <operand type="literal" value="512"/>
          </operand>
        </operand>
        <text>RefInput - 1024 WHEN (P8 AND (RefInput &gt;= 512))</text>
      </expression>
      <expression>
        <operand type="literal" value="1"/>
        <operator type="otherwise"/>
        <text>1 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="S_SpeedP8" type="read" source="8" target="SSpeedP8.P8"/>
  <arc id="S_SpeedP_in1" type="read" source="RefInput" target="SSpeedP8.RefInput" view="symbolic"/>
  <arc id="S_SpeedP8_out" type="read" source="SSpeedP8.out" target="Speed" view="xsymbolic"/>
  <signal id="ResetQEnc" mode="output" type="boolean" x="693" y="432" microstep="0" nano-step="2"/>
  <operation id="SResetQEncP7" x="487" y="382" size="30">
    <name text="ResetQEnc" off_x="-30" off_y="-30"/>
    <input id="SResetQEncP7.P7" name="P7" type="range" off_x="-30" off_y="-20"/>
    <input name="SPM" id="SResetQEncP7.SPM" type="boolean" min="0" max="1" frac="0" off_x="-30" off_y="15"/>
    <output id="SResetQEncP7.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="1">
      <expression>
        <operand type="signal" idRef="SPM"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P7"/>
        </operand>
        <text>SPM WHEN (P7)</text>
      </expression>
      <expression>
        <operand type="literal" value="0"/>
        <text>0</text>
      </expression>
    </output>
  </operation>
  <arc id="S_ResetQEncP7" type="read" source="7" target="SResetQEncP7.P7"/>
  <operation id="SResetQEncP9" x="487" y="482" size="30">
    <name text="ResetQEnc" off_x="-30" off_y="-30"/>
    <input id="SResetQEncP9.P9" name="P9" type="range" off_x="-30" off_y="-20"/>
    <output id="SResetQEncP9.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="1">
      <expression>
        <operand type="literal" value="1"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P9"/>
        </operand>
        <text>1 WHEN (P9)</text>
      </expression>
      <expression>
        <operand type="literal" value="0"/>
        <operator type="otherwise"/>
        <text>0 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="S_ResetQEncP9" type="read" source="9" target="SResetQEncP9.P9"/>
  <operation id="max_ResetQEnc" size="30" x="606" y="432">
    <name text="max(ResetQEnc)" off_x="-30" off_y="-30"/>
    <input id="max_ResetQEnc.P7" name="P7" type="range" off_x="-30" off_y="-8.333333333333332"/>
    <input id="max_ResetQEnc.P9" name="P9" type="range" off_x="-30" off_y="8.333333333333336"/>
    <output id="max_ResetQEnc.out" name="out" off_x="30" off_y="0" type="range" microstep="0" nano-step="2">
      <expression>
        <operand type="signal" idRef="P7"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="P7"/>
          <operator type="more-or-equal"/>
          <operand type="signal" idRef="P9"/>
        </operand>
        <text>P7 WHEN (P7 &gt;= P9)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="P9"/>
        <operator type="otherwise"/>
        <text>P9 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="max_ResetQEnc_out" type="read" source="max_ResetQEnc.out" target="ResetQEnc"/>
  <arc id="max_ResetQEnc_in1" type="read" source="SResetQEncP7.out" target="max_ResetQEnc.P7"/>
  <arc id="max_ResetQEnc_in2" type="read" source="SResetQEncP9.out" target="max_ResetQEnc.P9"/>
  <event id="CountEvt" mode="internal" x="803" y="148" microstep="1" nano-step="0"/>
  <arc id="CountEvt_in_evt" type="read" source="2" target="CountEvt" view="symbolic"/>
  <place id="6" x="147" y="144" init_marking="1">
    <name text="POS" off_x="32" off_y="-1"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="7" x="336" y="74" init_marking="0">
    <name text="ResetInput1" off_x="-25" off_y="-30"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="8" x="517" y="144" init_marking="0">
    <name text="Speed" off_x="-51" off_y="-3"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="9" x="336" y="214" init_marking="0">
    <name text="ResetInput2" off_x="-21" off_y="-28"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <transition id="2" x="607" y="144" priority="1" microstep="0">
    <name text="Count" off_x="-2" off_y="-19"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <transition id="10" x="226" y="74" priority="1" microstep="0">
    <name text="P2S1" off_x="2" off_y="-19"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <operation id="10_guard" size="25" x="100" y="70" rot="0">
    <name text="Guard" off_x="-20" off_y="-22"/>
    <input id="10_guard.SPM" name="SPM" type="range" off_x="-25" off_y="0" min="0" max="1" frac="0"/>
    <output id="10_guard.C" name="C" off_x="25" off_y="0" type="boolean" microstep="0" nano-step="1">
      <expression>
        <operand type="signal" idRef="SPM"/>
        <operator type="equal"/>
        <operand type="literal" value="1"/>
        <text>SPM = 1</text>
      </expression>
    </output>
  </operation>
  <arc id="10_gc" type="read" source="10_guard.C" target="10"/>
  <arc id="10_guard_in1" type="read" source="SpeedPosMode" target="10_guard.SPM" view="symbolic"/>
  <transition id="11" x="437" y="74" priority="1" microstep="0">
    <name text="P2S2" off_x="2" off_y="-17"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <transition id="12" x="437" y="214" priority="1" microstep="0">
    <name text="S2P1" off_x="2" off_y="-17"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <operation id="12_guard" size="25" x="374" y="147">
    <name text="Guard" off_x="-20" off_y="-22"/>
    <input id="12_guard.SMode" name="SMode" type="range" off_x="-25" off_y="0" min="0" max="1" frac="0"/>
    <output id="12_guard.C" name="C" off_x="25" off_y="0" type="boolean" microstep="0" nano-step="1">
      <expression>
        <operand type="signal" idRef="SMode"/>
        <operator type="equal"/>
        <operand type="literal" value="0"/>
        <text>SMode = 0</text>
      </expression>
    </output>
  </operation>
  <arc id="12_gc" type="read" source="12_guard.C" target="12"/>
  <arc id="12_guard_in1" type="read" source="SpeedPosMode" target="12_guard.SMode" view="symbolic"/>
  <transition id="13" x="226" y="214" priority="1" microstep="0">
    <name text="S2P2" off_x="3" off_y="21"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="14" source="6" target="10" type="normal"/>
  <arc id="15" source="10" target="7" type="normal"/>
  <arc id="16" source="7" target="11" type="normal"/>
  <arc id="17" source="11" target="8" type="normal"/>
  <arc id="18" source="8" target="12" type="normal"/>
  <arc id="19" source="12" target="9" type="normal"/>
  <arc id="20" source="9" target="13" type="normal"/>
  <arc id="21" source="13" target="6" type="normal"/>
  <arc id="a1" type="read" source="SpeedPosMode" target="SResetQEncP7.SPM"/>
  <arc id="a2" type="read" source="8" target="2"/>
</net>
