<?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>S12 / MagniV MicrocontrollersのトピックLn(x) approximation routines? - 9S12X</title>
    <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207134#M8467</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to calculate dewpoint in a 9S12X processor, and need a way to approximate the natural log function.&amp;nbsp; I have used a simple polynomial approximation, -x - x^2/2 - x^3/3..., but it breaks down below a certain relative humidity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know of any methods or routines, preferrable in assembly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Added p/n to subject.&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by NLFSJ on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-08-18&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;10:07 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Aug 2009 03:51:28 GMT</pubDate>
    <dc:creator>Pinhead</dc:creator>
    <dc:date>2009-08-14T03:51:28Z</dc:date>
    <item>
      <title>Ln(x) approximation routines? - 9S12X</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207134#M8467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to calculate dewpoint in a 9S12X processor, and need a way to approximate the natural log function.&amp;nbsp; I have used a simple polynomial approximation, -x - x^2/2 - x^3/3..., but it breaks down below a certain relative humidity.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know of any methods or routines, preferrable in assembly?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Added p/n to subject.&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by NLFSJ on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-08-18&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;10:07 AM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Aug 2009 03:51:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207134#M8467</guid>
      <dc:creator>Pinhead</dc:creator>
      <dc:date>2009-08-14T03:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Ln(x) approximation routines?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207135#M8468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It depends on the size of your input. If it's 8 to 10 bits, the simplest way would be a look-up table.&lt;/P&gt;&lt;P&gt;If you have 512 bytes to spare, you could make a 256-word table from which an 8-bit ln(x) would&lt;/P&gt;&lt;P&gt;be available directly . Beyond that, an 8-bit table could still be used, but interpolation would be needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Composing the table would be an interesting hour's project with Excel or Basic&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Aug 2009 22:41:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207135#M8468</guid>
      <dc:creator>WadeH</dc:creator>
      <dc:date>2009-08-14T22:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Ln(x) approximation routines?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207136#M8469</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Chris, and welcome to the forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I assume that you require the natural log of the fractional relative humidity value.&amp;nbsp; The problem with using the Taylor series for ln(1-x) is that the series converges very slowly, and extremely slowly for low values of RH.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An alternative method may be to consider deriving the the base 2 log, and to then to use the identity:&lt;/P&gt;&lt;P&gt;ln(h) = ln(2) * log2(h) = 0.6931 * log2(h)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since 0 &amp;lt; h &amp;lt; 1, the log value will always be negative, so the sign may be ignored within the derivation (and the result then subtracted, rather than added).&amp;nbsp; The log result will have an integer part and&amp;nbsp; a fractional part.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By initially using a base of 2, the integer part may be very easily derived by counting the number of left shifts of the binary h value, until there are no leading zeros remaining.&amp;nbsp; After shifting has occurred, the value will be within the range 0.5 &amp;lt;= h &amp;lt; 1, and the fractional part of the result will be derived from this value.&amp;nbsp; With this limited range, it would seem that a table lookup and interpolate method may be appropriate.&amp;nbsp; The use of linear interpolation between the the table values should give good accuracy for quite a small table.&amp;nbsp; My understanding is that the HCS12 has table lookup and interpolation instructions available, to simplify this process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result obtained would then be multiplied by the binary fractional value equivalent to 0.6931 ($B172 for a 16-bit fraction).&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 15 Aug 2009 12:06:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207136#M8469</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-08-15T12:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Ln(x) approximation routines?</title>
      <link>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207137#M8470</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It appears that this is the simplest way to do the approximation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It comes down to approximating the term:&amp;nbsp; LN(RH/100)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to shift and figure out the integer value, I started with 100/RH.&amp;nbsp; I made a table where one column held the numbers (100/0.1 to 100/99.9).&amp;nbsp; For each value I logged the shift remainder of that value and the mantissa of the log base 2 of that value.&amp;nbsp; I then decided on a resolution that I thought was acceptable for the remainder (0.500, 0.510, ... 1.000)&amp;nbsp; and made a table of remainder vs. log base 2.&amp;nbsp; In the end the integer remainder gets added to the mantissa from the table. &amp;nbsp; So my table is only 50 values long, or 100 bytes, and the calculations are all very simple.&amp;nbsp; Even a lot of approximations for these functions can be kind of large to deal with in HC12 assembly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I could of course make a lookup table for 1000 rh values, but I am a bit freaked out about making such a large lookup table, so the marriage seems like the best option.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Aug 2009 00:29:43 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S12-MagniV-Microcontrollers/Ln-x-approximation-routines-9S12X/m-p/207137#M8470</guid>
      <dc:creator>Pinhead</dc:creator>
      <dc:date>2009-08-19T00:29:43Z</dc:date>
    </item>
  </channel>
</rss>

