<?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: HC08LB8 arithmetic operation</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139079#M5183</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello bigmac and rocco, thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;This is the complete code, in my last post i have put less code for simplify the question, but in this way the information it is not full, sorry. &lt;BR /&gt;&lt;BR /&gt;this is my code :&lt;BR /&gt;&lt;BR /&gt; volt_T1=ADR; // get ADR value&lt;BR /&gt; freq_khz =AUX_K/HRPPER; // freq_khz between [40,120]&lt;BR /&gt; &lt;BR /&gt; A_f = (((3 * freq_khz * freq_khz)/50)+(6 * freq_khz+8432));&lt;BR /&gt; &lt;BR /&gt; //(3 * freq_khz * freq_khz) do not causes overflow in A_f?&lt;BR /&gt;&lt;BR /&gt; B_f = (((9 * freq_khz * freq_khz)/10)+(2*freq_khz+12787))/10;&lt;BR /&gt;&lt;BR /&gt; // 9 * freq_khz*freq_khz causes overflow and a bad B_f value?&lt;BR /&gt; // what is the solution? unsigned long?&lt;BR /&gt;&lt;BR /&gt; volt_pk_T1_bin = (A_f * volt_T1 + B_f)/100;&lt;BR /&gt; &lt;BR /&gt; // A_f * volt_T1 also causes overflow &lt;BR /&gt;&lt;BR /&gt; Declaration of variables:&lt;BR /&gt; &lt;BR /&gt; tU16 volt_pk_T1_bin; typedef unsigned int tU16; &lt;BR /&gt; extern tU16 extern tU16 A_f;;&lt;BR /&gt; &lt;BR /&gt; tU16 A_f; typedef unsigned int tU16; extern tU16 A_f;&lt;BR /&gt; tU16 B_f; typedef unsigned int tU16; extern tU16 B_f;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt; //A_f, B_f, volt_pk_T1_bin are unsigned int global&lt;P&gt;Message Edited by rceit on &lt;SPAN class="date_text"&gt;2006-06-11&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;05:44 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 11 Jun 2006 17:35:58 GMT</pubDate>
    <dc:creator>rceit</dc:creator>
    <dc:date>2006-06-11T17:35:58Z</dc:date>
    <item>
      <title>HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139075#M5179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello, i am working with a HC08LB8, freq_khz is&amp;nbsp;a number&amp;nbsp;between&amp;nbsp;[40, 120], A_f, B_f are&amp;nbsp;16bit variables&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My code is:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; A_f = (((3 * freq_khz * freq_khz)/50)+6 * freq_khz+8432);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; B_f = (freq_khz * freq_khz)/10;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;the opertion:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&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; A_f = (((3 * freq_khz * freq_khz)/50)+6 *freq_khz+8432);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;return&amp;nbsp;a correct&amp;nbsp;result, but in the next line:&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&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; B_f = (freq_khz * freq_khz)/10;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;the result is not the right, i think that the problem is the CCR (Condition Code Register) but i do not know how make for have a correct result.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thanks you.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Jun 2006 21:04:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139075#M5179</guid>
      <dc:creator>rceit</dc:creator>
      <dc:date>2006-06-09T21:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139076#M5180</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, rceit:&lt;BR /&gt;&lt;BR /&gt;How is freq_khz defined? is it an 8-bit or 16-bit value?&lt;BR /&gt;&lt;BR /&gt;What do you get as an incorrect result, and for what value of freq_khz?&lt;BR /&gt;&lt;BR /&gt;Can you post the generated assembly code?&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Jun 2006 07:16:33 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139076#M5180</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-06-10T07:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139077#M5181</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello rceit,&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;A further issue may be that the variable &lt;FONT face="Courier New"&gt;A_f&lt;/FONT&gt; (and &lt;FONT face="Courier New"&gt;B_f)&lt;/FONT&gt; may need to be &lt;FONT face="Courier New"&gt;unsigned int&lt;/FONT&gt; for the first equation to work for all allowable values of &lt;FONT face="Courier New"&gt;freq_khz.&lt;/FONT&gt;&lt;FONT face="Arial"&gt;&amp;nbsp; This is because the partial calculation &lt;FONT face="Courier New"&gt;3*freq_khz*freq_khz&lt;/FONT&gt; may overflow&amp;nbsp;a&amp;nbsp;&lt;FONT face="Courier New"&gt;signed int&lt;/FONT&gt; value.&amp;nbsp; You don't specify what you are currently using.&lt;/FONT&gt;&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 Jun 2006 15:40:05 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139077#M5181</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-06-10T15:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139078#M5182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello rceit,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I have now actually tried out your equations in the simulator, and obtained the expected results for both A_f and B_f variables, with freq_khz firstly set for 40, and then for a value of 120.&amp;nbsp; I declared all three variables as &lt;FONT face="Courier New"&gt;unsigned int.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;The following results were obtained:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;freq_khz&amp;nbsp;&amp;nbsp; A_f&amp;nbsp;&amp;nbsp; B_f&lt;BR /&gt;&amp;nbsp;&amp;nbsp; 40&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8768&amp;nbsp;&amp;nbsp; 160&lt;BR /&gt;&amp;nbsp;&amp;nbsp;120&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;10016&amp;nbsp; 1440&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Jun 2006 21:48:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139078#M5182</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-06-10T21:48:03Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139079#M5183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hello bigmac and rocco, thanks for your reply.&lt;BR /&gt;&lt;BR /&gt;This is the complete code, in my last post i have put less code for simplify the question, but in this way the information it is not full, sorry. &lt;BR /&gt;&lt;BR /&gt;this is my code :&lt;BR /&gt;&lt;BR /&gt; volt_T1=ADR; // get ADR value&lt;BR /&gt; freq_khz =AUX_K/HRPPER; // freq_khz between [40,120]&lt;BR /&gt; &lt;BR /&gt; A_f = (((3 * freq_khz * freq_khz)/50)+(6 * freq_khz+8432));&lt;BR /&gt; &lt;BR /&gt; //(3 * freq_khz * freq_khz) do not causes overflow in A_f?&lt;BR /&gt;&lt;BR /&gt; B_f = (((9 * freq_khz * freq_khz)/10)+(2*freq_khz+12787))/10;&lt;BR /&gt;&lt;BR /&gt; // 9 * freq_khz*freq_khz causes overflow and a bad B_f value?&lt;BR /&gt; // what is the solution? unsigned long?&lt;BR /&gt;&lt;BR /&gt; volt_pk_T1_bin = (A_f * volt_T1 + B_f)/100;&lt;BR /&gt; &lt;BR /&gt; // A_f * volt_T1 also causes overflow &lt;BR /&gt;&lt;BR /&gt; Declaration of variables:&lt;BR /&gt; &lt;BR /&gt; tU16 volt_pk_T1_bin; typedef unsigned int tU16; &lt;BR /&gt; extern tU16 extern tU16 A_f;;&lt;BR /&gt; &lt;BR /&gt; tU16 A_f; typedef unsigned int tU16; extern tU16 A_f;&lt;BR /&gt; tU16 B_f; typedef unsigned int tU16; extern tU16 B_f;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt; //A_f, B_f, volt_pk_T1_bin are unsigned int global&lt;P&gt;Message Edited by rceit on &lt;SPAN class="date_text"&gt;2006-06-11&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;05:44 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Jun 2006 17:35:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139079#M5183</guid>
      <dc:creator>rceit</dc:creator>
      <dc:date>2006-06-11T17:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139080#M5184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Hi, Rceit:&lt;BR /&gt;&lt;BR /&gt;Yes, a number of terms in your equations exceed 65535 when the frequency is 120. So unsigned integers are not large enough.&lt;BR /&gt;&lt;BR /&gt;If you are doing this all in C, I would suggest using longs. It may not matter whether you use signed or unsigned, but in my math library signed is a tiny bit more efficient than unsigned. I don't know about your C, however. Longs will certainly be more efficient than switching to floats.&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jun 2006 04:07:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139080#M5184</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2006-06-12T04:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139081#M5185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;Hi rocco, my code is C. I have try with unsigned long but this not works.&lt;/DIV&gt;&lt;DIV&gt;In my Sources folder i have defined basic mathematical functions:&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;SPAN class="msg_source_code"&gt;&lt;SPAN class="text_smallest"&gt;Code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;PRE&gt;/*****************************************************************************    Intrinsic functions definition*****************************************************************************/SByte Add_8(SByte x, SByte y);            /* source sdkmath.asm */SByte Lim_8(SByte x, SByte limit);        /* source sdkmath.c   */SByte Neg_8(SByte x);                     /* source sdkmath.asm */SByte Shl_8(SByte x, UByte n);            /* source sdkmath.asm */SByte Sub_8(SByte x, SByte y);            /* source sdkmath.asm */SWord16 Add(SWord16 x, SWord16 y);        /* source sdkmath.asm */SWord16 Lim(SWord16 x, SWord16 limit);    /* source sdkmath.c   */SWord16 Neg(SWord16 x);                   /* source sdkmath.asm */SWord16 Shl(SWord16 x, UByte n);          /* source sdkmath.asm */SWord16 Sub(SWord16 x, SWord16 y);        /* source sdkmath.asm */UWord16 Umul_16x8 (UWord16 x, UByte y);   /* source sdkmath.c   */SWord16 Smul_16x8 (SWord16 x, UByte y);   /* source sdkmath.c   */SWord16 Smul_8(SByte x, UByte y);         /* source sdkmath.c   */SByte   Sdiv_8(SWord16 x, UByte y);       /* source sdkmath.asm */UByte   Udiv_16to8(UWord16 x, UWord16 y); /* source sdkmath.asm */&lt;/PRE&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;May be this the problem? the arithmetical operations works with this funtions? if this is correct i&amp;nbsp;can not make unsigned long opertions only the operations specified in the funtions list.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="1"&gt;(Alban formatted code)&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;Message Edited by Alban on &lt;SPAN class="date_text"&gt;2006-06-12&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:18 AM&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jun 2006 14:59:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139081#M5185</guid>
      <dc:creator>rceit</dc:creator>
      <dc:date>2006-06-12T14:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139082#M5186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;Hello rceit,&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT size="2"&gt;If you wish to stick with the use of unsigned int, you&amp;nbsp;might modify the second formula as follows -&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;B_f = ((((freq_khz*freq_khz)/10)*9)+(2*freq_khz+12787))/10;&lt;BR /&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Arial"&gt;&lt;BR /&gt;This will do the division before the multiplication, and prevent overflow.&amp;nbsp; There could be a slight loss of precision due to integer rounding errors, but since you are doing a final division by 10, this should not be apparent in the end result.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Arial"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Arial"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Arial"&gt;&lt;/FONT&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Jun 2006 19:07:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139082#M5186</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-06-12T19:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139083#M5187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hello Mac,&lt;/P&gt;&lt;P&gt;The problem of overflow is solved for&amp;nbsp; B_f, but it continues with :&lt;/P&gt;&lt;P&gt;volt_pk_T1_bin = (A_f * volt_T1 + B_f)/100;&lt;/P&gt;&lt;P&gt;and any change done an inaceptable loss of resolution. The problem will be the mathematical functions described in &lt;SPAN&gt;&lt;SPAN class="date_text"&gt;2006-06-12&lt;/SPAN&gt;&lt;SPAN class="time_text"&gt;02:59 &lt;FONT size="1"&gt;AM&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT size="2"&gt;&lt;FONT size="1"&gt;&lt;/FONT&gt;reply?&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jun 2006 14:54:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139083#M5187</guid>
      <dc:creator>rceit</dc:creator>
      <dc:date>2006-06-13T14:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139084#M5188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;&lt;FONT size="2"&gt;Hello rceit,&lt;/FONT&gt;&lt;/P&gt;&lt;BLOCKQUOTE dir="ltr"&gt;&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;FONT size="2"&gt;rceit wrote:&lt;BR /&gt;The problem of overflow is solved for&amp;nbsp; B_f, but it continues with :&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT size="2"&gt;volt_pk_T1_bin = (A_f * volt_T1 + B_f)/100;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;and any change done an inaceptable loss of resolution.&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT size="2"&gt;Why do you not use the CW library for integer mathematical functions where I assume long variables can be handled?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;You do not mention the range of values expected for &lt;FONT face="Courier New"&gt;volt_T1&lt;/FONT&gt; variable.&amp;nbsp; You imply that this is equal to an address - or should this be the contents of an address - but this is not clear.&amp;nbsp; According to my calculations the&amp;nbsp;range of&amp;nbsp;values for &lt;FONT face="Courier New"&gt;A_f&lt;/FONT&gt; is 8768 to 10016, and for &lt;FONT face="Courier New"&gt;B_f&lt;/FONT&gt; the range is 1430 to 2598.&amp;nbsp; You may want to divide each of these by 100 prior to multiplying the first term by the &lt;FONT face="Courier New"&gt;volt_T1&lt;/FONT&gt; value, with a maximum allowed value of about 655 when &lt;FONT face="Courier New"&gt;A_f&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;B_f&lt;/FONT&gt; have their maximum values.&amp;nbsp; So the formula might be re-arranged as follows:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;volt_pk_T1_bin = ((A_f + 50)/100 * volt_T1 + (B_f + 50)/100;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Note the rounding correction for the integer division process.&amp;nbsp; This is probably the best result &amp;nbsp;achievable with integer arithmetic on 16-bit values.&amp;nbsp; The rounding correction might also be applied to the calculation of &lt;FONT face="Courier New"&gt;A_f&lt;/FONT&gt; and &lt;FONT face="Courier New"&gt;B_f&lt;/FONT&gt; (assuming the formulae do not already do this).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regards,&lt;BR /&gt;Mac&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Jun 2006 21:57:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139084#M5188</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2006-06-13T21:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: HC08LB8 arithmetic operation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139085#M5189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;P&gt;Hello big,&lt;/P&gt;&lt;P&gt;Thanks for your help, finally i have solved the question:&lt;/P&gt;&lt;P&gt;volt_T1 is ADR value [0,255].&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;with A_f = 8768&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&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; volt_pk_T1_bin = (A_f * volt_T1 + B_f&amp;nbsp;)/ 100 = 22372&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;with A_f = 87,68&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&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; A_f = A_f/100 +A_f -(A_f/100)*100&lt;/P&gt;&lt;P&gt;&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;&lt;FONT size="2"&gt;volt_pk_T1_bin = 87 * volt_T1+ (68 * volt_T1 + 1430)/100 = 22372&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;ciao.&lt;/FONT&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Jun 2006 16:06:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/HC08LB8-arithmetic-operation/m-p/139085#M5189</guid>
      <dc:creator>rceit</dc:creator>
      <dc:date>2006-06-15T16:06:36Z</dc:date>
    </item>
  </channel>
</rss>

