<?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="30" y="191" min="0" max="1"/>
  <signal id="CH_B" mode="input" type="boolean" x="49" y="310" min="0" max="1"/>
  <operation id="calc-A_UP" x="117" y="161" 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>
        <text>in[-1] &lt;=  0 and in &gt; 0</text>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="less_or_equal"/>
        <operand type="literal" value="@level"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="more"/>
        <operand type="literal" value="@level"/>
      </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="187" y="162"/>
  <arc id="calc-A_UP-out" type="read" source="calc-A_UP.out" target="A_UP"/>
  <operation id="calc-A_DOWN" x="117" y="222" 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>
        <text>in[-1] &gt;=  0 and in &lt; 0</text>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="more_or_equal"/>
        <operand type="literal" value="@level"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="less"/>
        <operand type="literal" value="@level"/>
      </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="187" y="223"/>
  <arc id="calc-A_DOWN-out" type="read" source="calc-A_DOWN.out" target="A_DOWN"/>
  <operation id="calc-B_UP" x="117" y="283" 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>
        <text>in[-1] &lt;=  0 and in &gt; 0</text>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="less_or_equal"/>
        <operand type="literal" value="@level"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="more"/>
        <operand type="literal" value="@level"/>
      </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="186" y="283"/>
  <arc id="calc-B_UP-out" type="read" source="calc-B_UP.out" target="B_UP"/>
  <operation id="calc-B_DOWN" x="116" y="337" 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>
        <text>in[-1] &gt;=  0 and in &lt; 0</text>
        <operand type="signal" idRef="in" delay="1"/>
        <operator type="more_or_equal"/>
        <operand type="literal" value="@level"/>
        <operator type="and"/>
        <operand type="signal" idRef="in" delay="0"/>
        <operator type="less"/>
        <operand type="literal" value="@level"/>
      </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="183" y="338"/>
  <arc id="calc-B_DOWN-out" type="read" source="calc-B_DOWN.out" target="B_DOWN"/>
  <signal id="COUNTER" mode="output" type="range" x="1106" y="362" min="0" max="1023"/>
  <operation id="calc_COUNTER" x="1102" y="450" 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>
        <text>COUNTER[-1] + 1 WHEN (CNT_UP)</text>
        <operand type="signal" idRef="COUNTER" delay="1"/>
        <operator type="add"/>
        <operand type="literal" value="1"/>
        <operator type="when"/>
        <operand type="signal" idRef="CNT_UP"/>
      </expression>
      <expression>
        <text>COUNTER[-1] - 1 WHEN (CNT_DOWN)</text>
        <operand type="signal" idRef="COUNTER" delay="1"/>
        <operator type="sub"/>
        <operand type="literal" value="1"/>
        <operator type="when"/>
        <operand type="signal" idRef="CNT_DOWN"/>
      </expression>
      <expression>
        <text>COUNTER[-1] OTHERWISE </text>
        <operand type="signal" idRef="COUNTER" delay="1"/>
      </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="995" y="447"/>
  <operation id="CNT_UP_or" x="918" y="420" 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>
        <text>tr1 OR tr2 OR tr3 OR tr4</text>
        <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"/>
      </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="995" y="477"/>
  <operation id="CNT_DOWN_or" x="918" y="510" 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>
        <text>tr1 OR tr2 OR tr3 OR tr4</text>
        <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"/>
      </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>
  <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>
  <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>
  <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>
  <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>
