<?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>Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64886/sometimes-nrf52840-aadc-calibration-is-wrong</link><description>Using the nrf52840 for analog sensor measurements we wanted to increase the accuracy by doing a regular calibration. Doing so we sometimes noticed spurious changes in measurement offset error when the calibration was done. After investigating this behaviour</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 04 Sep 2020 10:37:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64886/sometimes-nrf52840-aadc-calibration-is-wrong" /><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/268014?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 10:37:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:569e50e8-7ab1-416c-a03e-86445d966efc</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Ah, now I understand, thank you for clarifying.&lt;/p&gt;
[quote user="maarten v"]Depending on the sensor and the application we use less or more oversampling.&lt;br /&gt;With oversampling and extra offset correction the accuracy is good enough for our applications.[/quote]
&lt;p&gt;That sounds like a good solution - I am happy to hear that it achieved the required accuracy for your applications.&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.&lt;br /&gt;&lt;br /&gt;Good luck with your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/268010?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 10:16:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dfa7d957-1cac-4fad-ba47-1e8b0da7cb9b</guid><dc:creator>maarten v</dc:creator><description>&lt;p&gt;The required accuracy depends on the application. We have developed some IOT nodes (&lt;a href="https://xeelas.nl/producten)"&gt;https://xeelas.nl/producten)&lt;/a&gt; with capability of connecting external sensors.&lt;/p&gt;
&lt;p&gt;Depending on the sensor and the application we use less or more oversampling.&lt;br /&gt;With oversampling and extra offset correction the accuracy is good enough for our applications.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/268001?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 09:22:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:230417a5-5706-4ed7-b6d1-3a8c67a649c7</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="maarten v"]1024 times oversampling reduces the noise by a factor 2^5, which is indeed what i see when i did some experiments with this.[/quote]
&lt;p&gt;You never told me the exact accuracy / precision need of the SAADC for your project, so I not know what your target is.&lt;br /&gt;Does this mean you are able to achieve the required accuracy for your project?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/267997?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 09:11:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73ed4bb4-e014-4f13-a704-3ec95ab8e6f7</guid><dc:creator>maarten v</dc:creator><description>&lt;p&gt;yes, in 12 bit mode there is about 4 bits noise. That is unfortunate but according spec for the 52840.&lt;/p&gt;
&lt;p&gt;1024 times oversampling reduces the noise by a factor 2^5, which is indeed what i see when i did some experiments with this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/267960?ContentTypeID=1</link><pubDate>Fri, 04 Sep 2020 07:26:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d74e7057-c958-4dce-a932-04eb64737240</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="maarten v"]Thank you for the answer, and my apologies that it took some time.[/quote]
&lt;p&gt;That is no problem, I am happy to help!&lt;/p&gt;
[quote user="maarten v"]This is the confirmation i was looking for. Time is not an issue since it only has to be done incidentally and can be scheduled in between other actions.[/quote]
&lt;p&gt;Great, I am glad to hear that!&lt;/p&gt;
[quote user="maarten v"]fyi: The remaining offset is compensated with a firmware calculated offset from an average of 1024 samples. This does the trick in keeping the signal stable when the temperature is not changed, so i guess it will also work when it does change.[/quote]
&lt;p&gt;Are you here talking about using a static average to weight the samples? If you are achieving the correct readouts with this approach then I suppose it is fine, but I can not speak for the accuracy of the outcome. As I mentioned I would expect some LSB of noise on the SAADC outputs, depending on the SAADC configuration.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/267918?ContentTypeID=1</link><pubDate>Thu, 03 Sep 2020 18:18:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb026c30-13bc-4fca-b614-38d39aea7295</guid><dc:creator>maarten v</dc:creator><description>&lt;p&gt;Thank you for the answer, and my apologies that it took some time.&lt;br /&gt;This is the confirmation i was looking for. Time is not an issue since it only has to be done incidentally and can be scheduled in between other actions.&lt;/p&gt;
&lt;p&gt;fyi: The remaining offset is compensated with a firmware calculated offset from an average of 1024 samples. This does the trick in keeping the signal stable when the temperature is not changed, so i guess it will also work when it does change.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/266006?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2020 13:36:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd1c6a98-cf9e-4e2b-a52b-c52081b907c0</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello again,&lt;br /&gt;&lt;br /&gt;Thank you for providing me with the project files.&lt;br /&gt;I have just gotten back from speaking with the SAADC experts, which confirmed for me that setting oversampling for AIN0 does actually increase accuracy of the offset calibration since it too will use oversampling during the calibration. The oversampling will in this case suppress thermal noise - increasing accuracy -, but the calibration will not be more accurate than its internal DAC. The calibration will also take longer, since more samplings will be done.&lt;br /&gt;&lt;br /&gt;What&amp;nbsp;accuracy do you require for your project?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265940?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2020 11:10:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:342ad104-4b21-4451-a395-00e9e760c1eb</guid><dc:creator>maarten v</dc:creator><description>&lt;p&gt;Thank you for the answers.&lt;/p&gt;
&lt;p&gt;Attached is the whole project.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/aadc_2D00_precision.zip"&gt;devzone.nordicsemi.com/.../aadc_2D00_precision.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I did run it on a nRF52840DK.&lt;/p&gt;
&lt;p&gt;Looking forward to your findings.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265933?ContentTypeID=1</link><pubDate>Mon, 24 Aug 2020 10:41:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0256702-2f64-4dae-b21a-be66eff76384</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
[quote user="maarten v"]I restructured the program to improve showing the calibration problem.[/quote]
&lt;p&gt;Thank you for pinpointing this.&lt;br /&gt;Could you possibly share with me the entire project from which this main.c file is taken from?&lt;br /&gt;Then I will run this on my end and attempt to replicate the behavior - I would love to get a better look at&amp;nbsp;what might cause this change in offset calibration.&lt;/p&gt;
[quote user="maarten v"]I now use the gnd reading for an extra compensation. This works quite well but i do not know if reading the gnd as&amp;nbsp; shown is defined behavior.[/quote]
&lt;p&gt;If you are asking whether measuring gnd by setting the pin to pulldown is defined behavior then the answer would have to be that it indeed is undefined, but I do not immediately see any reason why this would not work.&lt;br /&gt;If this is not what you were asking, please elaborate.&lt;/p&gt;
[quote user="maarten v"]I want a solution for this offset problem.[/quote]
&lt;p&gt;How big is the fluctuation you are seeing now, in terms of bits of saadc output / mV? And, how frequently is it happening?&lt;/p&gt;
[quote user="maarten v"]Is this possible by setting the input to NRF_SAADC_INPUT_DISABLED, while setting the internal resistor network to NRF_SAADC_RESISTOR_PULLDOWN?[/quote]
&lt;p&gt;No, you should instead point it to a specific pin, and then change the configuration of that pin after the channel configuration is complete.&lt;br /&gt;Alternatively you can also just connect the chosen pin to GND with a jumper, for the same result.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265824?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 15:55:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0390cc41-416a-403c-a04a-838d8a6768fc</guid><dc:creator>maarten v</dc:creator><description>&lt;p&gt;I restructured the program to improve showing the calibration problem.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;

#include &amp;lt;nrf_delay.h&amp;gt;
#include &amp;lt;nrfx_gpiote.h&amp;gt;
#include &amp;lt;nrfx_saadc.h&amp;gt;


// uncomment this to show the calibration problem without oversampling.
//#define ENABLE_CALIBRATION_BUG


const float v_ref = 0.6;     // internal reference voltage
STATIC_ASSERT(NRFX_SAADC_CONFIG_RESOLUTION == 2);
#define ADC_RESOLUTION 4096u /// 12 bit adc reolution (14 bit is only accomplished with oversampling)

#define CHANNEL_CONFIG(PIN_P, RESISTOR_P, GAIN) (nrf_saadc_channel_config_t)\
{\
    .resistor_p = RESISTOR_P,      \
    .resistor_n = NRF_SAADC_RESISTOR_DISABLED,      \
	.gain       = GAIN,                \
    .reference  = NRF_SAADC_REFERENCE_INTERNAL,     \
    .acq_time   = NRF_SAADC_ACQTIME_10US,           \
    .mode       = NRF_SAADC_MODE_SINGLE_ENDED,      \
    .burst      = NRF_SAADC_BURST_DISABLED,         \
    .pin_p      = (nrf_saadc_input_t)(PIN_P),       \
    .pin_n      = NRF_SAADC_INPUT_DISABLED         \
}

static nrfx_saadc_config_t saadc_config = NRFX_SAADC_DEFAULT_CONFIG;
static volatile bool limit_event;

static float get_gain_factor(nrf_saadc_gain_t gain)
{
	float factor ;
	switch( gain )
	{
		case NRF_SAADC_GAIN1_6: factor = 1.0/6; break;
		case NRF_SAADC_GAIN1_5: factor = 1.0/5; break;
		case NRF_SAADC_GAIN1_4: factor = 1.0/4; break;
		case NRF_SAADC_GAIN1_3: factor = 1.0/3; break;
		case NRF_SAADC_GAIN1_2: factor = 1.0/2; break;
		case NRF_SAADC_GAIN1: factor = 1.0; break;
		case NRF_SAADC_GAIN2: factor = 2.0; break;
		case NRF_SAADC_GAIN4: factor = 4.0; break;
		default:
			ASSERT(false);
			break;
	}
	return factor;
}

static float adc_to_voltage( float adc, nrf_saadc_gain_t gain )
{
	float range = 0.6/get_gain_factor(gain);
	return range * adc/ADC_RESOLUTION;
}

static void saadc_callback(nrfx_saadc_evt_t const * p_event)
{
	if (p_event-&amp;gt;type == NRFX_SAADC_EVT_LIMIT)
	{
		limit_event = true;
	}
	else if (p_event-&amp;gt;type == NRFX_SAADC_EVT_DONE)
	{
		limit_event = false;
	}
	else if (p_event-&amp;gt;type == NRFX_SAADC_EVT_CALIBRATEDONE)
	{
		limit_event = false;
	}
}

static void mcu_adc_init(void)
{
	ret_code_t err_code = nrfx_saadc_init(&amp;amp;saadc_config, saadc_callback);
	ASSERT(err_code == NRF_SUCCESS);
}

static void mcu_adc_uninit(void)
{
	nrfx_saadc_uninit();
}

// sample 1 channel, already configured
// @param *adc [out]: the average of the raw read adc samples.
static void channel_convert(uint8_t channel, unsigned oversample, float *adc_avg)
{
	int adc_sum = 0;
	for( unsigned i = 0; i&amp;lt;oversample+1; i++ )
	{
		nrf_saadc_value_t adc;
		ret_code_t rr = nrfx_saadc_sample_convert(channel, &amp;amp;adc);
		ASSERT( rr == NRF_SUCCESS );
		//printf(&amp;quot;    part_adc=%hd\n&amp;quot;, *adc);
		adc_sum += adc;
	}
	
	*adc_avg = adc_sum / (float)(oversample+1);
}


void mcu_adc_calibrate(void)
{
	ret_code_t r;
	
	printf(&amp;quot;Calibrate\n&amp;quot;);
	
	// prepare
	nrfx_saadc_uninit();
	#ifndef ENABLE_CALIBRATION_BUG
	saadc_config.oversample = 8;
	#endif
	r = nrfx_saadc_init(&amp;amp;saadc_config, saadc_callback);
	
	// calibrate
	r = nrfx_saadc_calibrate_offset();
	ASSERT(r == NRF_SUCCESS);
	
	while (nrfx_saadc_is_busy())
	{
	}

	// finalize
	
	// Nordic errata 86 workaround...
	nrfx_saadc_uninit();
	saadc_config.oversample = 0;
	r = nrfx_saadc_init(&amp;amp;saadc_config, saadc_callback);
	ASSERT(r == NRF_SUCCESS);
}

void mcu_adc_read_gnd(nrf_saadc_gain_t gain, unsigned oversample, float *adc)
{
	nrf_saadc_channel_config_t chcfg = CHANNEL_CONFIG(NRF_SAADC_INPUT_DISABLED, NRF_SAADC_RESISTOR_PULLDOWN, gain);

	nrf_saadc_channel_init(0, &amp;amp;chcfg);
	channel_convert(0, oversample, adc);
	nrf_saadc_channel_input_set(0, NRF_SAADC_INPUT_DISABLED, NRF_SAADC_INPUT_DISABLED);
}

void mcu_adc_read_1(nrf_saadc_input_t pin, nrf_saadc_gain_t gain, unsigned oversample, float *adc)
{
	nrf_saadc_channel_config_t chcfg = CHANNEL_CONFIG(pin, NRF_SAADC_RESISTOR_DISABLED, gain);
	
	nrfx_saadc_channel_init(0, &amp;amp;chcfg);
	channel_convert(0, oversample, adc);
	nrfx_saadc_channel_uninit(0);
}

int mcu_adc_read_test(void)
{
	mcu_adc_init();
	nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(0, 2), NRF_GPIO_PIN_NOPULL);
	
	for(unsigned j=0; j&amp;lt;1000; j++)
	{
		mcu_adc_calibrate();
		for(unsigned i=0; i&amp;lt;3; i++)
		{
			const char *sep = &amp;quot;   &amp;quot;;
			const unsigned oversample = 1023;
			
			for( nrf_saadc_gain_t gain = NRF_SAADC_GAIN1_6; gain&amp;lt;=NRF_SAADC_GAIN1_5; gain++ )
			{
				printf(&amp;quot;%s{gain:%0.2f, &amp;quot;, sep,  get_gain_factor(gain));
					
				// zero measurement
				float adcgnd;
				mcu_adc_read_gnd(gain, oversample, &amp;amp;adcgnd);
				
				if(nrfx_saadc_is_busy())
				{
					printf(&amp;quot;still busy!\n&amp;quot;);
					nrfx_saadc_is_busy();
					{}
				}
				
				float v_adcgnd = adc_to_voltage(adcgnd, gain);
				printf(&amp;quot;, adcgnd:{adc:%0.1f, V::%0.3fV}&amp;quot;, adcgnd, v_adcgnd);
				
				// ain0 measurement
				float ain0;
				mcu_adc_read_1(NRF_SAADC_INPUT_AIN0, gain, oversample, &amp;amp;ain0);
				
				if(nrfx_saadc_is_busy())
				{
					printf(&amp;quot;still busy!\n&amp;quot;);
					nrfx_saadc_is_busy();
					{}
				}

				float v_ain0 = adc_to_voltage(ain0, gain);

				printf(&amp;quot;, ain0:{adc:%0.1f, V::%0.3fV}&amp;quot;, ain0, v_ain0);

				printf(&amp;quot;, ain0_corrected:{adc:%0.1f, V::%0.3fV}&amp;quot;, ain0-adcgnd, v_ain0-v_adcgnd);

				// FIXME this is a patch for the fact the that ADC does not stop (reason unknonw).
				nrfx_saadc_abort();
				nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP);

				sep = &amp;quot;, &amp;quot;;
			}

			printf(&amp;quot;\n&amp;quot;);
		}
	}
	
	mcu_adc_uninit();
	
	do
	{} 
	while (1);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Oversampling is disabled ENABLE_CALIBRATION_BUG is defined: then reading the gnd voltage differs often between calibrations.&lt;br /&gt;When oversampling is turned on during calibration, the ground reading is almost always stable.&lt;/p&gt;
&lt;p&gt;I now use the gnd reading for an extra compensation. This works quite well but i do not know if reading the gnd as&amp;nbsp; shown is defined behavior.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265722?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 09:54:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a789f6a2-f9cf-43d5-8095-267a510bc846</guid><dc:creator>maarten v</dc:creator><description>[quote userid="87869" url="~/f/nordic-q-a/64886/sometimes-nrf52840-aadc-calibration-is-wrong/265680"]The deviation seems to be much less frequent ( 1 in 40 ) when you have turned on x256 oversampling, is that what you are saying?&lt;br /&gt;[/quote]
&lt;p&gt;Correct. But that was yesterday. The exact same solution results in much more frequent calibration ofset jumps on a different nrf52840. So perhaps this was just coincidental.&lt;br /&gt;&lt;br /&gt;I want a solution for this offset problem.&lt;br /&gt;I was thinking of measuring the 0V adc deviation myself. Is this possible by setting the input to NRF_SAADC_INPUT_DISABLED, while setting the internal resistor network to NRF_SAADC_RESISTOR_PULLDOWN?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265680?ContentTypeID=1</link><pubDate>Fri, 21 Aug 2020 07:54:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91f102a1-2fa2-4751-bab4-1e9160742158</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user="maarten v"]I discovered that turning on oversampling (256x) &lt;em&gt;before&lt;/em&gt; doing a calibration reduced the variation in the result of the calibration to about 0.5 bit in the 12bit resolution, instead of 1 bit in the 8 bit resolution.&lt;br /&gt;This is what i would expect and acceptable.[/quote]
&lt;p&gt;That is interesting. I will note this down and attempt to recreate this behavior on my end. To my knowledge, whether you have configured oversampling or not should not affect the offset calibration procedure at all.&lt;br /&gt;&lt;br /&gt;Furthermore, depending on your input range configuration I would more or less expect a possible fluctuation in LSB of an SAADC output.&lt;br /&gt;Is this remaining fluctuation an issue for your current project - what is your required resolution?&lt;/p&gt;
[quote user="maarten v"]I was too quick: the deviation seems to be much less frequent (about 1 in 40) but still happens now and than: suddenly a jump in the offset after a calibration.[/quote]
&lt;p&gt;The deviation seems to be much less frequent ( 1 in 40 ) when you have turned on x256 oversampling, is that what you are saying?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265448?ContentTypeID=1</link><pubDate>Thu, 20 Aug 2020 06:33:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76d9d844-922d-47d5-9692-b342030b4eb5</guid><dc:creator>maarten v</dc:creator><description>[quote userid="87869" url="~/f/nordic-q-a/64886/sometimes-nrf52840-aadc-calibration-is-wrong/265103"]I see the samplings and how they seem to fluctuate, but I do not see any consistent trend between the different calibrations. Are you saying that the SAADC output values are increasing by 2-4 for every calibration?&lt;br /&gt;I am not sure I understand what you are saying here, please correct me if I am wrong.[/quote]
&lt;p&gt;What the code shows is that an adc conversion of a pin connected to ground (or actually the the average of 1000 conversions to exclude noise as a deviation), sometimes suddenly has a different value after a calibration.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;I found a possible cause and solution:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I discovered that turning on oversampling (256x) &lt;em&gt;before&lt;/em&gt; doing a calibration reduced the variation in the result of the calibration to about 0.5 bit in the 12bit resolution, instead of 1 bit in the 8 bit resolution.&lt;br /&gt;This is what i would expect and acceptable.&lt;br /&gt;&lt;br /&gt;Apparently the calibration is performed with the oversampling setting which needs to be set to&amp;nbsp; high value before doing the calibration to have a reliable result.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;It is possible i overlooked this in the documentation. Or is this an undocumented feature?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Edit:&lt;/p&gt;
&lt;p&gt;I was too quick: the deviation seems to be much less frequent (about 1 in 40) but still happens now and than: suddenly a jump in the offset after a calibration.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/265103?ContentTypeID=1</link><pubDate>Tue, 18 Aug 2020 12:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d79b0309-a3ce-4635-918e-948e94101f3e</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;With GAIN = 4 and using the internal 600 mV reference it seems you get the biggest fluctuation of 12 SAADC values (53 - 41).&lt;br /&gt;Calculating the input range with these parameters using the formula from the SAADC documentation yields the range 0 - 0.15 V. With a resolution of 12 bit there is a total of 4096 possible values, which means that the fluctuation at worst is 0.4 mV.&lt;br /&gt;This does not seem out of the ordinary to me.&lt;/p&gt;
[quote user=""]Thisis makes it clear the the calibration jumps between 2 values (some runs it is even 4 different values values)[/quote]
&lt;p&gt;I see the samplings and how they seem to fluctuate, but I do not see any consistent trend between the different calibrations. Are you saying that the SAADC output values are increasing by 2-4 for every calibration?&lt;br /&gt;I am not sure I understand what you are saying here, please correct me if I am wrong.&lt;br /&gt;&lt;br /&gt;For future reference, please use the &amp;quot;Insert -&amp;gt; Code&amp;quot; option when attaching code, and upload entire log files instead of copying parts of it, this will drastically increase readability.&lt;br /&gt;&lt;br /&gt;Looking forward to getting to the bottom of this!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sometimes nrf52840  aadc calibration is wrong</title><link>https://devzone.nordicsemi.com/thread/264895?ContentTypeID=1</link><pubDate>Mon, 17 Aug 2020 13:34:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64b2240f-3915-4785-bfed-41a5276e50d6</guid><dc:creator>maarten v</dc:creator><description>&lt;p&gt;I forgot to add: this example is with a 12 bit conversion. The error is less that 1 bit when the conversion is done with 8 bit.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>