<?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 DEMO9S08QG8 weird problem in debug???!!! in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125178#M517</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using DEMO9S08QG8 for a project, however, this is the first time I use freescale. When I use the codewarrior to debug the firmware, I have a weird problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below it is the code, the declare of varaibles are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int DL = 10, L = 10; // L and DL are constant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int DL2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int dataX[10];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, in the firmware, I need calculate some variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DL2 = DL / 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = 0, D_Y = 0, D_Z = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (i = L-1; i&amp;gt;=L - DL2; i--){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = D_X + (dataX[i]-dataX[(int)(L-DL2)]) * (dataX[i]-dataX[(int)(L-DL2)]); //*****&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i loops from 9 to 5, when i=9, everything seems ok. but when i=8, suddenly, DL2 changed value to 0. DL2 is a constant although it is declared as 'int' only. It is not used in any other places in the firmware. Because of this, the calculation is wrong. dataX's value is small, 0 or 1, so, it is not overflow problem&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I changed the code to :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DL2 = DL / 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = 0, D_Y = 0, D_Z = L - DL2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (i = L-1; i&amp;gt;=D_Z; i--){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_Y = dataX[i]-dataX[(int)(L-DL2)];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_Y = D_Y * D_Y;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = D_X + D_Y;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then seems ok, DL2's value doesn't change. But I'm worrying about something else changed but I didn't notice. So, what can cause this problem? How to fix this? Anyone has any ideas? Really need some help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;urlreader&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 Mar 2007 08:26:47 GMT</pubDate>
    <dc:creator>urlreader</dc:creator>
    <dc:date>2007-03-06T08:26:47Z</dc:date>
    <item>
      <title>DEMO9S08QG8 weird problem in debug???!!!</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125178#M517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using DEMO9S08QG8 for a project, however, this is the first time I use freescale. When I use the codewarrior to debug the firmware, I have a weird problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Below it is the code, the declare of varaibles are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int DL = 10, L = 10; // L and DL are constant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int DL2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;int dataX[10];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then, in the firmware, I need calculate some variables:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DL2 = DL / 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = 0, D_Y = 0, D_Z = 0;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (i = L-1; i&amp;gt;=L - DL2; i--){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = D_X + (dataX[i]-dataX[(int)(L-DL2)]) * (dataX[i]-dataX[(int)(L-DL2)]); //*****&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i loops from 9 to 5, when i=9, everything seems ok. but when i=8, suddenly, DL2 changed value to 0. DL2 is a constant although it is declared as 'int' only. It is not used in any other places in the firmware. Because of this, the calculation is wrong. dataX's value is small, 0 or 1, so, it is not overflow problem&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I changed the code to :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DL2 = DL / 2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = 0, D_Y = 0, D_Z = L - DL2;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for (i = L-1; i&amp;gt;=D_Z; i--){&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_Y = dataX[i]-dataX[(int)(L-DL2)];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_Y = D_Y * D_Y;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;D_X = D_X + D_Y;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;================================&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then seems ok, DL2's value doesn't change. But I'm worrying about something else changed but I didn't notice. So, what can cause this problem? How to fix this? Anyone has any ideas? Really need some help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;urlreader&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Mar 2007 08:26:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125178#M517</guid>
      <dc:creator>urlreader</dc:creator>
      <dc:date>2007-03-06T08:26:47Z</dc:date>
    </item>
    <item>
      <title>Re: DEMO9S08QG8 weird problem in debug???!!!</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125179#M518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;variables changing suddenly are often stack overflow problems, I would watch how close the SP gets to your DL2 variable.&lt;BR /&gt;Try to increase the STACK_SIZE in the prm file.&lt;BR /&gt;&lt;BR /&gt;In general I would use more unsigned char's and not int's for the 8 bit HCS08 CPU if all the possible values fit.&lt;BR /&gt;&lt;BR /&gt;Daniel&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Mar 2007 19:37:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125179#M518</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2007-03-06T19:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: DEMO9S08QG8 weird problem in debug???!!!</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125180#M519</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;thanks. I changed stacksize, and it seems ok now.&lt;BR /&gt;&lt;BR /&gt;in my firmware, I need collect data from sensors, and then do some calculation. some of the calculations have to be float. what value is reasonable for the stacksize? Or I can set it as high as I want? any other suggestions?&lt;BR /&gt;&lt;BR /&gt;I never used freescale and codewarrior before.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;thanks&lt;BR /&gt;&lt;BR /&gt;urlreader&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Mar 2007 04:47:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125180#M519</guid>
      <dc:creator>urlreader</dc:creator>
      <dc:date>2007-03-08T04:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: DEMO9S08QG8 weird problem in debug???!!!</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125181#M520</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello urlreader,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;With the QG8 device, the maximum RAM available is only 512 bytes. This must be apportioned to both&amp;nbsp;the global and static variables used by the program, and to the stack.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;However,&amp;nbsp;the CW debugger does not give any warning should overflow of the allocated stack size occur during operation of the program.&amp;nbsp; So you will need to conduct some tests (during simulation) to positively determine the lower boundary of stack usage by your program, and then make sure there is some additional margin allowed.&amp;nbsp; This margin will perhaps allow for the servicing of additional&amp;nbsp;interrupts that were not previously&amp;nbsp;simulated, and for&amp;nbsp;subsequent alterations to the program.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Make sure the globals are allocated, starting from the lowest RAM address (within zero page), and ensure that the stack commences at the highest RAM address.&amp;nbsp; This will maximize the available&amp;nbsp;stack size.&amp;nbsp; This may require some experimentation with the PRM file settings.&amp;nbsp; Also minimize the number of different RAM sections used by your code.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;These precautions can potentially be relaxed for MCUs with substantially more RAM available.&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Regards,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Mac&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Mar 2007 20:51:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/DEMO9S08QG8-weird-problem-in-debug/m-p/125181#M520</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2007-03-10T20:51:39Z</dc:date>
    </item>
  </channel>
</rss>

