<?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>Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100535/sampling-nrf5340-adc-at-8-khz</link><description>Hello, 
 
 I am trying to accurately sample the ADC on the nRF5340 at 8 kHz. I am trying to do this for 5 channels. However, when I try to acquire 8000 samples from each channel, the program takes over 6 seconds to finish, instead of the expected 1 second</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Jul 2023 10:50:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100535/sampling-nrf5340-adc-at-8-khz" /><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/434432?ContentTypeID=1</link><pubDate>Tue, 04 Jul 2023 10:50:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91d6cc61-9759-4afa-9047-336dc4921aad</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Håkon has left for vacation. This case was slightly lengthy and due to many take summer vacation within the support team we likely will not be able to dig into this. In general if you have problems with timing I suggest to add debug signals (e.g. gpios) to find what may be taking time and ensure that you execute tasks as expected.&lt;/p&gt;
&lt;p&gt;enneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/434272?ContentTypeID=1</link><pubDate>Mon, 03 Jul 2023 15:08:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2db6809c-eb41-4a82-82ef-f9370a921989</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;In the overlay file, I have set the acquisition time for each channel to&amp;nbsp;ADC_ACQ_TIME_DEFAULT, which should be 0.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/434037?ContentTypeID=1</link><pubDate>Sat, 01 Jul 2023 00:45:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef5bc82e-e3b3-4010-b792-a8fdf6a82fc1</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I don&amp;#39;t know. What are the channel acquisition times? If they total over 115us then you&amp;#39;ve maxed out your sample rate and the SAMPLE task is triggered before the SAADC is ready to sample again. Then you&amp;#39;ll have to wait 125us for the next SAMPLE task.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/433834?ContentTypeID=1</link><pubDate>Fri, 30 Jun 2023 06:12:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f896e0ea-048f-46e2-a6c8-e8f314da3bf6</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Thanks for the suggestions. I figured out what I was doing wrong with the channels; needed to update the channels bit-mask in the adc_sequence struct (lines 66-68) in the file I will attach. Also got some help from the Zephyr adc_api test code (&lt;a id="" href="https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/adc/adc_api/src/test_adc.c"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/adc/adc_api/src/test_adc.c&lt;/a&gt;).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The good news is that sampling now takes the same amount of time regardless of how many channels are enabled. It also takes a reasonable amount of time at 2 kHz (when the interval_us field of the adc_sequence_options is set to 500), roughly 1.038 seconds to perform 2000 reads, which is just slightly more than the expected 1 second runtime.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, when I increase the sampling rate to 8 kHz (interval_us = 125) and try to perform 8000 reads, it takes 1.221 seconds instead of exactly 1 second. This always happens regardless of the number of channels I have enabled. What is the reason for this taking so much longer than expected?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/00680.main.c"&gt;devzone.nordicsemi.com/.../00680.main.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/433656?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 11:14:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f85db313-f273-4b01-9c88-d63d8535ec42</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;See v2.4.0\zephyr\drivers\adc\adc_nrfx_saadc.c:286&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static int start_read(const struct device *dev,
		      const struct adc_sequence *sequence)
{
	int error;
	uint32_t selected_channels = sequence-&amp;gt;channels;
	uint8_t active_channels;
	uint8_t channel_id;

	/* Signal an error if channel selection is invalid (no channels or
	 * a non-existing one is selected).
	 */
	if (!selected_channels ||
	    (selected_channels &amp;amp; ~BIT_MASK(SAADC_CH_NUM))) {
		LOG_ERR(&amp;quot;Invalid selection of channels&amp;quot;);
		return -EINVAL;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Set a breakpoint and find the value of &amp;#39;selected_channels&amp;#39;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-edit:&amp;nbsp;&lt;br /&gt;Good catch on the buffer being allocated to the stack.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can declare the buffer as a global static variable, then main&amp;#39;s stack size should be independen of the buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Note that if you use a FIFO queue to transfer the content of the buffer to another thread you will need to increase the stack size anyways.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you break up the sampling sequence into multiple sequences you can reduce the required stack size considerably. This is typically how it is done in most multi-threaded applications.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/433365?ContentTypeID=1</link><pubDate>Wed, 28 Jun 2023 07:15:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:555cc5ac-57a5-4f8e-832d-3bf4893e6080</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Update to my previous message. I was able to fix the stack overflow error by just increasing the stack size. I added the line&amp;nbsp;&lt;span&gt;CONFIG_MAIN_STACK_SIZE&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;102400 to the prj.conf file. Makes sense because I was trying to allocate a very large array inside the main function.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;However, I am getting a new error now:&amp;nbsp;&amp;lt;err&amp;gt; adc_nrfx_saadc: Invalid selection of channels&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Any ideas on what the cause of this might be? I am uploading the code, overlay, and conf files with this message.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for your help.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/8625.nrf5340dk_5F00_nrf5340_5F00_cpuapp_5F00_ns.overlay"&gt;devzone.nordicsemi.com/.../8625.nrf5340dk_5F00_nrf5340_5F00_cpuapp_5F00_ns.overlay&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3857.prj.conf"&gt;devzone.nordicsemi.com/.../3857.prj.conf&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/444860.main.c"&gt;devzone.nordicsemi.com/.../444860.main.c&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/432870?ContentTypeID=1</link><pubDate>Mon, 26 Jun 2023 08:12:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68b251b1-bc6e-4606-b191-6a82d859eed7</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Hi haakonsh,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Sorry for the delay. Here is the code:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/1464.main.c"&gt;devzone.nordicsemi.com/.../1464.main.c&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/432338?ContentTypeID=1</link><pubDate>Wed, 21 Jun 2023 13:24:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66269c82-165e-4365-bbf4-80cc848f612c</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I don&amp;#39;t know why you&amp;#39;re getting a stack overflow, you&amp;#39;ll have to share your code. The most common reasons for a stack overflow is when you call functions in an infinite loop before previous calls have returned(Stack frames are continuously added while&amp;nbsp;never being removed), or the stack size is set to low for given context that would otherwise run without issues (f.ex you need 10 stack frames on the stack, but can only fit 10).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/432129?ContentTypeID=1</link><pubDate>Tue, 20 Jun 2023 19:28:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32b2eee3-5a01-4b33-a649-6066a9a99693</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Hi haakonsh,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you very much for explaining.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have tried to implement everything you have said, and it successfully builds. However, I get this error message repeatedly:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v3.3.99-ncs1 ***&lt;/p&gt;
&lt;p&gt;[00:00:00.253,631] &amp;lt;err&amp;gt; os: ***** USAGE FAULT *****&lt;br /&gt;[00:00:00.253,662] &amp;lt;err&amp;gt; os: Stack overflow (context area not valid)&lt;br /&gt;[00:00:00.253,662] &amp;lt;err&amp;gt; os: r0/a1: 0xfffffff5 r1/a2: 0xe000ed00 r2/a3: 0x20009094&lt;br /&gt;[00:00:00.253,662] &amp;lt;err&amp;gt; os: r3/a4: 0x00000001 r12/ip: 0x2000a0d8 r14/lr: 0x00016ff9&lt;br /&gt;[00:00:00.253,692] &amp;lt;err&amp;gt; os: xpsr: 0x61000000&lt;br /&gt;[00:00:00.253,692] &amp;lt;err&amp;gt; os: Faulting instruction address (r15/pc): 0x00010426&lt;br /&gt;[00:00:00.253,723] &amp;lt;err&amp;gt; os: &amp;gt;&amp;gt;&amp;gt; ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0&lt;br /&gt;[00:00:00.253,753] &amp;lt;err&amp;gt; os: Current thread: 0x200087f0 (main)&lt;br /&gt;[00:00:00.500,183] &amp;lt;err&amp;gt; fatal_error: Resetting system&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do you know what might be causing this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/431698?ContentTypeID=1</link><pubDate>Mon, 19 Jun 2023 10:09:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1144d437-2c52-4c4f-94ad-1b12dc861df0</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Try:&amp;nbsp;DEVICE_DT_GET_ONE(nordic_nrf_saadc)&lt;/p&gt;
[quote user="shamboozled"]Secondly, don&amp;#39;t each of the ADC channels have separate device nodes? Why are we only using one device when trying to sample 5 different channels? I apologize if I have misunderstood how this works.[/quote]
&lt;p&gt;The channels are represented as&amp;nbsp;different devicetree nodes, but they all share the same HW peripheral and driver instance. See&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/saadc.html?cp=4_0_0_6_28"&gt;SAADC — Successive approximation analog-to-digital converter&lt;/a&gt;&amp;nbsp;specifications.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In short, the SAADC will sample all enabled channels in rapid succession once every time the SAMPLE task is triggered. Once the given buffer has been filled the SAADC will send the END event to signal that the data has been sampled and is safe to process. Zephyr&amp;#39;s ADC device driver&amp;nbsp;implementation(nrfx saadc driver) will raise the given k_poll signal when it receives the END event.&lt;/p&gt;
&lt;p&gt;This means that you only need to instruct Zephyr&amp;#39;s ADC driver to sample X channels at Y sample rate for Z amount of samples and wait for the given k_poll signal to be raised.&lt;/p&gt;
&lt;p&gt;When a thread waits for a K_poll signal it will suspended until the signal has been raised. This means that you are supposed to use a dedicated thread for handling this signal so that the rest of your application is free to do whatever it needs to do(asynchroneous operation).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/431557?ContentTypeID=1</link><pubDate>Fri, 16 Jun 2023 16:29:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0155f0c1-ec22-4906-befe-3b68827fd52a</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Hi haakonsh,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for your response. Sorry for the delay on my end.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am confused by the first line in your code:&amp;nbsp;#define adc_dev DT_INST(0, nordic_nrf_saadc)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First, I get this error when trying to build:&amp;nbsp;error: &amp;#39;DT_N_S_soc_S_peripheral_40000000_S_adc_e000&amp;#39; undeclared (first use in this function); did you mean &amp;#39;DT_N_S_soc_S_peripheral_40000000_S_adc_e000_ORD&amp;#39;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Secondly, don&amp;#39;t each of the ADC channels have separate device nodes? Why are we only using one device when trying to sample 5 different channels? I apologize if I have misunderstood how this works.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/430288?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 15:48:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:989f7f94-0244-4507-89fd-3417cdd918cf</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hmm, looks like you don&amp;#39;t need to define a callback function, but you do need to define a k_poll_signal that will be set when a given sampling sequence has finished.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define adc_dev DT_INST(0, nordic_nrf_saadc)

struct k_poll_signal adc_signal;

int main(void)
{
	int err;
	int16_t[8000][5] buf;
	
	struct adc_sequence_options options = {
		.interval_us = 125,
		.extra_samplings = 8000 - 1
	};

	struct adc_sequence sequence = {
		.buffer = &amp;amp;buf,
		.buffer_size = sizeof(buf),
		.options = &amp;amp;options,
		.resolution = 12
	};

	config_adc_channels();
	
	k_poll_signal_init(&amp;amp;adc_signal)
	
	struct k_poll_event adc_events[1] = {
        K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
                                 K_POLL_MODE_NOTIFY_ONLY,
                                 &amp;amp;signal),
    };

	int64_t start = k_uptime_get();
	
	err = adc_read_async(adc_dev);
	
    err = k_poll(adc_events, 1, K_FOREVER);
    if(err != 0)
    {
        //Handle error!
        printk(&amp;quot;k_poll returned error: %i&amp;quot;, err);
    }
	printk(&amp;quot;time elapsed in ms: %&amp;quot; PRId64 &amp;quot;\n&amp;quot;, k_uptime_delta(&amp;amp;start));
    
    if(adc_events[0].signal-&amp;gt;signaled){
        //ADC has sampled all 5 channels 8000 times
        
    	for (uint16_t j = 0; j &amp;lt; 8000; j++) {
    		printk(&amp;quot;ADC reading[%hu]:\n\n&amp;quot;, j);
    		
    		for (uint8_t i = 0U; i &amp;lt; 5; i++) {
    			printk(&amp;quot;adc channel: %u     val: %hi\n&amp;quot;, i, buf[j][i]);
    		}
    	}
    	
    	adc_events[0].signal-&amp;gt;signaled = 0;
    	adc_events[0].state = K_POLL_STATE_NOT_READY;
    }

	return 0;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/430056?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2023 17:17:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6a77d4e-8867-4b8d-a861-0936393506d3</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;I have not. I am not sure how to approach that. Is there some sample code I can look at that will help with this? If not, can you explain to me how&amp;nbsp;I should approach implementing them?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/429960?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2023 11:14:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18b60059-1015-482d-a8ae-c0bba9f801fb</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Have you implemented the polling signal and adc callback?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/429854?ContentTypeID=1</link><pubDate>Wed, 07 Jun 2023 20:25:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fa691b0-210b-48b5-b473-0c9da42ca3ac</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Realized that I needed to add&amp;nbsp;&lt;span&gt;CONFIG_ADC_ASYNC&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;y to the config file. However, it still takes longer than expected to sample 5 channels at 8 kHz. In my main.c file, I try to perform 8000 reads for 5 channels&amp;nbsp;of the ADC. This should only take 1 second, but it instead takes more like 6 seconds. When I only try one channel, it takes about 1 second. Why does adding more channels slow down the execution so much?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/429846?ContentTypeID=1</link><pubDate>Wed, 07 Jun 2023 19:02:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1b45573-3dc2-4e4c-9509-15f64129dcb2</guid><dc:creator>shamboozled</dc:creator><description>&lt;p&gt;Hi haakonsh,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for getting back to me. I tried directly swapping the adc_read call to an adc_read_async (line 97 in main.c). However, I get this error:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map &lt;br /&gt;cmd.exe /C &amp;quot;cd . &amp;amp;&amp;amp; C:\ncs\toolchains\31f4403e35\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf -fuse-ld=bfd -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=C:/nordic/myApps/analog_in/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/subsys/random/libsubsys__random.a zephyr/drivers/adc/libdrivers__adc.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/entropy/libdrivers__entropy.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/mbox/libdrivers__mbox.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/modules/tfm/zephyr/libtfm_api_nrf.a modules/trusted-firmware-m/libtfm_api.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a modules/segger/libmodules__segger.a modules/nrfxlib/nrfxlib/nrf_security/src/zephyr/libmbedtls_zephyr.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L&amp;quot;c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp&amp;quot; -LC:/nordic/myApps/analog_in/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a tfm/secure_fw/s_veneers.o -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -Wl,-no-pie modules/nrfxlib/nrfxlib/nrf_security/src/libmbedcrypto.a C:/ncs/v2.4.0/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_mbedtls_3.0.13.a modules/nrfxlib/nrfxlib/nrf_security/src/libmbedcrypto_base.a -mcpu=cortex-m33 -mthumb -mabi=aapcs C:/ncs/v2.4.0/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_3.0.13.a &amp;amp;&amp;amp; cmd.exe /C &amp;quot;cd /D C:\nordic\myApps\analog_in\build\zephyr &amp;amp;&amp;amp; C:\ncs\toolchains\31f4403e35\opt\bin\cmake.exe -E echo &amp;quot;&amp;quot;&lt;br /&gt;c:/ncs/toolchains/31f4403e35/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(main.c.obj): in function `adc_read_async&amp;#39;:&lt;br /&gt;C:\nordic\myApps\analog_in\build\zephyr\include\generated\syscalls\adc.h:83: undefined reference to `z_impl_adc_read_async&amp;#39;&lt;br /&gt;collect2.exe: error: ld returned 1 exit status&lt;br /&gt;ninja: build stopped: subcommand failed.&lt;br /&gt;FATAL ERROR: command exited with status 1: &amp;#39;c:\ncs\toolchains\31f4403e35\opt\bin\cmake.EXE&amp;#39; --build &amp;#39;c:\nordic\myApps\analog_in\build&amp;#39;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do you have any idea why this happens?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Sampling nRF5340 ADC at 8 kHz</title><link>https://devzone.nordicsemi.com/thread/429708?ContentTypeID=1</link><pubDate>Wed, 07 Jun 2023 09:11:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f593d0ab-c85c-4d31-8440-63f4eb8878d6</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;If you want to use Zephyr&amp;#39;s ADC device driver at 8kHz you&amp;#39;ll need to use &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/peripherals/adc.html#c.adc_read_async"&gt;adc_read_async&lt;/a&gt;, this api will use a sw timer to periodically sample the ADC&lt;span&gt;. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Another option is to use the nrfx saadc driver directly with a hw timer to trigger the sampling sequence.&amp;nbsp;See&amp;nbsp;ncs\v2.4.0\modules\hal\nordic\nrfx\samples\src\nrfx_saadc\simple_non_blocking\README.md.&lt;br /&gt;&lt;br /&gt; FYI using the nrfx driver directly will offload the CPU a lot, especially true at 8kHz.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>