<?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>8-bit MicrocontrollersのトピックRe: integer overflow - DEMOJM board using MC9S08JM60</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160978#M9727</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Schalasa, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What ADC mode are you using, 8- , 10- or 12-bit mode?&amp;nbsp; I think that you will need to post your ADC code.&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>Mon, 08 Nov 2010 12:21:11 GMT</pubDate>
    <dc:creator>bigmac</dc:creator>
    <dc:date>2010-11-08T12:21:11Z</dc:date>
    <item>
      <title>integer overflow - DEMOJM board using MC9S08JM60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160977#M9726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the DEMOJM Board with the 8 bit MC9S08JM60 processor mounted on it. I am using codewarrior version 6 for developing the application. I am facing a problem while performing a simple subtraction over a set of raw values read by the ADC channel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to declare the variables as signed int and I see that, if the difference between the raw values&amp;nbsp; is either 0 or -1, an overflow occurs and I get -256 or 255 randomly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am declaring the variables as signed integers. ( say signed int diff =0).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any other way i need to declare the variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the first time I am using Codewarrior and I am a beginner in Firmware developement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;schalasa&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Nov 2010 00:48:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160977#M9726</guid>
      <dc:creator>schalasa</dc:creator>
      <dc:date>2010-11-06T00:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: integer overflow - DEMOJM board using MC9S08JM60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160978#M9727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Schalasa, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What ADC mode are you using, 8- , 10- or 12-bit mode?&amp;nbsp; I think that you will need to post your ADC code.&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>Mon, 08 Nov 2010 12:21:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160978#M9727</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-11-08T12:21:11Z</dc:date>
    </item>
    <item>
      <title>Re: integer overflow - DEMOJM board using MC9S08JM60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160979#M9728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the reply. I am using the 10 bit mode for the ADC. Find below, the code for initializing ADC.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;ADCCFG = 0XF8;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;nbsp; low power, clk%2, long sample time, 10 bit, bus clock&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;ADCSC2 = 0X00;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // compare fn disabled&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;ADCSC1 =0X21;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // interrupt disabled, continuous conversion, channel 1&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;APCTL1 = 0X02;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // i/o pin 1 disabled&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;schalasa&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 08 Nov 2010 23:11:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160979#M9728</guid>
      <dc:creator>schalasa</dc:creator>
      <dc:date>2010-11-08T23:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: integer overflow - DEMOJM board using MC9S08JM60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160980#M9729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Schalasa,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I actually meant for you to post the code where the ADC result is being read and then processed - where the error is occurring.&amp;nbsp; You should also include the definition for each variable.&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>Tue, 09 Nov 2010 12:14:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160980#M9729</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-11-09T12:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: integer overflow - DEMOJM board using MC9S08JM60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160981#M9730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Mac,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought you wanted to take a look at the initialization &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here you go, a snippet of the ADC part. The two raw values are read by ADC channel 1 and ADC channel 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (flag == 0 ) {&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; adc1config ( ) ;&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; // fn to configure ADC channel 1&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (ADCSC1_COCO== 0) ;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rssi_r= ADCR;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;ADCSC1_COCO = 0; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;flag = flag +1;&lt;BR /&gt;&lt;BR /&gt;}&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;if ( flag == 1) {&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; adc2config ( );&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; // fn to configure ADC channel 2&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; while ( ADCSC1_COCO == 0);&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; rssi_l = ADCR; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&lt;BR /&gt;ADCSC1_COCO = 0;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; flag = 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;diff = rssi_l&amp;nbsp; - rssi_r;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;diff1 = ((diff/2) - 5 );&amp;nbsp; // offset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rssi_r, rssi_l, diff, diff1 are declared as signed ints.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when the diff1 is varying between 0 and -1, I see the overflow on the variable diff1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;schalasa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Nov 2010 05:23:18 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160981#M9730</guid>
      <dc:creator>schalasa</dc:creator>
      <dc:date>2010-11-10T05:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: integer overflow - DEMOJM board using MC9S08JM60</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160982#M9731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Schalasa,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are a number of operational issues that need to be sorted, and then see if your original problem still persists.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you are sequentially measuring two different channels, it is quite inappropriate to select continuous conversion mode.&amp;nbsp; The usual method would be to start the first conversion, and on its completion to start the second conversion.&amp;nbsp; Additionally, the APCTL1 setting appears to disable the GPIO pin for only one of the ADC channels.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some of the code you have included is quite unnecessary, for example explicitly&amp;nbsp;writing zero to the COCO bit.&amp;nbsp; The flag variable also does nothing.&amp;nbsp; You might need a flag to keep track of the current&amp;nbsp;channel&amp;nbsp;only if you were to use interrupts.&amp;nbsp; I arrived at the following simplified code snippet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;int rssi_r, rssi_l;int diff, diff1;ADCSC1 = 0x01;              // Start conversion ADC channel 1while (ADCSC1_COCO == 0) ;  // Wait for completionrssi_r = ADCR;ADCSC1 = 0x02;              // Start conversion ADC channel 2while (ADCSC1_COCO == 0);   // Wait for completionrssi_l = ADCR;     diff = rssi_l - rssi_r;diff1 = (diff/2) - 5;       // offset
&lt;/PRE&gt;&lt;P&gt;Did you previously get the correct signed result&amp;nbsp;within diff?&amp;nbsp; With the division by 2, I can see no reason why the diff1 calculation&amp;nbsp;should overflow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ADC initialisation might be modified to the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void ADC_init( void){   ADCCFG = 0xF8; // low power, long samp, 10 bit, bus clock/8   ADCSC2 = 0x00; // compare fn disabled   ADCSC1 = 0x1F; // ADC module disabled   APCTL1 = 0x06; // GPIO disabled channels 1 &amp;amp; 2}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;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>Thu, 29 Oct 2020 09:06:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/integer-overflow-DEMOJM-board-using-MC9S08JM60/m-p/160982#M9731</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2020-10-29T09:06:27Z</dc:date>
    </item>
  </channel>
</rss>

