<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://gres.uninova.pt/iopt-flow/show-pf.xsl" type="text/xsl" ?>
<net name="quad_encoder" type="iopt-flow">
  <signal id="CH_A" mode="input" type="boolean" x="34" y="146" min="0" max="1"/>
  <signal id="CH_B" mode="input" type="boolean" x="39" y="455" min="0" max="1"/>
  <operation id="calc-A_UP" x="115" y="120" size="15" locked="true">
    <name text="A_UP" off_x="-15" off_y="-15"/>
    <input id="calc-A_UP.in" name="in" off_x="-15" off_y="0"/>
    <output id="calc-A_UP.out" name="out" off_x="15" off_y="0" type="event">
      <expression>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="less-or-equal"/>
        <operand type="literal" value="0"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="more"/>
        <operand type="literal" value="0"/>
        <text>in[-1] &lt;= 0 AND in &gt; 0</text>
      </expression>
    </output>
  </operation>
  <arc id="calc-A_UP-in" type="read" source="CH_A" target="calc-A_UP.in"/>
  <event id="A_UP" mode="internal" x="183" y="121"/>
  <arc id="calc-A_UP-out" type="read" source="calc-A_UP.out" target="A_UP"/>
  <operation id="calc-A_DOWN" x="114" y="189" size="15" locked="true">
    <name text="A_DOWN" off_x="-15" off_y="-15"/>
    <input id="calc-A_DOWN.in" name="in" off_x="-15" off_y="0"/>
    <output id="calc-A_DOWN.out" name="out" off_x="15" off_y="0" type="event">
      <expression>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="more-or-equal"/>
        <operand type="literal" value="0"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="less"/>
        <operand type="literal" value="0"/>
        <text>in[-1] &gt;= 0 AND in &lt; 0</text>
      </expression>
    </output>
  </operation>
  <arc id="calc-A_DOWN-in" type="read" source="CH_A" target="calc-A_DOWN.in"/>
  <event id="A_DOWN" mode="internal" x="177" y="191"/>
  <arc id="calc-A_DOWN-out" type="read" source="calc-A_DOWN.out" target="A_DOWN"/>
  <operation id="calc-B_UP" x="125" y="415" size="15" locked="true">
    <name text="B_UP" off_x="-15" off_y="-15"/>
    <input id="calc-B_UP.in" name="in" off_x="-15" off_y="0"/>
    <output id="calc-B_UP.out" name="out" off_x="15" off_y="0" type="event">
      <expression>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="less-or-equal"/>
        <operand type="literal" value="0"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="more"/>
        <operand type="literal" value="0"/>
        <text>in[-1] &lt;= 0 AND in &gt; 0</text>
      </expression>
    </output>
  </operation>
  <arc id="calc-B_UP-in" type="read" source="CH_B" target="calc-B_UP.in"/>
  <event id="B_UP" mode="internal" x="198" y="415"/>
  <arc id="calc-B_UP-out" type="read" source="calc-B_UP.out" target="B_UP"/>
  <operation id="calc-B_DOWN" x="123" y="502" size="15" locked="true">
    <name text="B_DOWN" off_x="-15" off_y="-15"/>
    <input id="calc-B_DOWN.in" name="in" off_x="-15" off_y="0"/>
    <output id="calc-B_DOWN.out" name="out" off_x="15" off_y="0" type="event">
      <expression>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="more-or-equal"/>
        <operand type="literal" value="0"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="less"/>
        <operand type="literal" value="0"/>
        <text>in[-1] &gt;= 0 AND in &lt; 0</text>
      </expression>
    </output>
  </operation>
  <arc id="calc-B_DOWN-in" type="read" source="CH_B" target="calc-B_DOWN.in"/>
  <event id="B_DOWN" mode="internal" x="199" y="503"/>
  <arc id="calc-B_DOWN-out" type="read" source="calc-B_DOWN.out" target="B_DOWN"/>
  <signal id="COUNTER" mode="output" type="range" x="1056" y="269" min="0" max="1023"/>
  <operation id="calc_COUNTER" x="1056" y="349" 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.CNT_UP" name="CNT_UP" off_x="-40" off_y="0" type="event"/>
    <input id="calc_COUNTER.CNT_DOWN" name="CNT_DOWN" off_x="-40" off_y="25" type="event"/>
    <output id="calc_COUNTER.out" name="out" off_x="40" off_y="0" type="range">
      <expression>
        <operand type="signal" idRef="COUNTER" delay="1"/>
        <operator type="add"/>
        <operand type="literal" value="1"/>
        <operator type="when"/>
        <operand type="signal" idRef="CNT_UP"/>
        <text>COUNTER[-1] + 1 WHEN (CNT_UP)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="COUNTER" delay="1"/>
        <operator type="sub"/>
        <operand type="literal" value="1"/>
        <operator type="when"/>
        <operand type="signal" idRef="CNT_DOWN"/>
        <text>COUNTER[-1] - 1 WHEN (CNT_DOWN)</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="CNT_UP" target="calc_COUNTER.CNT_UP"/>
  <arc id="calc_COUNTER_2" type="read" source="CNT_DOWN" target="calc_COUNTER.CNT_DOWN"/>
  <event id="CNT_UP" mode="internal" x="958" y="319"/>
  <operation id="CNT_UP_or" x="872" y="320" size="30">
    <name text="OR" off_x="-10" off_y="4"/>
    <input id="CNT_UP_or.tr1" name="tr1" off_x="-30" off_y="-18" type="event"/>
    <input id="CNT_UP_or.tr2" name="tr2" off_x="-30" off_y="-6" type="event"/>
    <input id="CNT_UP_or.tr3" name="tr3" off_x="-30" off_y="6" type="event"/>
    <input id="CNT_UP_or.tr4" name="tr4" off_x="-30" off_y="18" type="event"/>
    <output id="CNT_UP_or.out" name="out" off_x="30" off_y="0" type="event">
      <expression>
        <operand type="signal" idRef="tr1"/>
        <operator type="or"/>
        <operand type="signal" idRef="tr2"/>
        <operator type="or"/>
        <operand type="signal" idRef="tr3"/>
        <operator type="or"/>
        <operand type="signal" idRef="tr4"/>
        <text>tr1 OR tr2 OR tr3 OR tr4</text>
      </expression>
    </output>
  </operation>
  <arc id="CNT_UP_in_1" type="read" source="6" target="CNT_UP_or.tr1" view="symbolic"/>
  <arc id="CNT_UP_in_2" type="read" source="8" target="CNT_UP_or.tr2" view="symbolic"/>
  <arc id="CNT_UP_in_3" type="read" source="10" target="CNT_UP_or.tr3" view="symbolic"/>
  <arc id="CNT_UP_in_4" type="read" source="12" target="CNT_UP_or.tr4" view="symbolic"/>
  <arc id="CNT_UP-in-evt" type="read" source="CNT_UP_or.out" target="CNT_UP"/>
  <event id="CNT_DOWN" mode="internal" x="961" y="403"/>
  <operation id="CNT_DOWN_or" x="870" y="405" size="30">
    <name text="OR" off_x="-10" off_y="4"/>
    <input id="CNT_DOWN_or.tr1" name="tr1" off_x="-30" off_y="-18" type="event"/>
    <input id="CNT_DOWN_or.tr2" name="tr2" off_x="-30" off_y="-6" type="event"/>
    <input id="CNT_DOWN_or.tr3" name="tr3" off_x="-30" off_y="6" type="event"/>
    <input id="CNT_DOWN_or.tr4" name="tr4" off_x="-30" off_y="18" type="event"/>
    <output id="CNT_DOWN_or.out" name="out" off_x="30" off_y="0" type="event">
      <expression>
        <operand type="signal" idRef="tr1"/>
        <operator type="or"/>
        <operand type="signal" idRef="tr2"/>
        <operator type="or"/>
        <operand type="signal" idRef="tr3"/>
        <operator type="or"/>
        <operand type="signal" idRef="tr4"/>
        <text>tr1 OR tr2 OR tr3 OR tr4</text>
      </expression>
    </output>
  </operation>
  <arc id="CNT_DOWN_in_1" type="read" source="7" target="CNT_DOWN_or.tr1" view="symbolic"/>
  <arc id="CNT_DOWN_in_2" type="read" source="9" target="CNT_DOWN_or.tr2" view="symbolic"/>
  <arc id="CNT_DOWN_in_3" type="read" source="11" target="CNT_DOWN_or.tr3" view="symbolic"/>
  <arc id="CNT_DOWN_in_4" type="read" source="13" target="CNT_DOWN_or.tr4" view="symbolic"/>
  <arc id="CNT_DOWN-in-evt" type="read" source="CNT_DOWN_or.out" target="CNT_DOWN"/>
  <place id="2" x="530" y="30" init_marking="0">
    <name text="A0B0" off_x="-45" off_y="-5"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="3" x="770" y="260" init_marking="0">
    <name text="A1B0" off_x="-42" off_y="-13"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="4" x="530" y="470" init_marking="0">
    <name text="A1B1" off_x="35" off_y="2"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="5" x="290" y="260" init_marking="0">
    <name text="A0B1" off_x="38" off_y="11"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <place id="30" x="530" y="260" init_marking="1">
    <name text="Init" off_x="17" off_y="27"/>
    <comment text="" off_x="-30" off_y="20"/>
  </place>
  <transition id="6" x="700" y="100" priority="1">
    <name text="TAup1" off_x="0" off_y="-20"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="6_ie_1" type="read" source="A_UP" target="6" view="symbolic"/>
  <transition id="7" x="650" y="140" priority="1">
    <name text="TAdn2" off_x="-15" off_y="21"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="7_ie_1" type="read" source="A_DOWN" target="7" view="symbolic"/>
  <transition id="8" x="690" y="400" priority="1">
    <name text="TBup1" off_x="-2" off_y="22"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="8_ie_1" type="read" source="B_UP" target="8" view="symbolic"/>
  <transition id="9" x="660" y="360" priority="1">
    <name text="TBdn2" off_x="-3" off_y="-23"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="9_ie_1" type="read" source="B_DOWN" target="9" view="symbolic"/>
  <transition id="10" x="360" y="400" priority="1">
    <name text="TAdn1" off_x="-3" off_y="22"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="10_ie_1" type="read" source="A_DOWN" target="10" view="symbolic"/>
  <transition id="11" x="410" y="370" priority="1">
    <name text="TAup2" off_x="8" off_y="-22"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="11_ie_1" type="read" source="A_UP" target="11" view="symbolic"/>
  <transition id="12" x="370" y="100" priority="1">
    <name text="TBdn1" off_x="-2" off_y="-20"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="12_ie_1" type="read" source="B_DOWN" target="12" view="symbolic"/>
  <transition id="13" x="410" y="150" priority="1">
    <name text="TBup2" off_x="3" off_y="24"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <arc id="13_ie_1" type="read" source="B_UP" target="13" view="symbolic"/>
  <transition id="31" x="530" y="160" priority="1">
    <name text="TIA0B0" off_x="21" off_y="-18"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <operation id="31_guard" size="25" x="479" y="96">
    <name text="Guard" off_x="-20" off_y="-22"/>
    <input id="31_guard.CH_A" name="CH_A" type="range" off_x="-25" off_y="-6.666666666666666"/>
    <input id="31_guard.CH_B" name="CH_B" type="range" off_x="-25" off_y="6.666666666666668"/>
    <output id="31_guard.C" name="C" off_x="25" off_y="0" type="boolean">
      <expression>
        <operand type="signal" idRef="CH_A"/>
        <operator type="equal"/>
        <operand type="literal" value="0"/>
        <operator type="and"/>
        <operand type="signal" idRef="CH_B"/>
        <operator type="equal"/>
        <operand type="literal" value="0"/>
        <text>CH_A = 0 AND CH_B = 0</text>
      </expression>
    </output>
  </operation>
  <arc id="31_gc" type="read" source="31_guard.C" target="31"/>
  <arc id="31_guard_in1" type="read" source="CH_A" target="31_guard.CH_A" view="symbolic"/>
  <arc id="31_guard_in2" type="read" source="CH_B" target="31_guard.CH_B" view="symbolic"/>
  <transition id="32" x="640" y="260" priority="1">
    <name text="TIA1B0" off_x="-6" off_y="-20"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <operation id="32_guard" size="25" x="614" y="196">
    <name text="Guard" off_x="-20" off_y="-22"/>
    <input id="32_guard.CH_A" name="CH_A" type="range" off_x="-25" off_y="-6.666666666666666"/>
    <input id="32_guard.CH_B" name="CH_B" type="range" off_x="-25" off_y="6.666666666666668"/>
    <output id="32_guard.C" name="C" off_x="25" off_y="0" type="boolean">
      <expression>
        <operand type="signal" idRef="CH_A"/>
        <operator type="equal"/>
        <operand type="literal" value="1"/>
        <operator type="and"/>
        <operand type="signal" idRef="CH_B"/>
        <operator type="equal"/>
        <operand type="literal" value="0"/>
        <text>CH_A = 1 AND CH_B = 0</text>
      </expression>
    </output>
  </operation>
  <arc id="32_gc" type="read" source="32_guard.C" target="32"/>
  <arc id="32_guard_in1" type="read" source="CH_A" target="32_guard.CH_A" view="symbolic"/>
  <arc id="32_guard_in2" type="read" source="CH_B" target="32_guard.CH_B" view="symbolic"/>
  <transition id="33" x="420" y="260" priority="1">
    <name text="TIA0B1" off_x="-6" off_y="-19"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <operation id="33_guard" size="25" x="366" y="202">
    <name text="Guard" off_x="-20" off_y="-22"/>
    <input id="33_guard.CH_A" name="CH_A" type="range" off_x="-25" off_y="-6.666666666666666"/>
    <input id="33_guard.CH_B" name="CH_B" type="range" off_x="-25" off_y="6.666666666666668"/>
    <output id="33_guard.C" name="C" off_x="25" off_y="0" type="boolean">
      <expression>
        <operand type="signal" idRef="CH_A"/>
        <operator type="equal"/>
        <operand type="literal" value="0"/>
        <operator type="and"/>
        <operand type="signal" idRef="CH_B"/>
        <operator type="equal"/>
        <operand type="literal" value="1"/>
        <text>CH_A = 0 AND CH_B = 1</text>
      </expression>
    </output>
  </operation>
  <arc id="33_gc" type="read" source="33_guard.C" target="33"/>
  <arc id="33_guard_in1" type="read" source="CH_A" target="33_guard.CH_A" view="symbolic"/>
  <arc id="33_guard_in2" type="read" source="CH_B" target="33_guard.CH_B" view="symbolic"/>
  <transition id="34" x="530" y="360" priority="1">
    <name text="TIA1B1" off_x="-38" off_y="-19"/>
    <comment text="" off_x="-30" off_y="20"/>
  </transition>
  <operation id="34_guard" size="25" x="466" y="315">
    <name text="Guard" off_x="-20" off_y="-22"/>
    <input id="34_guard.CH_A" name="CH_A" type="range" off_x="-25" off_y="-6.666666666666666"/>
    <input id="34_guard.CH_B" name="CH_B" type="range" off_x="-25" off_y="6.666666666666668"/>
    <output id="34_guard.C" name="C" off_x="25" off_y="0" type="boolean">
      <expression>
        <operand type="signal" idRef="CH_A"/>
        <operator type="equal"/>
        <operand type="literal" value="1"/>
        <operator type="and"/>
        <operand type="signal" idRef="CH_B"/>
        <operator type="equal"/>
        <operand type="literal" value="1"/>
        <text>CH_A = 1 AND CH_B = 1</text>
      </expression>
    </output>
  </operation>
  <arc id="34_gc" type="read" source="34_guard.C" target="34"/>
  <arc id="34_guard_in1" type="read" source="CH_A" target="34_guard.CH_A" view="symbolic"/>
  <arc id="34_guard_in2" type="read" source="CH_B" target="34_guard.CH_B" view="symbolic"/>
  <arc id="14" source="2" target="6" type="normal"/>
  <arc id="15" source="6" target="3" type="normal"/>
  <arc id="16" source="3" target="8" type="normal"/>
  <arc id="17" source="8" target="4" type="normal"/>
  <arc id="18" source="4" target="10" type="normal"/>
  <arc id="19" source="10" target="5" type="normal"/>
  <arc id="20" source="5" target="12" type="normal"/>
  <arc id="21" source="12" target="2" type="normal"/>
  <arc id="22" source="2" target="13" type="normal"/>
  <arc id="23" source="13" target="5" type="normal"/>
  <arc id="24" source="5" target="11" type="normal"/>
  <arc id="25" source="11" target="4" type="normal"/>
  <arc id="26" source="4" target="9" type="normal"/>
  <arc id="27" source="9" target="3" type="normal"/>
  <arc id="28" source="3" target="7" type="normal"/>
  <arc id="29" source="7" target="2" type="normal"/>
  <arc id="35" source="30" target="31" type="normal"/>
  <arc id="36" source="31" target="2" type="normal"/>
  <arc id="37" source="30" target="32" type="normal"/>
  <arc id="38" source="32" target="3" type="normal"/>
  <arc id="39" source="30" target="34" type="normal"/>
  <arc id="40" source="34" target="4" type="normal"/>
  <arc id="41" source="30" target="33" type="normal"/>
  <arc id="42" source="33" target="5" type="normal"/>
</net>
