<?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: ADC interpretation in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287845#M20437</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look up table should be the fastest and the best, provided you have space for it.&lt;/P&gt;&lt;P&gt;But the speed of LCD display routine is usually not important. You may lower refresh frequency, you may use preemptive RTOS, etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 30 Apr 2013 21:06:17 GMT</pubDate>
    <dc:creator>kef</dc:creator>
    <dc:date>2013-04-30T21:06:17Z</dc:date>
    <item>
      <title>ADC interpretation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287841#M20433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please help&lt;/P&gt;&lt;P&gt;this shouldnt be a difficult question to answer and it gets freaking frustrating to have 40 views and no response of anykind&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i'm trying to use the adc, lets forget about EMI and coupling for the time being&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;assume this&lt;/P&gt;&lt;P&gt;ADC 0 = 0V&lt;/P&gt;&lt;P&gt;ADC 255 = 650V&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i get a 237 from the ADC&lt;/P&gt;&lt;P&gt;the voltage should be 237*650/255=604&lt;/P&gt;&lt;P&gt;at least that's what i want...&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but it doesn't works, i assume its due type&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i do this&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned char ADCmeasure;&lt;/P&gt;&lt;P&gt;unsigned int Voltage;&lt;/P&gt;&lt;P&gt;ADC1_Measure(1);&lt;/P&gt;&lt;P&gt;ADC1_GetValue8(ADCReadBuffer);&lt;/P&gt;&lt;P&gt;ADCm=ADCReadBuffer[0];&lt;/P&gt;&lt;P&gt;Voltage=(int)ADCm*650/255;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it compiles but is not correct&lt;/P&gt;&lt;P&gt;i think because ADCmeasure*650 might not fit on a int&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i do this&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned int ADCm;&lt;/P&gt;&lt;P&gt;long Voltage;&lt;/P&gt;&lt;P&gt;ADC1_Measure(1); //measure&lt;/P&gt;&lt;P&gt;ADC1_GetValue8(ADCReadBuffer); //record&lt;/P&gt;&lt;P&gt;ADCm=(int)ADCReadBuffer[0]; //get first number and cast it to int&lt;/P&gt;&lt;P&gt;Voltage=ADCm*2.54902; //interpret it&lt;/P&gt;&lt;P&gt;ADCm=Voltage; //truncate it&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it breaks saying&lt;/P&gt;&lt;P&gt;_DMUL_RC, _DSTRUNC, _DUFLOAT are not defined&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if i do this&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;unsigned int ADCm;&lt;/P&gt;&lt;P&gt;long Voltage;&lt;/P&gt;&lt;P&gt;ADC1_Measure(1); //measure&lt;/P&gt;&lt;P&gt;ADC1_GetValue8(ADCReadBuffer); //record&lt;/P&gt;&lt;P&gt;ADCm=(int)ADCReadBuffer[0]; //get first number and cast it to int&lt;/P&gt;&lt;P&gt;Voltage=ADCm*650/255; //interpret it&lt;/P&gt;&lt;P&gt;ADCm=Voltage; //truncate it&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;it compiles but still is not correct&lt;/P&gt;&lt;P&gt;i think because it is messing with the sign or something for supposedly negative stuff&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so how do i do this?&lt;/P&gt;&lt;P&gt;do i rather make the table of what each adc step mean and just look out for it?&lt;/P&gt;&lt;P&gt;would that be faster than dividing and multiplying on a 8 bit mcu?&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Apr 2013 16:54:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287841#M20433</guid>
      <dc:creator>GMVS</dc:creator>
      <dc:date>2013-04-27T16:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: ADC interpretation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287842#M20434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;UL&gt;&lt;LI&gt;_DMUL_RC, _DSTRUNC, _DUFLOAT are not defined&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These are double precision floating point routines. Creating project you had to tell project wizard that you want floating point sipport.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;unsigned int ADCm;&lt;/LI&gt;&lt;LI&gt;long Voltage;&lt;/LI&gt;&lt;LI&gt;&lt;/LI&gt;&lt;LI&gt;Voltage=ADCm*650/255; //interpret it&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Though Voltage is long, expression on the right is calculates as all int, as a result multiply overflows and you see weird result. Try typecasting one or both multipliers to get expected result:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Voltage=(long)ADCm*650/255;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Apr 2013 19:54:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287842#M20434</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2013-04-27T19:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: ADC interpretation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287843#M20435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It should be possible to stay with a 16-bit calculation, since it will be more efficient than a 32-bit calculation.&lt;/P&gt;&lt;P&gt;In place of the expression&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Voltage = (int)ADCm * 650 / 255;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;instead use the following equivalent, whose intermediate result will not overflow a 16-bit value.&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;unsigned int Voltage;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Voltage = (unsigned int)ADCm * 130 / 51;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the case of the 32-bit calculation, another way of forcing this would be -&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;long Voltage;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Voltage = ADCm * 650L / 255;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&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>Sun, 28 Apr 2013 13:32:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287843#M20435</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-04-28T13:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: ADC interpretation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287844#M20436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;excelent! this is what worked the best, thanks a lot!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you too &lt;STRONG style="font-size: 12px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;A href="https://community.nxp.com/people/kef"&gt;kef&lt;/A&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one last question, optional tho&lt;/P&gt;&lt;P&gt;i need to show this converted value on a 2x16 LCD&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after your answer i came up with this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void hex2dec(unsigned int hex, char *dec)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; unsigned int temp=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (hex==0) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; *dec = '0';&lt;/P&gt;&lt;P&gt;&amp;nbsp; return;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(hex!=0){&lt;/P&gt;&lt;P&gt;&amp;nbsp; temp=hex%10;&amp;nbsp; // &amp;lt;------------this...&lt;/P&gt;&lt;P&gt;&amp;nbsp; *dec = (char) temp + '0';&lt;/P&gt;&lt;P&gt;&amp;nbsp; hex=hex/10;&amp;nbsp;&amp;nbsp; // &amp;lt;------------and this are gonna take a lot of time to get done, won't they? and they require a lot of code, aren't they?&lt;/P&gt;&lt;P&gt;&amp;nbsp; dec--;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void main(){&lt;/P&gt;&lt;P&gt;/*somewhere in the main*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; ADC1_Measure(1);&lt;/P&gt;&lt;P&gt;&amp;nbsp; ADC1_GetValue8(ADCReadBuffer);&lt;/P&gt;&lt;P&gt;&amp;nbsp; ADCm=ADCReadBuffer[0];&lt;/P&gt;&lt;P&gt;&amp;nbsp; Voltage=(unsigned int)ADCm*130/51;&lt;/P&gt;&lt;P&gt;&amp;nbsp; strcpy(blaf, "ADC: 0x&amp;nbsp;&amp;nbsp;&amp;nbsp; ,&amp;nbsp;&amp;nbsp;&amp;nbsp; V");&lt;/P&gt;&lt;P&gt;&amp;nbsp; hex2ascii((int)ADCm, banner+10);&lt;/P&gt;&lt;P&gt;&amp;nbsp; hex2dec(Voltage, banner+15);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LCD_clear();&lt;/P&gt;&lt;P&gt;&amp;nbsp; LCD_sendString(banner);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;/*way more code*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but before that i had this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;unsigned char HVBm[][4] = {&lt;/P&gt;&lt;P&gt;/*all (255) equivalent values in asacii for ADC measures*/&amp;nbsp;&amp;nbsp;&amp;nbsp; //&amp;lt;------- 1 k of memory gone&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void main (){&lt;/P&gt;&lt;P&gt;/*somewhere in the main*/&lt;/P&gt;&lt;P&gt;ADC1_Measure(1);&lt;/P&gt;&lt;P&gt;ADC1_GetValue8(ADCReadBuffer);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt; &lt;/SPAN&gt;strcpy(blaf, "ADC: 0x&amp;nbsp;&amp;nbsp;&amp;nbsp; , "+ 0 );&lt;/P&gt;&lt;P&gt;&amp;nbsp; hex2ascii((int)ADCm, blaf+10);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LCD_clear();&lt;/P&gt;&lt;P&gt;&amp;nbsp; LCD_sendString(blaf);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LCD_sendString(HVBm[ADCm]);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LCD_sendChar("V");&lt;/P&gt;&lt;P&gt;//code code code&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which approach would be better? in the end both present the info the way i want it&lt;/P&gt;&lt;P&gt;but i'm limited in&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;memory (i wouldn't like to have an array using a whole 1K just for this),&lt;/LI&gt;&lt;LI&gt;program size (i cant make the code too large, c code may appear short but asm might get wild)&lt;/LI&gt;&lt;LI&gt;execution time (there's a lot to do and so little time... this is a design requirement)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;i think my highst priority is execution time&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what do you think?&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Apr 2013 15:02:58 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287844#M20436</guid>
      <dc:creator>GMVS</dc:creator>
      <dc:date>2013-04-29T15:02:58Z</dc:date>
    </item>
    <item>
      <title>Re: ADC interpretation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287845#M20437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look up table should be the fastest and the best, provided you have space for it.&lt;/P&gt;&lt;P&gt;But the speed of LCD display routine is usually not important. You may lower refresh frequency, you may use preemptive RTOS, etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Apr 2013 21:06:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287845#M20437</guid>
      <dc:creator>kef</dc:creator>
      <dc:date>2013-04-30T21:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: ADC interpretation</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287846#M20438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From your template string, I am guessing that you wish to display the raw ADC data as a hexadecimal value, followed by the scaled decimal value representing the voltage?&amp;nbsp; Assuming this is so, I have "streamlined" and rationalised the code to some extent, as follows -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;#include &amp;lt;string.h&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&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;&amp;nbsp;&amp;nbsp; 0000000000111111&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&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;&amp;nbsp;&amp;nbsp; 0123456789012345&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;const byte template1[] = "ADC: 0x--,&amp;nbsp;&amp;nbsp; 0 V";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;void Show_ADC_result( word value)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; byte buf[17], i, c;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; // Copy template to buffer (779 cycles)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; (void)strcpy( buf, template1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; // Insert hexadecimal value in template (49-65 cycles)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; c = ((value &amp;amp; 0xF0) &amp;gt;&amp;gt; 4) + '0';&amp;nbsp; // Upper nybble&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; if (c &amp;gt; '9')&amp;nbsp; c += 7;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; buf[7] = c;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; c = (value &amp;amp; 0x0F) + '0';&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Lower nybble&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; if (c &amp;gt; '9')&amp;nbsp; c += 7;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; buf[8] = c;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; // Insert scaled decimal value in template (215 + 671 cycles)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; value = value * 130 / 51;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Scale value&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; for (i = 13; value; i--) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buf[i] = (value % 10) + '0';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; value /= 10;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; LCD_clear();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Minimum 1640 us&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp;&amp;nbsp; LCD_sendString( buf); // Minimum 640 us (16 * 40 us)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;Not including the LCD operations, the processing will require about 1750 cycles.&amp;nbsp; For a bus frequency of 10 MHz, this would amount to a period of 175 microseconds.&amp;nbsp; However, the LCD operations are notoriously slow.&amp;nbsp; When these are implemented in the usual manner, the minimum durations, required by the display, are as I have indicated.&amp;nbsp; In comparison, the time required for the string processing is insignificant.&amp;nbsp; Depending on the actual implementation of the LCD functions, the delays could be much longer than the minimum requirement.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;To speed the function execution time, you might use a more complex LCD write method, where the individual characters of the string are actually written during a periodic timer interrupt, thus avoiding the need to wait for the total write period within the above function.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;I also question whether you need to clear the LCD and home the cursor, as you are doing.&amp;nbsp; Since the data string writes to all 16 positions of a display line, simply over-write the previous data.&amp;nbsp; This would then require only that the cursor be positioned to the start of the display line, requiring 40 microseconds (rather than 1640 microseconds).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;Mac&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="mce_paste_marker"&gt;&lt;/SPAN&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2013 03:21:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/ADC-interpretation/m-p/287846#M20438</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2013-05-01T03:21:22Z</dc:date>
    </item>
  </channel>
</rss>

