<?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>Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79922/inconsistent-adc-values---adc-conversion-taking-a-long-time</link><description>Hello, 
 I am using multiple ADC pins and realized that repeated calls to the ADC give inconsistent data, suggesting that the conversions are not completing before the next call. I am using the blocking function nrf_drv_saadc_sample_convert (pin, &amp;amp;value</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 Sep 2021 13:07:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79922/inconsistent-adc-values---adc-conversion-taking-a-long-time" /><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/331938?ContentTypeID=1</link><pubDate>Thu, 30 Sep 2021 13:07:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e968428-80a3-450a-a65b-017516df0eb2</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;If you are only measuring remaining battery capacity, I don&amp;#39;t expect a few % errors is any problem, but you can find the electrical parameters here:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html#unique_699150403"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html#unique_699150403&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/331713?ContentTypeID=1</link><pubDate>Wed, 29 Sep 2021 12:35:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b34105b7-26b5-4277-b566-f5e90716331b</guid><dc:creator>mrsunny</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Kenneth,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I believe I corrected my confusion on configuring ADC pins and assigning them to channels. However, I had to search online to find the correct gain factor, and now I read that there are ADC offsets and other nuances that I need to add/subtract to get the actual voltage reading. Can you point me to any docs or datasheets that outline these computational parameters, and if changing the ADC configurations such as&amp;nbsp;NRF_SAADC_GAIN1_6, or&amp;nbsp;NRF_SAADC_ACQTIME_10US modify these values?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To confirm I am doing this correctly, here&amp;#39;s the minimum set of code to configure and read an ADC pin (in blocking mode)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// this is where the physical pin is defined. Say AINO on the board
nrf_saadc_channel_config_t channel_config0 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

// in blocking mode, this callback isn&amp;#39;t used but needs to be initialized.
// callback is not written here for brevity
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);

// this is where that pin is assigned to a ADC channel. Channels go from 0-7
ret_code_t err_code;
err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config0);
APP_ERROR_CHECK(err_code);

// this is where the ADC value is read.
// NOTE - using the same channel defined above, which is 0
nrf_saadc_value_t adc_result;
err_code = nrf_drv_saadc_sample_convert(0, &amp;amp;adc_result);

// math to get the equivalent voltage (mV) reading
// NOTE - gain is 3.6 for default settings and bit resolution defined in sdk_config is 12 bits.
float val = ((adc_result * 3.6 * 1000) / 4096) ;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you, and hope this helps others involved.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;George&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/331542?ContentTypeID=1</link><pubDate>Tue, 28 Sep 2021 13:50:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:652eec8a-bf42-4ca5-989b-f06ea4a358df</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I think you are mixing adc channels with analog pins, there is no dependency between the two. So if you need to sample one analog pin (e.g. &lt;span&gt;AnalogInput7)&lt;/span&gt;, then I suggest to configure adc channel 0 to sample whatever analog input you want to sample (e.g. &lt;span&gt;AnalogInput7 = value 8)&lt;/span&gt;. Also see:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html#register.CH-0.PSELP"&gt;https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html#register.CH-0.PSELP&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/331504?ContentTypeID=1</link><pubDate>Tue, 28 Sep 2021 12:24:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76368db9-4e90-4e73-aaee-87d4b6cff9ce</guid><dc:creator>mrsunny</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;/p&gt;
&lt;p&gt;Did some more testing and now I am a confused on how these ADC pins work. I used an ADC on an arduino and found that the resistor and cap values should be okay. I&amp;#39;m wondering if I configured my pins correctly,&amp;nbsp;especially the&amp;nbsp;pin numbering as I&amp;#39;ve read that AIN7 (pin 7, or P0.31) is &lt;span style="text-decoration:underline;"&gt;NOT&lt;/span&gt;&amp;nbsp;NRF_SAADC_INPUT_AIN7.&lt;/p&gt;
&lt;p&gt;I am using pin 0.31, AIN7 as the voltage reading on the battery voltage divider.&amp;nbsp;Is it appropriate to assign this pin as 7 and run configuration:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_saadc_channel_config_t channel_config7 = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(7);
err_code = nrf_drv_saadc_channel_init(7, &amp;amp;channel_config7);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then I simply read its value in blocking mode&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t err_code;
nrf_saadc_value_t adc_result;

// convert ADC value
err_code = nrf_drv_saadc_sample_convert(BATTERY_PIN, &amp;amp;adc_result);
APP_ERROR_CHECK(err_code);

// print
NRF_LOG_INFO(&amp;quot;%d&amp;quot;, adc_result);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Yet, these are giving me readings of&amp;nbsp;321 out of a&amp;nbsp;12 bit resolution (configured in sdk_config.h - #define SAADC_CONFIG_RESOLUTION 2), which means my battery is dead or not hooked up.&lt;/p&gt;
&lt;p&gt;Any insights?&lt;/p&gt;
&lt;p&gt;Best,&lt;/p&gt;
&lt;p&gt;George&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/331222?ContentTypeID=1</link><pubDate>Mon, 27 Sep 2021 07:42:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de46139d-5ce7-47c4-a9e4-40944b320a61</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;The 10nF should do the job here, so I don&amp;#39;t see how this shouldn&amp;#39;t work. But for test please try with smaller resistors just to confirm this is the issue at hand.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/330928?ContentTypeID=1</link><pubDate>Thu, 23 Sep 2021 23:34:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:053dd80b-f82e-42ed-97a2-187989bfe8cb</guid><dc:creator>mrsunny</dc:creator><description>&lt;p&gt;That could be right. Here&amp;#39;s the voltage divider I am using to measure the battery level.&lt;/p&gt;
&lt;p&gt;It&amp;nbsp;is a 4MOhm by 10MOhm voltage divider with a 10nF cap. I remember I could do this with my sampling frequency from this &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/measuring-lithium-battery-voltage-with-nrf52"&gt;post&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1632439800098v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;From the post&lt;/p&gt;
&lt;p&gt;&lt;img height="93" src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1632440026589v2.png" width="451" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;However, if you see the notes it should have been 2 100KOhm resistors. Anyways, I&amp;#39;m surprised it would be this slow to charge. I&amp;#39;m assuming a fix would be to replace the resistors for something smaller. Same for the capacitor (say 1 nF)?&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;George&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Inconsistent ADC values - ADC conversion taking a long time</title><link>https://devzone.nordicsemi.com/thread/330816?ContentTypeID=1</link><pubDate>Thu, 23 Sep 2021 11:12:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7511605c-7884-41a4-9e6e-56cfa80bb592</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Sounds to me that you are measuring a very high impedance source (e.g. &amp;gt;1Mohm), which each time the pin is sampled need to be &amp;quot;charged&amp;quot; before it return to the same level. Can you connect a small capacitor (e.g. &amp;gt;1nF) on the analog input to see if this affect your results?&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>