<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Problem with ADC precision</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49054/problem-with-adc-precision</link><description>Hello everyone, 
 
 We are using the nrf52840 Dev Kit (PCA10056 1.1.0 2019.19 683465548) 
 SDK Version: 15.3 
 OS: Fedora 
 
 When we are generating a 1V voltage our adc returns values between [260, 280]. We use this function to convert it into &amp;#181;V: We</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 29 Jun 2019 09:27:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49054/problem-with-adc-precision" /><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195451?ContentTypeID=1</link><pubDate>Sat, 29 Jun 2019 09:27:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccd1ae3c-bdb5-4b2c-8186-c4a9d92e210f</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;You should be able to avoid the int32 overflow by casting to 64-bit ...&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Or, as it&amp;#39;s all compile-time constants, just work it out before hand.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195444?ContentTypeID=1</link><pubDate>Sat, 29 Jun 2019 07:32:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d244da97-a579-421f-962c-5ce47fe59d95</guid><dc:creator>p_t</dc:creator><description>&lt;p&gt;In here multiplication was the&amp;nbsp;reason which overflowed the int32, thats why i suggested doing division first . but thats true that if result is int type then it will lose its fraction part.&amp;nbsp; Thanks for the correction.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195167?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 13:30:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:237fa9dd-42cc-4ce7-a09f-97bca92c55ec</guid><dc:creator>awneil</dc:creator><description>[quote userid="75788" url="~/f/nordic-q-a/49054/problem-with-adc-precision/195067"](600000/16384) * 6&amp;nbsp; = 219.7265625[/quote]
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/louis-hatte"&gt;Louis Hatte&lt;/a&gt;: remember that &amp;#39;C&amp;#39; will do this in&amp;nbsp;&lt;em&gt;&lt;strong&gt;integer&lt;/strong&gt; &lt;/em&gt;arithmetic&lt;/p&gt;
&lt;p&gt;So it will first calculate&amp;nbsp;&lt;span&gt;600000/16384 = 36 and then multiply by 6 to give &lt;strong&gt;192&lt;/strong&gt; - which is a significant error!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;With &lt;strong&gt;integer&lt;/strong&gt; maths, always do the &lt;strong&gt;multiplication &lt;em&gt;first&lt;/em&gt;&lt;/strong&gt;;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;ie,&amp;nbsp;600000 * 6 =&amp;nbsp;3600000 and then dividing by 16384 gives &lt;strong&gt;219&lt;/strong&gt; - which is much closer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f603.svg" title="Smiley"&gt;&amp;#x1f603;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Of course, you have to be careful of overflow ...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You might want to note this thread about using the FPU:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/49062/fpu-power-consumption"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/49062/fpu-power-consumption&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195162?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 13:16:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1863416-5259-45af-94fb-54f614f856ea</guid><dc:creator>Louis Hatte</dc:creator><description>&lt;p&gt;Thank for the trick &lt;a href="https://devzone.nordicsemi.com/members/p_5f00_t"&gt;p_t&lt;/a&gt; It works now with 14BIT resolution.&lt;br /&gt;Yes &lt;a href="https://devzone.nordicsemi.com/members/haakonsh"&gt;haakonsh&lt;/a&gt;, my source wasn&amp;#39;t really 1.00V but 0.940V&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195113?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 11:32:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb5840c9-d860-4762-a936-bc034f1a9f5c</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Are you using multiple SAADC channels?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195098?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 11:03:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0931d9e4-edd3-402f-b7ba-46905a1a53b9</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;My guess is that you&amp;#39;ve probably not calibrated the offset, or your 1V source is not really 1.00V.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195072?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 09:28:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c356f863-00b5-4b9c-ba4f-b995322d79a4</guid><dc:creator>awneil</dc:creator><description>[quote userid="80791" url="~/f/nordic-q-a/49054/problem-with-adc-precision"]When we are generating a 1V voltage[/quote]
&lt;p&gt;How are you generating it?&lt;/p&gt;
&lt;p&gt;How precise is it?&lt;/p&gt;
[quote userid="80791" url="~/f/nordic-q-a/49054/problem-with-adc-precision"]We get values around 940 000 µV instead of 1 000 000µV.[/quote]
&lt;p&gt;Assuming your &amp;quot;1V&amp;quot; really is 1 000 000 uV, that&amp;#39;s an error of 60 000 uV - which is 6%&lt;/p&gt;
&lt;p&gt;In the&amp;nbsp;&lt;span&gt;nrf52840&amp;nbsp; SAADC electrical specs, the gain error is 3-4%&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So it doesn&amp;#39;t seem that you&amp;#39;re wildly off ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html?cp=3_0_0_5_22_9#unique_1950216936"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html?cp=3_0_0_5_22_9#unique_1950216936&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;See also:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/48492/saadc-error"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/48492/saadc-error&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with ADC precision</title><link>https://devzone.nordicsemi.com/thread/195067?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 09:24:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63c499bf-22f8-480c-8098-ca79de4d8cb0</guid><dc:creator>p_t</dc:creator><description>&lt;p&gt;(600000/16384) * 6&amp;nbsp; = 219.7265625&lt;/p&gt;
&lt;p&gt;try,&lt;/p&gt;
&lt;p&gt;adc_uv = adc_value * 219.7265625;&lt;/p&gt;
&lt;p&gt;or make adc_uv unsigned32&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;shouldnt get negative values after that&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>