<?xml version="1.0" encoding="UTF-8"?>
<net name="PID" type="iopt-flow">
  <signal id="RefPos" x="60" y="230" mode="input" type="range" min="0" max="1023" frac="0" value="0" dynamic="none" io_pin="0" microstep="0" nano-step="0"/>
  <signal id="SensPos" x="60" y="285" mode="input" type="range" min="0" max="1023" frac="0" value="0" dynamic="none" io_pin="0" microstep="0" nano-step="0"/>
  <operation id="o4" x="135" y="260" rot="0" shape="arrow" size="24">
    <name off_x="-20" off_y="-25" text="sub"/>
    <input off_x="-24" off_y="-8" name="RefPos" id="o4.RefPos" type="range" min="0" max="1023" dynamic="all" frac="0"/>
    <input off_x="-24" off_y="8" name="SensPos" id="o4.SensPos" type="range" min="0" max="1023" dynamic="all" frac="0"/>
    <output off_x="24" off_y="0" name="out" id="o4.out" type="range" min="-1024" max="1023" dynamic="none" frac="0" microstep="0" nano-step="1">
      <expression>
        <operand type="signal" idRef="SensPos"/>
        <operator type="sub"/>
        <operand type="signal" idRef="RefPos"/>
        <text>SensPos - RefPos</text>
      </expression>
    </output>
  </operation>
  <operation id="o9" x="220" y="260" rot="0" shape="arrow" size="16">
    <name off_x="-20" off_y="-15" text="pos_err"/>
    <input off_x="-16" off_y="0" name="diff_pos" id="o9.diff_pos" type="range" min="-1024" max="1023" dynamic="all" frac="0"/>
    <output off_x="16" off_y="0" name="out" id="o9.out" type="range" min="-1024" max="1023" dynamic="none" frac="0" microstep="0" nano-step="2">
      <expression>
        <operand type="signal" idRef="diff_pos"/>
        <operator type="sub"/>
        <operand type="literal" value="1024"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="diff_pos"/>
          <operator type="more-or-equal"/>
          <operand type="literal" value="512"/>
        </operand>
        <text>diff_pos - 1024 WHEN (diff_pos &gt;= 512)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="diff_pos"/>
        <operator type="add"/>
        <operand type="literal" value="1024"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="diff_pos"/>
          <operator type="less-or-equal"/>
          <operand type="literal" value="-512"/>
        </operand>
        <text>diff_pos + 1024 WHEN (diff_pos &lt;= -512)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="diff_pos"/>
        <text>diff_pos OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="a10" type="read" source="o4.out" target="o9.diff_pos"/>
  <signal id="PosErr" x="305" y="260" mode="output" type="range" min="-512" max="511" frac="0" value="0" dynamic="none" io_pin="0" microstep="0" nano-step="2"/>
  <signal id="DiffErr" x="490" y="335" mode="internal" type="range" min="-1024" max="1023" frac="0" value="0" dynamic="type" microstep="0" nano-step="3"/>
  <operation id="o18" x="365" y="180" rot="0" shape="arrow" size="34">
    <name off_x="-7" off_y="-28" text="Int"/>
    <input off_x="-35" off_y="10" name="IntErr" id="o18.IntErr" type="range" min="-8192" max="8191" dynamic="all" frac="0"/>
    <input off_x="-35" off_y="25" name="PosErr" id="o18.PosErr" type="range" min="-512" max="511" dynamic="all" frac="0"/>
    <input name="Enable" id="o18.Enable" type="boolean" min="0" max="1" dynamic="all" off_x="-35" off_y="-5"/>
    <input name="UpdClk" id="o18.UpdClk" type="event" min="0" max="1" frac="0" dynamic="name" off_x="-35" off_y="-20"/>
    <output off_x="34" off_y="0" name="out" id="o18.out" type="range" min="-7000" max="7000" dynamic="none" frac="0" microstep="0" nano-step="3">
      <expression>
        <operand type="signal" idRef="IntErr" delay="1"/>
        <operator type="add"/>
        <operand type="signal" idRef="PosErr"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="UpdClk"/>
        </operand>
        <text>IntErr[-1] + PosErr WHEN (UpdClk)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="IntErr" delay="1"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="Enable"/>
        </operand>
        <text>IntErr[-1] WHEN (Enable)</text>
      </expression>
      <expression>
        <operand type="literal" value="0"/>
        <text>0 OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="a19" type="read" source="PosErr" target="o18.PosErr"/>
  <signal id="IntErr" x="485" y="180" mode="internal" type="range" min="-8192" max="8191" frac="0" value="0" dynamic="none" microstep="0" nano-step="3"/>
  <operation id="o25" x="565" y="170" rot="0" shape="arrow" size="24">
    <name off_x="-10" off_y="-20" text="mul_ki"/>
    <input off_x="-24" off_y="-8" name="Ki" id="o25.Ki" type="range" min="0" max="31" dynamic="all" frac="0"/>
    <input off_x="-24" off_y="8" name="IntErr" id="o25.IntErr" type="range" min="-8192" max="8191" dynamic="all" frac="0"/>
    <output off_x="24" off_y="0" name="out" id="o25.out" type="range" min="-65536" max="65535" dynamic="none" frac="0" microstep="0" nano-step="4">
      <expression>
        <operand type="sub-expression">
          <operand type="signal" idRef="Ki"/>
          <operator type="mul"/>
          <operand type="signal" idRef="IntErr"/>
        </operand>
        <operator type="div"/>
        <operand type="literal" value="4"/>
        <text>(Ki * IntErr) / 4</text>
      </expression>
    </output>
  </operation>
  <arc id="a26" type="read" source="IntErr" target="o25.IntErr"/>
  <signal id="Ki" x="55" y="100" mode="input" type="range" min="0" max="31" frac="0" value="0" dynamic="none" io_pin="0" microstep="0" nano-step="0"/>
  <arc id="a28" type="read" source="Ki" target="o25.Ki" view="symbolic"/>
  <operation id="o30" x="565" y="250" rot="0" shape="arrow" size="24">
    <name off_x="-20" off_y="-25" text="mul_kp"/>
    <input off_x="-24" off_y="-8" name="Kp" id="o30.Kp" type="range" min="0" max="127" dynamic="all" frac="0"/>
    <input off_x="-24" off_y="8" name="PosErr" id="o30.PosErr" type="range" min="-512" max="511" dynamic="all" frac="0"/>
    <output off_x="24" off_y="0" name="out" id="o30.out" type="range" min="-65536" max="65535" dynamic="none" frac="0" microstep="0" nano-step="3">
      <expression>
        <operand type="signal" idRef="Kp"/>
        <operator type="mul"/>
        <operand type="signal" idRef="PosErr"/>
        <text>Kp * PosErr</text>
      </expression>
    </output>
  </operation>
  <signal id="Kp" x="55" y="60" mode="input" type="range" min="0" max="127" frac="0" value="0" dynamic="none" io_pin="0" microstep="0" nano-step="0"/>
  <arc id="a32" type="read" source="Kp" target="o30.Kp" view="symbolic"/>
  <arc id="a33" type="read" source="PosErr" target="o30.PosErr"/>
  <signal id="Kd" x="55" y="145" mode="input" type="range" min="0" max="127" frac="0" value="0" dynamic="none" io_pin="0" microstep="0" nano-step="0"/>
  <operation id="o35" x="565" y="325" rot="0" shape="arrow" size="24">
    <name off_x="-15" off_y="-25" text="mul_kd"/>
    <input off_x="-24" off_y="-8" name="Kd" id="o35.Kd" type="range" min="0" max="127" dynamic="all" frac="0"/>
    <input off_x="-24" off_y="8" name="DiffErr" id="o35.DiffErr" type="range" min="-1024" max="1023" dynamic="all" frac="0"/>
    <output off_x="24" off_y="0" name="out" id="o35.out" type="range" min="-65536" max="65535" dynamic="none" frac="0" microstep="0" nano-step="4">
      <expression>
        <operand type="signal" idRef="Kd"/>
        <operator type="mul"/>
        <operand type="signal" idRef="DiffErr"/>
        <text>Kd * DiffErr</text>
      </expression>
    </output>
  </operation>
  <arc id="a36" type="read" source="Kd" target="o35.Kd" view="symbolic"/>
  <arc id="a37" type="read" source="DiffErr" target="o35.DiffErr"/>
  <operation id="o38" x="650" y="250" rot="0" shape="circle" size="22">
    <name off_x="-10" off_y="-27" text="add"/>
    <input off_x="0" off_y="-20" name="i" id="o38.i" type="range" min="-65536" max="65535" dynamic="type" frac="0"/>
    <input off_x="-22" off_y="0" name="p" id="o38.p" type="range" min="-65536" max="65535" dynamic="type" frac="0"/>
    <input off_x="0" off_y="21" name="d" id="o38.d" type="range" min="-65536" max="65535" dynamic="type" frac="0"/>
    <output off_x="22" off_y="0" name="out" id="o38.out" type="range" min="-65536" max="65535" dynamic="none" frac="0" microstep="0" nano-step="5">
      <expression>
        <text>i + p + d</text>
        <operand type="signal" idRef="i"/>
        <operator type="add"/>
        <operand type="signal" idRef="p"/>
        <operator type="add"/>
        <operand type="signal" idRef="d"/>
      </expression>
    </output>
  </operation>
  <arc id="a39" type="read" source="o30.out" target="o38.p"/>
  <operation id="o44" x="735" y="185" rot="0" shape="arrow" size="16">
    <name off_x="-20" off_y="-20" text="calc_dir"/>
    <input off_x="-16" off_y="0" name="s" id="o44.s" type="range" min="-65536" max="65535" dynamic="type" frac="0"/>
    <output off_x="16" off_y="0" name="out" id="o44.out" type="boolean" min="0" max="1" dynamic="type" frac="0" microstep="0" nano-step="6">
      <expression>
        <operand type="signal" idRef="s"/>
        <operator type="less-or-equal"/>
        <operand type="literal" value="0"/>
        <text>s &lt;= 0</text>
      </expression>
    </output>
  </operation>
  <signal id="Dir" x="875" y="185" mode="output" type="boolean" min="0" max="1" dynamic="type" frac="0" microstep="0" nano-step="6"/>
  <arc id="a47" type="read" source="o44.out" target="Dir"/>
  <operation id="o48" x="740" y="310" rot="0" shape="arrow" size="16">
    <name off_x="-10" off_y="-15" text="abs"/>
    <input off_x="-16" off_y="0" name="s" id="o48.s" type="range" min="-65536" max="65535" dynamic="type" frac="0"/>
    <output off_x="16" off_y="0" name="out" id="o48.out" type="range" min="0" max="65535" dynamic="none" frac="0" microstep="0" nano-step="6">
      <expression>
        <operand type="signal" idRef="s" sign="-1"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="s"/>
          <operator type="less"/>
          <operand type="literal" value="0"/>
        </operand>
        <text>-s WHEN (s &lt; 0)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="s"/>
        <text>s</text>
      </expression>
    </output>
  </operation>
  <operation id="o50" x="815" y="310" rot="0" shape="arrow" size="16">
    <name off_x="-5" off_y="-15" text="div"/>
    <input off_x="-16" off_y="0" name="s" id="o50.s" type="range" min="0" max="65535" dynamic="type" frac="0"/>
    <output off_x="16" off_y="0" name="out" id="o50.out" type="range" min="0" max="1024" dynamic="none" frac="0" microstep="0" nano-step="1">
      <expression>
        <operand type="signal" idRef="s" delay="1"/>
        <operator type="div"/>
        <operand type="literal" value="16"/>
        <text>s[-1] / 16</text>
      </expression>
    </output>
  </operation>
  <arc id="a51" type="read" source="o48.out" target="o50.s"/>
  <signal id="DC" x="875" y="310" mode="output" type="range" min="0" max="1000" dynamic="none" frac="0" value="0" io_pin="0" microstep="0" nano-step="1"/>
  <arc id="a53" type="read" source="o50.out" target="DC"/>
  <arc id="a54" type="read" source="IntErr" target="o18.IntErr" view="symbolic"/>
  <signal id="Enable" x="250" y="175" mode="input" type="boolean" min="0" max="1" microstep="0" nano-step="0"/>
  <arc id="a2" type="read" source="Enable" target="o18.Enable"/>
  <event id="UpdClk" x="205" y="160" mode="input" microstep="0" nano-step="0"/>
  <arc id="a3" type="read" source="UpdClk" target="o18.UpdClk"/>
  <arc id="a5" type="read" source="o9.out" target="PosErr"/>
  <arc id="a6" type="read" source="RefPos" target="o4.RefPos"/>
  <arc id="a7" type="read" source="SensPos" target="o4.SensPos"/>
  <arc id="a1" type="read" source="o38.out" target="o44.s"/>
  <arc id="a4" type="read" source="o38.out" target="o48.s"/>
  <arc id="a8" type="read" source="o35.out" target="o38.d"/>
  <arc id="a9" type="read" source="o25.out" target="o38.i"/>
  <arc id="a11" type="read" source="o18.out" target="IntErr"/>
  <operation id="o3" x="190" y="370" rot="0" shape="arrow" size="32">
    <name off_x="-27" off_y="-32" text="Delay"/>
    <input off_x="-32" off_y="-16" name="Clk" id="o3.Clk" type="event" min="0" max="1" frac="0"/>
    <input off_x="-32" off_y="0" name="Err" id="o3.Err" type="range" min="-512" max="511" dynamic="type" frac="0"/>
    <input off_x="-32" off_y="16" name="PrevErr" id="o3.PrevErr" type="range" min="-512" max="511" dynamic="type" frac="0"/>
    <output off_x="32" off_y="0" name="out" id="o3.out" type="range" min="-512" max="511" frac="0">
      <expression>
        <operand type="signal" idRef="Err" delay="1"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="Clk"/>
        </operand>
        <text>Err[-1] WHEN (Clk)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="PrevErr" delay="1"/>
        <text>PrevErr[-1] OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="a12" type="read" source="o3.out" target="o3.PrevErr" view="symbolic"/>
  <arc id="a13" type="read" source="UpdClk" target="o3.Clk" view="symbolic"/>
  <arc id="a14" type="read" source="PosErr" target="o3.Err" view="symbolic"/>
  <operation id="o21" x="325" y="370" rot="0" shape="arrow" size="32">
    <name off_x="-27" off_y="-32" text="Delay"/>
    <input off_x="-32" off_y="-16" name="Clk" id="o21.Clk" type="event" min="0" max="1" frac="0"/>
    <input off_x="-32" off_y="0" name="Err" id="o21.Err" type="range" min="-512" max="511" dynamic="type" frac="0"/>
    <input off_x="-32" off_y="16" name="PrevErr" id="o21.PrevErr" type="range" min="-512" max="511" dynamic="type" frac="0"/>
    <output off_x="32" off_y="0" name="out" id="o21.out" type="range" min="-512" max="511" frac="0">
      <expression>
        <operand type="signal" idRef="Err" delay="1"/>
        <operator type="when"/>
        <operand type="sub-expression">
          <operand type="signal" idRef="Clk"/>
        </operand>
        <text>Err[-1] WHEN (Clk)</text>
      </expression>
      <expression>
        <operand type="signal" idRef="PrevErr" delay="1"/>
        <text>PrevErr[-1] OTHERWISE</text>
      </expression>
    </output>
  </operation>
  <arc id="a22" type="read" source="o21.out" target="o21.PrevErr" view="symbolic"/>
  <arc id="a23" type="read" source="o3.out" target="o21.Err"/>
  <arc id="a24" type="read" source="UpdClk" target="o21.Clk" view="symbolic"/>
  <operation id="o26" x="425" y="335" rot="0" shape="arrow" size="24">
    <name off_x="-19" off_y="-24" text="diff"/>
    <input off_x="-24" off_y="-8" name="PosErr" id="o26.PosErr" type="range" min="-512" max="511" dynamic="all" frac="0"/>
    <input off_x="-24" off_y="8" name="PrevError" id="o26.PrevError" type="range" min="-512" max="511" dynamic="type" frac="0"/>
    <output off_x="24" off_y="0" name="out" id="o26.out" type="range" min="-1024" max="1023" dynamic="none" frac="0">
      <expression>
        <operand type="signal" idRef="PosErr"/>
        <operator type="sub"/>
        <operand type="signal" idRef="PrevError"/>
        <text>PosErr - PrevError</text>
      </expression>
    </output>
  </operation>
  <arc id="a27" type="read" source="PosErr" target="o26.PosErr"/>
  <arc id="a29" type="read" source="o21.out" target="o26.PrevError"/>
  <arc id="a30" type="read" source="o26.out" target="DiffErr"/>
  <signal id="xxx" x="815" y="420" mode="output" type="boolean" min="0" max="1" dynamic="type"/>
</net>
