<?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: Problems with cosf() and sinf() in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125319#M192</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;No Watchdog/COP is running on this project. Instead I have a snippet of code in the main loop that blinks an LED at a set frequency, 1 Hz. But when I have the cosf() or sinf() functions, the LED blinks sporadically and eventually completely stops blinking, staying either on or off.&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 31 Jul 2006 18:54:13 GMT</pubDate>
    <dc:creator>thisisbrians</dc:creator>
    <dc:date>2006-07-31T18:54:13Z</dc:date>
    <item>
      <title>Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125317#M190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Using CodeWarrior IDE for HC(S)08 version 5.7.0, with processor expert plug-in. Code is in C and target is the Freescale MC908GP32. The problem is that whenever I try to use cosf() or sinf() (or sin() or cos() for that matter...) the microcontroller goes crazy (random pins going high and low) and eventually the main loop just stops running altogether. As soon as I remove the lines of code containing the trig functions everything else works fine. Anyone know what's up???&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#include "math.h"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;float theta=3.14159; //it doesn't matter what value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;float x;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for(;; ){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;x=sinf(theta); //or x=cosf(theta), once again it doesn't matter&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;P.S. It's urgent!!! This is for a school project due by October, see &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.geocities.com%2Fthisisbrians%2F" rel="nofollow" target="_blank"&gt;http://www.geocities.com/thisisbrians/&lt;/A&gt;&lt;SPAN&gt; for details.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 06:15:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125317#M190</guid>
      <dc:creator>thisisbrians</dc:creator>
      <dc:date>2006-07-31T06:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125318#M191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Watchdog (COP) on or off???&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 17:37:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125318#M191</guid>
      <dc:creator>UK_CF_FAE</dc:creator>
      <dc:date>2006-07-31T17:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125319#M192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;No Watchdog/COP is running on this project. Instead I have a snippet of code in the main loop that blinks an LED at a set frequency, 1 Hz. But when I have the cosf() or sinf() functions, the LED blinks sporadically and eventually completely stops blinking, staying either on or off.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 18:54:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125319#M192</guid>
      <dc:creator>thisisbrians</dc:creator>
      <dc:date>2006-07-31T18:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125320#M193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Can you do pure floating-point arithmetic operations without trouble? That should pin the problem down to either the FP math or the trig function calls. What libraries are you linking in?&lt;BR /&gt;&lt;BR /&gt;---Tom&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 19:48:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125320#M193</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2006-07-31T19:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125321#M194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;J2MEJediMaster wrote:&lt;BR /&gt;Can you do pure floating-point arithmetic operations without trouble? That should pin the problem down to either the FP math or the trig function calls. What libraries are you linking in?&lt;BR /&gt;&lt;BR /&gt;---Tom&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;This project is for a robot controller board, and I am running a PID controller in the software to control the motors using plenty of floating point arithmetic with no trouble at all. I am linking only the ansif.lib library. Also, I get no errors or warnings with the trig function calls, they just simply mess up the execution of the program.&lt;P&gt;Message Edited by thisisbrians on &lt;SPAN class="date_text"&gt;2006-07-31&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;08:26 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 20:25:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125321#M194</guid>
      <dc:creator>thisisbrians</dc:creator>
      <dc:date>2006-07-31T20:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125322#M195</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;OK, so it's a library problem. Go the CodeWarrior's lib directory and see what other libraries there are in that directory. Look for one with a 'b' or 'x' or 'l', like ansibf.lib, ansixl.lib, and similar. (Caveat, I'm basing this on a quick scan of my HC12 lib directory.) To reduce the memory footprint, some of the ansi libraries don't include the trigonometric functions. You need to link in a library that does. Of course, this doesn't explain why you wouldn't be getting linker errors.&lt;BR /&gt;&lt;BR /&gt;---Tom&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 21:11:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125322#M195</guid>
      <dc:creator>J2MEJediMaster</dc:creator>
      <dc:date>2006-07-31T21:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125323#M196</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Okay, I know that the library I'm linking in has the trig functions in it, because upon introducting another library to the project, the linker tells me that there are duplicate definitions for sin(), cos(), etc. And running the program produces the same results even with an entirely different library. I'm stumped...&lt;P&gt;Message Edited by thisisbrians on &lt;SPAN class="date_text"&gt;2006-07-31&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;09:40 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 21:39:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125323#M196</guid>
      <dc:creator>thisisbrians</dc:creator>
      <dc:date>2006-07-31T21:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125324#M197</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;I think there are two main reasons for such a failure.&lt;BR /&gt;One is the COP, it has already been ruled out.&lt;BR /&gt;The second one is the stack size. Try to increase the stack size in the prm file. Check if the values on the bottom area of the stack get overwritten.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Jul 2006 22:49:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125324#M197</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2006-07-31T22:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125325#M198</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;So, I went in and doubled the stack from 128 to 256 bytes, and it appears to be working fine as such. I have yet to test whether the trig functions are returning the correct values, but if I find later that they do I will submit another post to the thread. Thanks for the help!&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 00:21:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125325#M198</guid>
      <dc:creator>thisisbrians</dc:creator>
      <dc:date>2006-08-01T00:21:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125326#M199</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;It doesn't sound like a COP problem to me at all since the&amp;nbsp;flashing light goes crazy, then stops.&amp;nbsp; This seems like a stack issue.&amp;nbsp; That would explain the randomness, anyway.&amp;nbsp; The floating point operations that you're doing are probably using up the last bit of stack space and then one of the floating op functions is looking to the corrupted stack to find the return address and that sends the CPU executing 'code' from who-knows-where.&amp;nbsp; I think CW defaults to only 100 bytes of stack by default.&amp;nbsp; Try editing your *.prm file and change the line that says "STACKSIZE 0x100" to "STACKTOP 0x3FFF" and then edit the line that says "RAM&amp;nbsp;= READ_WRITE&amp;nbsp;0x2000 TO&amp;nbsp;0x3FFF" to "RAM = READ_WRITE&amp;nbsp;0x2000 TO&amp;nbsp;0x3FFE".&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 00:31:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125326#M199</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2006-08-01T00:31:09Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with cosf() and sinf()</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125327#M200</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Oops.&amp;nbsp; I posted too late.&amp;nbsp; :smileyhappy:&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 00:31:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/Problems-with-cosf-and-sinf/m-p/125327#M200</guid>
      <dc:creator>rhinoceroshead</dc:creator>
      <dc:date>2006-08-01T00:31:43Z</dc:date>
    </item>
  </channel>
</rss>

