<?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: Passing floating point parameters issue in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1460195#M63124</link>
    <description>&lt;P&gt;In general Floating Point should be avoided, it is rarely needed in Embedded Code, you are seeing why with this code.&lt;/P&gt;&lt;P&gt;Comparison to zero has no guarantee of being true, see:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/19837576/comparing-floating-point-number-to-zero#19841844" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/19837576/comparing-floating-point-number-to-zero#19841844&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;and the referenced C++ FAQ entry.&lt;BR /&gt;&lt;BR /&gt;Also use 0.0 not 0, however it will not make a lot of difference due to the above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 May 2022 17:30:18 GMT</pubDate>
    <dc:creator>bobpaddock</dc:creator>
    <dc:date>2022-05-18T17:30:18Z</dc:date>
    <item>
      <title>Passing floating point parameters issue</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1456233#M63077</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am currently working on device K70FN1M0M15 with MQX OS.&lt;/P&gt;&lt;P&gt;FPU&amp;nbsp;: fpv4-sp-d16&lt;/P&gt;&lt;P&gt;I have a function which takes an enumerate and a float as parameters and the problem is that sometimes the function’s float parameter takes the value 0 instead of the given value.&lt;/P&gt;&lt;P&gt;Here is an example of the function call, then the source code of the function:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;MRTimer_SetValue(mTimerRefBracketAlarm1, 3.0);&lt;/LI-CODE&gt;&lt;LI-CODE lang="c"&gt;void MRTimer_SetValue(tTimersRef TimerRef, float setTimerValue)
{
       uint16_t *pDestValue = NULL;
       uint16_t rawValue = 0;
       test = setTimerValue;

       if(setTimerValue == 0)
             test++;

       if ((TimerRef &amp;gt;= MRTIMER_10MS_FIRSTREF) &amp;amp;&amp;amp; (TimerRef &amp;lt;= MRTIMER_10MS_LASTREF))
       {
             rawValue = (uint16_t) (setTimerValue * 100.0);
             pDestValue = &amp;amp;timers10ms[TimerRef - MRTIMER_10MS_FIRSTREF];
       }
       else if (TimerRef &amp;gt;= MRTIMER_100MS_FIRSTREF &amp;amp;&amp;amp; TimerRef &amp;lt;= MRTIMER_100MS_LASTREF)
       {
             rawValue = (uint16_t) (setTimerValue * 10.0);
             pDestValue = &amp;amp;timers100ms[TimerRef - MRTIMER_100MS_FIRSTREF];
       }
       else if (TimerRef &amp;gt;= MRTIMER_1000MS_FIRSTREF &amp;amp;&amp;amp; TimerRef &amp;lt;= MRTIMER_1000MS_LASTREF)
       {
             rawValue = (uint16_t) (setTimerValue * 1.0);
             pDestValue = &amp;amp;timers1000ms[TimerRef - MRTIMER_1000MS_FIRSTREF];
       }
       else
       {
             return;
       }

       if(rawValue &amp;gt;65530 || rawValue &amp;lt; 3 || pDestValue == NULL)
       {
             tmpdebug_ref = TimerRef;
             tmpdebug_valeur = rawValue;
             test++;
       }
       else
       {
             *pDestValue = rawValue;
       }
       return;

}&lt;/LI-CODE&gt;&lt;P&gt;As you can see, I give 3.0 as parameter but when the bug occurs «&amp;nbsp;setTimerValue&amp;nbsp;» in the function take the value 0 instead of 3.0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The call of the function uses this assembler code:&lt;/P&gt;&lt;P&gt;577&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MRTimer_SetValue(mTimerRefBracketAlarm2, 3);&lt;/P&gt;&lt;P&gt;0001fd08:&amp;nbsp;&amp;nbsp; ldr r3, [r7, #4]&lt;/P&gt;&lt;P&gt;0001fd0a:&amp;nbsp;&amp;nbsp; ldrh r3, [r3, #6]&lt;/P&gt;&lt;P&gt;0001fd0c:&amp;nbsp;&amp;nbsp; addw r3, r3, #287&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ; 0x11f&lt;/P&gt;&lt;P&gt;0001fd10:&amp;nbsp;&amp;nbsp; uxth r3, r3&lt;/P&gt;&lt;P&gt;0001fd12:&amp;nbsp;&amp;nbsp; mov r0, r3&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;0001fd14:&amp;nbsp;&amp;nbsp; vmov.f32 s0, #8&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;0001fd18:&amp;nbsp;&amp;nbsp; bl 0x2bae8 &amp;lt;MRTimer_SetValue&amp;gt;&lt;/P&gt;&lt;P&gt;In my opinion, the value of the parameter is stored in the register s0 (red line).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then when I enter in the function, I have this assembler code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MRTimer_SetValue:&lt;/P&gt;&lt;P&gt;0002bae8:&amp;nbsp;&amp;nbsp; push {r7, lr}&lt;/P&gt;&lt;P&gt;0002baea:&amp;nbsp;&amp;nbsp; sub sp, #16&lt;/P&gt;&lt;P&gt;0002baec:&amp;nbsp;&amp;nbsp; add r7, sp, #0&lt;/P&gt;&lt;P&gt;0002baee:&amp;nbsp;&amp;nbsp; mov r3, r0&lt;/P&gt;&lt;P&gt;0002baf0:&amp;nbsp;&amp;nbsp; vstr s0, [r7]&lt;/P&gt;&lt;P&gt;0002baf4:&amp;nbsp;&amp;nbsp; strh r3, [r7, #6]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The instruction” 0002baf0:&amp;nbsp;&amp;nbsp; vstr s0, [r7]” is supposed to store the content of an extension register(S0) to memory (address given by r7).&lt;/P&gt;&lt;P&gt;When the bug occurs, after this instruction the value in the memory is 0.&lt;/P&gt;&lt;P&gt;For your information, it’s not possible to watch S0 in KDS 3.0.&lt;/P&gt;&lt;P&gt;Do you have any clue about this odd behavior ?&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 08:24:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1456233#M63077</guid>
      <dc:creator>mattht42</dc:creator>
      <dc:date>2022-05-11T08:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Passing floating point parameters issue</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1459449#M63113</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I highly recommend you to switch to MCUXpresso IDE.&lt;/P&gt;
&lt;P&gt;About your problem, is this happening every time you run your code?&lt;/P&gt;
&lt;P&gt;Do you have problems with floating point numbers in general or is it just in this case in particular?&lt;/P&gt;
&lt;P&gt;Best regards, Daniel.&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2022 15:38:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1459449#M63113</guid>
      <dc:creator>DanielRuvalcaba</dc:creator>
      <dc:date>2022-05-17T15:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Passing floating point parameters issue</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1460195#M63124</link>
      <description>&lt;P&gt;In general Floating Point should be avoided, it is rarely needed in Embedded Code, you are seeing why with this code.&lt;/P&gt;&lt;P&gt;Comparison to zero has no guarantee of being true, see:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stackoverflow.com/questions/19837576/comparing-floating-point-number-to-zero#19841844" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/19837576/comparing-floating-point-number-to-zero#19841844&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;and the referenced C++ FAQ entry.&lt;BR /&gt;&lt;BR /&gt;Also use 0.0 not 0, however it will not make a lot of difference due to the above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2022 17:30:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1460195#M63124</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2022-05-18T17:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Passing floating point parameters issue</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1463309#M63157</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thanks for the answer, the problem occurs randomly when the code is running. I only noticed this problem with this function but I can imagine it can appear in other functions where I use float as parameter.&lt;/P&gt;&lt;P&gt;I'm on a travel work for 2 week, I will give you more information when i come back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 May 2022 14:21:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Passing-floating-point-parameters-issue/m-p/1463309#M63157</guid>
      <dc:creator>mattht42</dc:creator>
      <dc:date>2022-05-24T14:21:19Z</dc:date>
    </item>
  </channel>
</rss>

