<?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: C calculation Error in Classic/Legacy CodeWarrior</title>
    <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158308#M2522</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Without that cast, the compiler will use the int type to do all computations. With it, everything is done with longs. Basically ANSI always uses the types of the arguments of the operators, and as there were only ints involved, all computations are based on them. Well, the real rule is a bit more complex also caring about the signed vs unsigned types and more.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Nov 2007 14:49:35 GMT</pubDate>
    <dc:creator>CompilerGuru</dc:creator>
    <dc:date>2007-11-01T14:49:35Z</dc:date>
    <item>
      <title>C calculation Error</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158306#M2520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Using:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Codewarrior 8.1.1a build 7168 for the DSC56800/E&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;Target = 56F8323&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;USB Tap as debugger&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN style="font-size: 2;"&gt;I am having an interesting issue:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#define ONE_REV&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 200&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //1.8deg per Full Step = 200 Steps for 1 Rev#define HALF_STEP_MULTIPLY&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp; //Each Step = 1/2 Step#define NINE_EIGHTFIVE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 985&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //9.85typedef struct MOT_PARAM{ unsigned char&amp;nbsp; Mode;&amp;nbsp;&amp;nbsp; // CW, CCW, Shortest unsigned char&amp;nbsp; Step_Mode;&amp;nbsp; //Full, Half, etc.. unsigned char Port_Position; //Current Position 0=Home unsigned char Port_Total;&amp;nbsp; //Total Ports on the Valve unsigned int&amp;nbsp;&amp;nbsp;&amp;nbsp; GearRatio;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This is the Gear Ratio of the Motor unsigned int&amp;nbsp;&amp;nbsp;&amp;nbsp; Port_Deg;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // this is how many degree's between ports unsigned int QOffset;&amp;nbsp; //Quadrature Decoder Offset long&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TotalSteps;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Estimated number of steps for 1 revolution}mot_param;extern mot_param UA_Param;UA_Param.GearRatio = NINE_EIGHTFIVE;UA_Param.TotalSteps = (((UA_Param.GearRatio * ONE_REV) * HALF_STEP_MULTIPLY) / 100);&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;SPAN style="font-size: 2;"&gt;&lt;BR /&gt;When this calculation is complete UA_Param.TotalSteps = 7&lt;BR /&gt;&lt;BR /&gt;Should be 3940&lt;BR /&gt;&lt;BR /&gt;I must be doing something wrong but not sure what yet. Any ideas?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:03:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158306#M2520</guid>
      <dc:creator>v_dave</dc:creator>
      <dc:date>2020-10-29T09:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: C calculation Error</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158307#M2521</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;A separate "cast" operator is required, I think&lt;BR /&gt;&lt;BR /&gt;UA_Param.TotalSteps = (( (long) UA_Param.GearRatio * ONE_REV * HALF_STEP_MULTIPLY) / 100 );&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2007 20:12:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158307#M2521</guid>
      <dc:creator>Problem99</dc:creator>
      <dc:date>2007-10-31T20:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: C calculation Error</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158308#M2522</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Without that cast, the compiler will use the int type to do all computations. With it, everything is done with longs. Basically ANSI always uses the types of the arguments of the operators, and as there were only ints involved, all computations are based on them. Well, the real rule is a bit more complex also caring about the signed vs unsigned types and more.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2007 14:49:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158308#M2522</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2007-11-01T14:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: C calculation Error</title>
      <link>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158309#M2523</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I just wanted to follow-up with the solution in case someone else has this problem.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;The final result was to cast every variable:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;UA_Param.TotalSteps = (((long)UA_Param.GearRatio * (long)ONE_REV * (long)HALF_STEP_MULTIPLY) / 100);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Nov 2007 03:23:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Classic-Legacy-CodeWarrior/C-calculation-Error/m-p/158309#M2523</guid>
      <dc:creator>v_dave</dc:creator>
      <dc:date>2007-11-15T03:23:16Z</dc:date>
    </item>
  </channel>
</rss>

