<?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>ADC channels scrambled</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/104911/adc-channels-scrambled</link><description>My ADC overlay file looks like this (the same for all 8 channels): 
 
 And my ADC read code looks like this: 
 
 The problem I&amp;#39;m seeing is that, when I use a voltage source to test them, the ADC channels are scrambled. My device-tree overlay calls out</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 25 Oct 2023 21:25:18 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/104911/adc-channels-scrambled" /><item><title>RE: ADC channels scrambled</title><link>https://devzone.nordicsemi.com/thread/452374?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 21:25:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4168be1-73db-473e-a8fb-52994e967c4d</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;I found the problem here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
	zephyr,user {
		// compatible = &amp;quot;nordic,nrf-adc&amp;quot;;
		io-channels = &amp;lt;&amp;amp;adc 0&amp;gt;, &amp;lt;&amp;amp;adc 1&amp;gt;, &amp;lt;&amp;amp;adc 2&amp;gt;, &amp;lt;&amp;amp;adc 3&amp;gt;, &amp;lt;&amp;amp;adc 4&amp;gt;, &amp;lt;&amp;amp;adc 5&amp;gt;, &amp;lt;&amp;amp;adc 6&amp;gt;, &amp;lt;&amp;amp;adc 7&amp;gt;;
	};
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I had left out channel 3 because I&amp;#39;m using that pin for the UART CTS signal. And that caused all subsequent channels above channel 2 to be incorrect. What is the correct way to make sure the CTS pin doesn&amp;#39;t get mapped to an ADC channel?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC channels scrambled</title><link>https://devzone.nordicsemi.com/thread/452369?ContentTypeID=1</link><pubDate>Wed, 25 Oct 2023 20:27:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a909f35-8f5f-485a-9525-6fab801b7088</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;One piece of context that I should add is that my ADC setup comes from Nordic advice given in this thread:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/101561/zephyr-adc-init-in-device-tree-versus-runtime"&gt;Zephyr adc init in device tree versus runtime&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here&amp;#39;s where the device tree overlay example comes from:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/v3.3.99-ncs1/samples/drivers/adc"&gt;github.com/.../adc&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note that none of the device tree examples have a &amp;quot;compatible&amp;quot; line in the zephyr,user node, even though the SDK seems to flag a warning.&lt;/p&gt;
&lt;p&gt;Note that some of the board files have the comment /* adjust channel number according to pinmux in board.dts */ in the zephyr,user node. But it&amp;#39;s not clear &lt;strong&gt;which&lt;/strong&gt; board.dts file is being used. In my case, I think I&amp;#39;m referencing the wrong one, but I don&amp;#39;t know how to tell.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s another overlay example where they actually have the pin numbers shown as comments in the file. But in my build those defines don&amp;#39;t get resolved to pin numbers at all:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.3.99-ncs1/samples/drivers/adc/boards/nrf52840dk_nrf52840.overlay"&gt;github.com/.../nrf52840dk_nrf52840.overlay&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC channels scrambled</title><link>https://devzone.nordicsemi.com/thread/452099?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2023 23:05:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f3b5d6a4-690f-4a24-9eb4-f6bed165de32</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;I think I see the problem in my device tree overlay:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/ {
	zephyr,user {
		// compatible = &amp;quot;nordic,nrf-adc&amp;quot;;
		io-channels = &amp;lt;&amp;amp;adc 0&amp;gt;, &amp;lt;&amp;amp;adc 1&amp;gt;, &amp;lt;&amp;amp;adc 2&amp;gt;, &amp;lt;&amp;amp;adc 4&amp;gt;, &amp;lt;&amp;amp;adc 5&amp;gt;, &amp;lt;&amp;amp;adc 6&amp;gt;, &amp;lt;&amp;amp;adc 7&amp;gt;;
	};
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;There&amp;#39;s a warning that zephyr,user node should have a &amp;quot;compatible&amp;quot; property. I tried adding that property (commented out in the code above) but got a device tree error in my build. What should be the proper device tree compatible line for this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC channels scrambled</title><link>https://devzone.nordicsemi.com/thread/452097?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2023 22:53:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2bd4b5f-fcba-4930-beb8-a8941aaac5af</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;I&amp;#39;m pretty sure this C-code is where the magic happens. But it&amp;#39;s not clear where these macros are picking up the (incorrect) channel-to-pin mapping.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
#define DT_SPEC_AND_COMMA(node_id, prop, idx) \
	ADC_DT_SPEC_GET_BY_IDX(node_id, idx),

/* Data of ADC io-channels specified in devicetree. */
static const struct adc_dt_spec adc_channels[] = {
	DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels,
			     DT_SPEC_AND_COMMA)
};
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC channels scrambled</title><link>https://devzone.nordicsemi.com/thread/452084?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2023 20:05:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c041de4-25ef-43d3-ac37-6a7a358bfea9</guid><dc:creator>Bret Foreman</dc:creator><description>&lt;p&gt;By &amp;quot;scrambled&amp;quot; I mean that the voltage on a pin that&amp;#39;s supposed to be associated with one channel reads back on another. Not all are wrong, though. For instance, AIN2 reads back the correct voltage. But the AIN5 &amp;quot;channel&amp;quot; reads the voltage on the AIN6 &amp;quot;pin&amp;quot;&amp;nbsp;and AIN6 &amp;quot;channel&amp;quot; reads the voltage on the AIN7 &amp;quot;pin&amp;quot; and the AIN4 &amp;quot;channel&amp;quot; reads the voltage on the AIN6 &amp;quot;pin&amp;quot;.&lt;/p&gt;
&lt;p&gt;I suspect there is some incorrect bit shifting going on somewhere down in the driver. But it&amp;#39;s pretty hard to figure out where that stuff happens.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC channels scrambled</title><link>https://devzone.nordicsemi.com/thread/451926?ContentTypeID=1</link><pubDate>Tue, 24 Oct 2023 09:56:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7dac126-fcd8-4ab9-aaa1-ad996ad403d6</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]when I use a voltage source to test them, the ADC channels are scrambled.[/quote]
&lt;p&gt;Could you elaborate on what you mean when you say that the channels are scrambled?&lt;br /&gt;For instance, do you see that when you set a voltage of X on the Y pin, the log shows a difference in the Z channel measurements, or something else?&lt;br /&gt;&lt;br /&gt;In general, &lt;a href="https://github.com/jorhol/NCS-SAADC-samples"&gt;I highly recommend taking a look at these 2 example projects to see a demonstration of the two primary recommended ways to use the SAADC in the nRF Connect SDK&lt;/a&gt;, which is the approach similar to what you are doing now (CPU triggered sampling), and PPI based sampling.&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></channel></rss>