<?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 sqrt causing lockup  (NOT a float/linker issue) in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sqrt-causing-lockup-NOT-a-float-linker-issue/m-p/211810#M18249</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been using sqrt for a while without any issue.&lt;/P&gt;&lt;P&gt;Added a loop to run this function many times to average many ADC samples.&lt;/P&gt;&lt;P&gt;It runs fine then on the 5th time locks up on the second STA here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;STA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kexp:1&lt;BR /&gt;PULA&lt;BR /&gt;ADC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #(D_EXPHI)&lt;BR /&gt;STA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kexp:0&lt;BR /&gt;; // { exp done }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;PRE&gt;void ADC(void) {&amp;nbsp; float Fresult;&amp;nbsp; float PFResult;&amp;nbsp; float Result_a;&amp;nbsp; float Result_b;&amp;nbsp; float temp;&amp;nbsp; float Result_c;&amp;nbsp;&amp;nbsp; /*&amp;nbsp; take 4 ADC readings: VOLT, CURR, FREQ and PF&amp;nbsp; */&amp;nbsp; Fresult = (float)FREQ;&amp;nbsp; PFResult = (float)PF;&amp;nbsp; Result_a = (VOLT*VOLT)/(CURR*CURR);&amp;nbsp; temp = sqrt(Fresult);&amp;nbsp; Result_b = PFResult/(temp*Fresult);&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; Result_c = Result_a*Result_b*4096;&amp;nbsp; adcval = (int)Result_c;&amp;nbsp; return;}//ADC&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hangs up on the "temp" variable. Only on the 5th time through this code.&lt;/P&gt;&lt;P&gt;The only difference is a counter goes from 4 to 5 for this cycle, but I don't see how that'd make a difference.&lt;/P&gt;&lt;P&gt;What's happening here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 10 Jul 2010 03:48:30 GMT</pubDate>
    <dc:creator>z537z</dc:creator>
    <dc:date>2010-07-10T03:48:30Z</dc:date>
    <item>
      <title>sqrt causing lockup  (NOT a float/linker issue)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sqrt-causing-lockup-NOT-a-float-linker-issue/m-p/211810#M18249</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been using sqrt for a while without any issue.&lt;/P&gt;&lt;P&gt;Added a loop to run this function many times to average many ADC samples.&lt;/P&gt;&lt;P&gt;It runs fine then on the 5th time locks up on the second STA here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;STA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kexp:1&lt;BR /&gt;PULA&lt;BR /&gt;ADC&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #(D_EXPHI)&lt;BR /&gt;STA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Kexp:0&lt;BR /&gt;; // { exp done }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is:&lt;/P&gt;&lt;PRE&gt;void ADC(void) {&amp;nbsp; float Fresult;&amp;nbsp; float PFResult;&amp;nbsp; float Result_a;&amp;nbsp; float Result_b;&amp;nbsp; float temp;&amp;nbsp; float Result_c;&amp;nbsp;&amp;nbsp; /*&amp;nbsp; take 4 ADC readings: VOLT, CURR, FREQ and PF&amp;nbsp; */&amp;nbsp; Fresult = (float)FREQ;&amp;nbsp; PFResult = (float)PF;&amp;nbsp; Result_a = (VOLT*VOLT)/(CURR*CURR);&amp;nbsp; temp = sqrt(Fresult);&amp;nbsp; Result_b = PFResult/(temp*Fresult);&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; Result_c = Result_a*Result_b*4096;&amp;nbsp; adcval = (int)Result_c;&amp;nbsp; return;}//ADC&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hangs up on the "temp" variable. Only on the 5th time through this code.&lt;/P&gt;&lt;P&gt;The only difference is a counter goes from 4 to 5 for this cycle, but I don't see how that'd make a difference.&lt;/P&gt;&lt;P&gt;What's happening here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Jul 2010 03:48:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sqrt-causing-lockup-NOT-a-float-linker-issue/m-p/211810#M18249</guid>
      <dc:creator>z537z</dc:creator>
      <dc:date>2010-07-10T03:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: sqrt causing lockup  (NOT a float/linker issue)</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/sqrt-causing-lockup-NOT-a-float-linker-issue/m-p/211811#M18250</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You do not say how the "hang" is evidenced, i.e. what happens to the program counter when this occurs.&amp;nbsp; If you are experiencing a reset, it may be possible that this is a COP reset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The square root process for a floating point number will likely be a lengthy process, and unless you are clearing the COP timer within each loop, it&amp;nbsp;may be&amp;nbsp;quite possible for COP timeout to occur after five iterations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Jul 2010 05:36:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/sqrt-causing-lockup-NOT-a-float-linker-issue/m-p/211811#M18250</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-07-10T05:36:21Z</dc:date>
    </item>
  </channel>
</rss>

