<?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 Peripheral Power Management on NRF52840 (BMD-340)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119175/adc-peripheral-power-management-on-nrf52840-bmd-340</link><description>OS: Windows 11 Pro 
 OS Version: 10.0.22631 
 Toolchain: nRF Connect SDK (VS Code Extension) version 2.9.0 
 Hardware: BMD-340 
 Our Implementation requires disabling the ADC peripheral while not in use to conserve power. 
 Issue: While attempting to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Mar 2025 09:39:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119175/adc-peripheral-power-management-on-nrf52840-bmd-340" /><item><title>RE: ADC Peripheral Power Management on NRF52840 (BMD-340)</title><link>https://devzone.nordicsemi.com/thread/525672?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 09:39:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5baeb1d7-c336-4b90-b00a-65839abb80f1</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am sorry for the very late reply. You are right, when using the Zephyr blocking API there is no stop. It is also not needed in this case, and you only need to enable device power management in Kconfig, and it will be handled automatically under the holld. That can be demonstrated by using the &lt;a href="https://devzone.nordicsemi.com/support-private/support/341115/zephyr/samples/drivers/adc/adc_dt"&gt;adc_dt sample&lt;/a&gt; from SDK 2.9, with this added to prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_PM_DEVICE=y
CONFIG_PM_DEVICE_RUNTIME=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, the sample will continue to consume a significant amount of current in sleep due to the UART being enabled, so I modified the sample like this to sample for a short time and then also disable the UART. If you measure the current consumption of this, you&amp;nbsp;should see a low sleep current as expected:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2020 Libre Solar Technologies GmbH
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;inttypes.h&amp;gt;
#include &amp;lt;stddef.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;

#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/adc.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/sys/printk.h&amp;gt;
#include &amp;lt;zephyr/sys/util.h&amp;gt;
#include &amp;lt;zephyr/pm/device.h&amp;gt;
#include &amp;lt;zephyr/pm/device_runtime.h&amp;gt;

#if !DT_NODE_EXISTS(DT_PATH(zephyr_user)) || \
	!DT_NODE_HAS_PROP(DT_PATH(zephyr_user), io_channels)
#error &amp;quot;No suitable devicetree overlay specified&amp;quot;
#endif

#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)
};

void uart_suspend(void)
{
	static const struct device *const console_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));

	/* Disable console UART */
	int err = pm_device_action_run(console_dev, PM_DEVICE_ACTION_SUSPEND);
	if (err &amp;lt; 0)
	{
		printk(&amp;quot;Unable to suspend console UART. (err: %d)\n&amp;quot;, err);
	}
}

int main(void)
{
	int err;
	uint32_t count = 0;
	uint16_t buf;
	struct adc_sequence sequence = {
		.buffer = &amp;amp;buf,
		/* buffer size in bytes, not number of samples */
		.buffer_size = sizeof(buf),
	};
	/* Configure channels individually prior to sampling. */
	for (size_t i = 0U; i &amp;lt; ARRAY_SIZE(adc_channels); i++) {
		if (!adc_is_ready_dt(&amp;amp;adc_channels[i])) {
			printk(&amp;quot;ADC controller device %s not ready\n&amp;quot;, adc_channels[i].dev-&amp;gt;name);
			return 0;
		}

		err = adc_channel_setup_dt(&amp;amp;adc_channels[i]);
		if (err &amp;lt; 0) {
			printk(&amp;quot;Could not setup channel #%d (%d)\n&amp;quot;, i, err);
			return 0;
		}
	}

	for (int k = 0; k &amp;lt; 2; k++) {
		printk(&amp;quot;ADC reading[%u]:\n&amp;quot;, count++);
		for (size_t i = 0U; i &amp;lt; ARRAY_SIZE(adc_channels); i++) {
			int32_t val_mv;

			printk(&amp;quot;- %s, channel %d: &amp;quot;,
			       adc_channels[i].dev-&amp;gt;name,
			       adc_channels[i].channel_id);

			(void)adc_sequence_init_dt(&amp;amp;adc_channels[i], &amp;amp;sequence);

			err = adc_read_dt(&amp;amp;adc_channels[i], &amp;amp;sequence);
			if (err &amp;lt; 0) {
				printk(&amp;quot;Could not read (%d)\n&amp;quot;, err);
				continue;
			}

			/*
			 * If using differential mode, the 16 bit value
			 * in the ADC sample buffer should be a signed 2&amp;#39;s
			 * complement value.
			 */
			if (adc_channels[i].channel_cfg.differential) {
				val_mv = (int32_t)((int16_t)buf);
			} else {
				val_mv = (int32_t)buf;
			}
			printk(&amp;quot;%&amp;quot;PRId32, val_mv);
			err = adc_raw_to_millivolts_dt(&amp;amp;adc_channels[i],
						       &amp;amp;val_mv);
			/* conversion to mV may not be supported, skip if not */
			if (err &amp;lt; 0) {
				printk(&amp;quot; (value in mV not available)\n&amp;quot;);
			} else {
				printk(&amp;quot; = %&amp;quot;PRId32&amp;quot; mV\n&amp;quot;, val_mv);
			}
		}

		k_sleep(K_MSEC(1000));
	}

	uart_suspend();

	// Wait forever
	while (1) {
		k_sleep(K_MSEC(1000));
	}

	return 0;
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Peripheral Power Management on NRF52840 (BMD-340)</title><link>https://devzone.nordicsemi.com/thread/524134?ContentTypeID=1</link><pubDate>Fri, 21 Feb 2025 15:22:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39c82ac5-b7f7-4605-88ce-4bc87b35e159</guid><dc:creator>rschimandle</dc:creator><description>&lt;p&gt;There is no &amp;quot;stop&amp;quot; API call, how do you stop the sample sequence? If there is not a way to explicitly stop the sample sequence can i configure for &amp;quot;single sample&amp;quot; or &amp;quot;single shot&amp;quot; mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ADC Peripheral Power Management on NRF52840 (BMD-340)</title><link>https://devzone.nordicsemi.com/thread/524104?ContentTypeID=1</link><pubDate>Fri, 21 Feb 2025 13:52:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0395c6f-6aad-45b9-a166-1f4967e6d281</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Do yo make sure to stop ongoin sampling before calling your&amp;nbsp;ADC_Disable() function?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>