<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re:  I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it  is a cycle of 50us . But the generated code assumed 220us ,  in Model-Based Design Toolbox (MBDT)</title>
    <link>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645202#M190</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you share the model?&lt;/P&gt;&lt;P&gt;From the generated code, i assume you are using some Simulink division blocks. As you know division is highly inefficient on embedded processor and usually ends up in compiler runtime function calls.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should look for ways&amp;nbsp;to minimize the divisions like:&lt;/P&gt;&lt;P&gt;#1: precompute the inverse of a1 and use multiplication instead&lt;/P&gt;&lt;P&gt;rtb_Divide_e = (real32_T)FOC_INTC_test1_z_B.SFunction &lt;SPAN style="color: #ff0000;"&gt;/ a1&lt;/SPAN&gt; * a2;&lt;/P&gt;&lt;P&gt;rtb_Sum = (real32_T)FOC_INTC_test1_z_B.SFunction_e&lt;SPAN style="color: #ff0000;"&gt; / a1&lt;/SPAN&gt; * a3 - a4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#2: use additional coefficients to pre-compute the constant multiplications/divisions&lt;/P&gt;&lt;P&gt;rtb_Fcn = (((real32_T)FOC_INTC_test1_z_B.SFunction_i / &lt;SPAN style="color: #ff0000;"&gt;a1 * a3&lt;/SPAN&gt; - a4) * a7 + rtb_Sum) * a5;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#3: try using shifting instead of divisions whenever is possible&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An additional question: does your application requires such fast control loop @50us ? Typically in FOC the inner loop (current control) can be executed at 100us while the outer loop (speed/position control) is usually executed at 1ms.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 08 Apr 2017 11:29:38 GMT</pubDate>
    <dc:creator>Daniel_Popa</dc:creator>
    <dc:date>2017-04-08T11:29:38Z</dc:date>
    <item>
      <title>I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it  is a cycle of 50us . But the generated code assumed 220us , i do</title>
      <link>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645200#M188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;nbsp;I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it &amp;nbsp;is a cycle of 50us . But the generated code assumed 220us , i do not know why assumed so long time . I hope this time is reduced to 40us. I am very confused. The following is the RTW generated code . The function is void FOC_INTC_test1_z_FOC_ISR(int_T controlPortIdx) in FOC_INTC_test1_z.c file. &amp;nbsp;Very thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #51626f; background-color: #ffffff; border: 0px; font-weight: bold;"&gt;Original Attachment has been moved to:&amp;nbsp;&lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-339916"&gt;FOC_INTC_test1_z.c.zip&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Apr 2017 11:38:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645200#M188</guid>
      <dc:creator>zqwaidy</dc:creator>
      <dc:date>2017-04-04T11:38:13Z</dc:date>
    </item>
    <item>
      <title>Re:  I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it  is a cycle of 50us . But the generated code assumed 220us ,</title>
      <link>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645201#M189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Did you enabled the Optimizations from Simulink/Configuration Parameters/Optimization ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Apr 2017 16:09:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645201#M189</guid>
      <dc:creator>Daniel_Popa</dc:creator>
      <dc:date>2017-04-04T16:09:47Z</dc:date>
    </item>
    <item>
      <title>Re:  I use Real Time workshop in simulink to generate code , and the generated code is about AC motor control , and Execute the code generated by this motor control code in the interrupt and it  is a cycle of 50us . But the generated code assumed 220us ,</title>
      <link>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645202#M190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you share the model?&lt;/P&gt;&lt;P&gt;From the generated code, i assume you are using some Simulink division blocks. As you know division is highly inefficient on embedded processor and usually ends up in compiler runtime function calls.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should look for ways&amp;nbsp;to minimize the divisions like:&lt;/P&gt;&lt;P&gt;#1: precompute the inverse of a1 and use multiplication instead&lt;/P&gt;&lt;P&gt;rtb_Divide_e = (real32_T)FOC_INTC_test1_z_B.SFunction &lt;SPAN style="color: #ff0000;"&gt;/ a1&lt;/SPAN&gt; * a2;&lt;/P&gt;&lt;P&gt;rtb_Sum = (real32_T)FOC_INTC_test1_z_B.SFunction_e&lt;SPAN style="color: #ff0000;"&gt; / a1&lt;/SPAN&gt; * a3 - a4;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#2: use additional coefficients to pre-compute the constant multiplications/divisions&lt;/P&gt;&lt;P&gt;rtb_Fcn = (((real32_T)FOC_INTC_test1_z_B.SFunction_i / &lt;SPAN style="color: #ff0000;"&gt;a1 * a3&lt;/SPAN&gt; - a4) * a7 + rtb_Sum) * a5;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#3: try using shifting instead of divisions whenever is possible&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An additional question: does your application requires such fast control loop @50us ? Typically in FOC the inner loop (current control) can be executed at 100us while the outer loop (speed/position control) is usually executed at 1ms.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Apr 2017 11:29:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Model-Based-Design-Toolbox-MBDT/I-use-Real-Time-workshop-in-simulink-to-generate-code-and-the/m-p/645202#M190</guid>
      <dc:creator>Daniel_Popa</dc:creator>
      <dc:date>2017-04-08T11:29:38Z</dc:date>
    </item>
  </channel>
</rss>

