<?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>Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84845/configure-sampling-rate-for-nrf5340-saadc</link><description>I&amp;#39;m working on the nrf5340 with a modified sample found here ( main.c of the base sample here ) and nrf connect sdk 1.7.1 
 I see that adc_sequence_options .interval_us can set the time between samples in microseconds, so I tried to use that to set my</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Apr 2022 11:56:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84845/configure-sampling-rate-for-nrf5340-saadc" /><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/362327?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 11:56:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f41c05f-177c-4978-b51a-64bd982b993a</guid><dc:creator>ChrtistophAT</dc:creator><description>&lt;p&gt;Thank you very much Edvin!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/362321?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 11:43:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59fe6020-e5cc-4148-9ac5-435d565227d6</guid><dc:creator>Edvin</dc:creator><description>[quote user="chriistoph"]Unfortunately ther is no example/peripheral/ saadc in the sdk connect 1.9.1[/quote]
&lt;p&gt;Not that I am aware of.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I suggest that you take a quick peek at the nRF5 SDK\examples\peripheral\saadc, to familiarize yourself with how the ADC works, and then you can use the nrfx driver ADC instead of the zephyr implementation. This way you should be able to get a higher sample rate.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But again, for further questions, please open a new ticket.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/362289?ContentTypeID=1</link><pubDate>Thu, 07 Apr 2022 10:23:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1598902-26be-44ed-b58d-a3549ae98dbf</guid><dc:creator>ChrtistophAT</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;didnt know about the small amount of reference voltages you can choose, I believe I one time saw some mor like real VDD and simple Gain 1. Anyway saw now the&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/saadc/hal.html?highlight=nrf_saadc_reference#c.nrf_saadc_reference_t"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/saadc/hal.html?highlight=nrf_saadc_reference#c.nrf_saadc_reference_t&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;right way how to do&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1649326314143v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;and now everything is fine -&amp;gt; 512 when 2.5V applied by 10bit resolution.&lt;/p&gt;
&lt;p&gt;-22 failer code when wrong ADC_REF was selected. Sorry for writing in this -6 ticket.&lt;/p&gt;
[quote userid="26071" url="~/f/nordic-q-a/84845/configure-sampling-rate-for-nrf5340-saadc/362006#362006"]What are you trying to implement?[/quote]
&lt;p&gt;I have some dry muscel signal sensor, which is amplifying and filtering the signal with reference to 2.5V (VCC/2) from the PCB. For purpose of powerline noise 50Hz, I would like to ADC the amplified signal from the sensor and transfer through bluetooth package.&lt;/p&gt;
&lt;p&gt;Questions:&lt;/p&gt;
&lt;p&gt;adc mode single or differential to 2.5V reference?&lt;/p&gt;
&lt;p&gt;do I have to use ADC/driver lib for this fast sampling (15-20us)?&lt;/p&gt;
&lt;p&gt;exists some better example like the one I am struggling around?&lt;/p&gt;
[quote userid="25385" url="~/f/nordic-q-a/84845/configure-sampling-rate-for-nrf5340-saadc/361799#361799"]github.com/.../quote]
&lt;p&gt;Unfortunately ther is no example/peripheral/ saadc in the sdk connect 1.9.1&lt;/p&gt;
&lt;p&gt;Thank you for your advice in advance,&lt;/p&gt;
&lt;p&gt;Christoph&lt;/p&gt;
[/quote]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/362006?ContentTypeID=1</link><pubDate>Wed, 06 Apr 2022 09:05:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ad8f19ab-717b-4740-8128-0ed86a984897</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Christoph,&lt;/p&gt;
&lt;p&gt;It doesn&amp;#39;t look like this is the same issue as discussed in this ticket. Do you mean that the &amp;quot;failed with err code -22&amp;quot; is caused by the &amp;quot;Selected ADC reference is not valid&amp;quot;? EINVAL = 6, and what you see is -22 (0x16), so I am not sure how this would cause it to fail with -22.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="chriistoph"]&lt;p&gt;&lt;span&gt;wanted to write the case for ADC_REF_VDD_1 by myself but in the nrf_saadc.h file&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;a href="#"&gt;&lt;/a&gt;&lt;/div&gt;[/quote]
&lt;p&gt;What exactly do you want to do with an ADC_REF_VDD_1? What are you trying to implement?&lt;/p&gt;
&lt;p&gt;And what chip are you using?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/361799?ContentTypeID=1</link><pubDate>Tue, 05 Apr 2022 10:26:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:775a70ea-4313-47bb-93fa-a8057b7c0389</guid><dc:creator>ChrtistophAT</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;thank you for your digging. I was&amp;nbsp; digging to a bit in VS Code debugger SDK Connect 1.9.1 on nRF5340DK with example code&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/too1/ncs-peripheral-uart-adc/tree/d575cdb9a2e0d7e5f0984a6a228bcb0d3a6f1a7c"&gt;https://github.com/too1/ncs-peripheral-uart-adc/tree/d575cdb9a2e0d7e5f0984a6a228bcb0d3a6f1a7c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The only thing I had to chang for proper build and flash was the LOG_WRN() to simple printk(), afterwards got ADC raw value: 426 , 425 or 427&lt;/p&gt;
&lt;p&gt;I built up some voltagefollower opamp circuit and adjust (by poti VDD to GND) the output to 2.5V and measured with my multimeter.&lt;/p&gt;
&lt;p&gt;Should be 512 by 10bit resolution, so i changed ADC definitions to ADC_GAIN_1 and ADC_REFERENCE to&amp;nbsp;&lt;span&gt;ADC_REF_VDD_1.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Now adc_read() output err is -22 and raw value is 0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1649153586507v2.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;By digging I found&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	switch (channel_cfg-&amp;gt;reference) {
	case ADC_REF_INTERNAL:
		config.reference = NRF_SAADC_REFERENCE_INTERNAL;
		break;
	case ADC_REF_VDD_1_4:
		config.reference = NRF_SAADC_REFERENCE_VDD4;
		break;
	
	default:
		printk(&amp;quot;Selected ADC reference is not valid\n&amp;quot;);		//LOG_ERR
		return -EINVAL;
	}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;wanted to write the case for ADC_REF_VDD_1 by myself but in the nrf_saadc.h file&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;/** @brief Reference selection for the analog-to-digital converter. */
typedef enum
{
    NRF_SAADC_REFERENCE_INTERNAL = SAADC_CH_CONFIG_REFSEL_Internal, ///&amp;lt; Internal reference (0.6 V).
    NRF_SAADC_REFERENCE_VDD4     = SAADC_CH_CONFIG_REFSEL_VDD1_4    ///&amp;lt; VDD/4 as reference.
    
} nrf_saadc_reference_t;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;also no definition in the typdef enum ... why is this? Do I write all by myself or is ther better example ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My purpose: I have some analog signal amplification PCB and would like to digitize by nRF controller and send by BLE. The signal should be sampled by around 10-20us (10kHz of interrest, nyquist and so on). I would appreciate so much for some example code &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;would like to differentialy measure the signal to REF2.5 from the opamp pcb board, is the best way to measure differential mode or just single but referenced to REF2.5 through other AIN pin?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Many thanks in advance,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Christoph&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/353799?ContentTypeID=1</link><pubDate>Fri, 18 Feb 2022 10:09:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae828358-d3fa-424d-a166-9b4c1d36f59d</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Janpaul,&lt;/p&gt;
&lt;p&gt;I did some digging. The unmodified sample from the github seems to work well, but when you set the sampling rate to 17µs it seems to return an error. I tried to set it to 100µs (0.1ms), and in that case the error was not returned. I tried to debug, and traced it down to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static inline int adc_context_wait_for_completion(struct adc_context *ctx)
{
#ifdef CONFIG_ADC_ASYNC
	if (ctx-&amp;gt;asynchronous) {
		return 0;
	}
#endif /* CONFIG_ADC_ASYNC */

	k_sem_take(&amp;amp;ctx-&amp;gt;sync, K_FOREVER);
	return ctx-&amp;gt;status;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in adc_context.h.&lt;/p&gt;
&lt;p&gt;It is the return ctx-&amp;gt;status that returns -16.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I see that this probably happens because of this function (same file):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static inline void adc_context_complete(struct adc_context *ctx, int status)
{
#ifdef CONFIG_ADC_ASYNC
	if (ctx-&amp;gt;asynchronous) {
		if (ctx-&amp;gt;signal) {
			k_poll_signal_raise(ctx-&amp;gt;signal, status);
		}

		k_sem_give(&amp;amp;ctx-&amp;gt;lock);
		return;
	}
#endif /* CONFIG_ADC_ASYNC */

	/*
	 * Override the status only when an error is signaled to this function.
	 * Please note that adc_context_request_next_sampling() might have set
	 * this field.
	 */
	if (status != 0) {
		ctx-&amp;gt;status = status;
	}
	k_sem_give(&amp;amp;ctx-&amp;gt;sync);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;which again can comes from this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static inline void adc_context_request_next_sampling(struct adc_context *ctx)
{
	if (atomic_inc(&amp;amp;ctx-&amp;gt;sampling_requested) == 0) {
		adc_context_start_sampling(ctx);
	} else {
		/*
		 * If a sampling was already requested and was not finished yet,
		 * do not start another one from here, this will be done from
		 * adc_context_on_sampling_done() after the current sampling is
		 * complete. Instead, note this fact, and inform the user about
		 * it after the sequence is done.
		 */
		ctx-&amp;gt;status = -EBUSY;
	}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So the issue is that the new sample is requested before the previous sample is done. The sequence_options.interval_us is too small.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you particularly need an interval_us of 17, or was this a random test? The maximum sample rate of the ADC is 200kHz, so theoretically, it is possible to sample every 5µs, but not using the zephyr adc drivers. In that case I believe you would need to use the adc drivers directly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Let me know if you really need that short interval, or if that was just a test.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/353715?ContentTypeID=1</link><pubDate>Thu, 17 Feb 2022 20:16:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:941a7030-19f2-4fd1-98c9-4bb4dd9df30b</guid><dc:creator>jala</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;I searched the entire solution for the print statement, but nothing came up and I couldnt find what was returning the -16.&amp;nbsp; (I am using SEGGER studios)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Its almost identical to the github, I modified it to read from pin 5 instead of pin 4: #&lt;span class="pl-k"&gt;define&lt;/span&gt; &lt;span class="pl-en"&gt;ADC_1ST_CHANNEL_ID&lt;/span&gt; 1&lt;/p&gt;
&lt;p&gt;and I use the math library (math.h) to use some functions(sqrt, powf) on the samples I receive.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Again, I am open to other methods of setting the sampling rate.&lt;/p&gt;
&lt;p&gt;Thanks for the help,&lt;/p&gt;
&lt;p&gt;Janpaul&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Configure sampling rate for nrf5340 SAADC</title><link>https://devzone.nordicsemi.com/thread/353706?ContentTypeID=1</link><pubDate>Thu, 17 Feb 2022 19:09:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e55e1393-7502-43c3-9745-ae8bf7c21e0e</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;What function is it that returns -16? I see that it is adc_read(), but have you tried to investigate inside adc_read() to see why it returns -16?&lt;/p&gt;
&lt;p&gt;Also, did you do any modifications to the sample? Or is it exactly like the one I can download from the github that you refer to?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>