<?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 windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96922/adc-windows-mode-in-nrf-sdk-connect</link><description>Hi, 
 I was looking for the best solution for our case where an interrupt should be triggered/generated when the adc value is between two values (min and max) something like window mode. 
 
 SOC: nrf5340 
 SDK: 2.2.0 
 
 Thanks in advance!</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 23 Feb 2023 12:58:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96922/adc-windows-mode-in-nrf-sdk-connect" /><item><title>RE: adc windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/thread/411664?ContentTypeID=1</link><pubDate>Thu, 23 Feb 2023 12:58:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f9086f7-81e5-4a8a-9fe4-21e625b05d94</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Great, thanks for the update - I am happy to hear that you&amp;#39;ve got it working as intended now :)&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open another ticket if you should encounter any other issues or questions in the future!&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: adc windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/thread/411493?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 21:13:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f32f34f8-eba5-4905-98b5-d23be58b6dbc</guid><dc:creator>Mustafa</dc:creator><description>&lt;p&gt;[Update] I modified the code to this way and now looks more stable&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;	if (nrfx_comp_init (&amp;amp;config, comp_handler) == NRFX_SUCCESS) {
		IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_COMP), IRQ_PRIO_LOWEST, nrfx_comp_irq_handler,0);
		nrfx_comp_start(NRFX_COMP_EVT_EN_READY_MASK | NRFX_COMP_EVT_EN_DOWN_MASK | NRFX_COMP_EVT_EN_UP_MASK, 0);
	} else {
		LOG_ERR(&amp;quot;COMP init error&amp;quot;);
	}


    return 0;
}

void comp_handler(nrf_comp_event_t event) {
	gpio_pin_toggle_dt(&amp;amp;led);
	switch (event) {
		case NRF_COMP_EVENT_READY:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_READY&amp;quot;);
			break;
			
		case NRF_COMP_EVENT_DOWN:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_DOWN&amp;quot;);
			break;

		case NRF_COMP_EVENT_UP:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_UP&amp;quot;);
			break;

		case NRF_COMP_EVENT_CROSS:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_CROSS&amp;quot;);
			break;
		
		default:
			LOG_INF(&amp;quot;COMP : UNKOWN&amp;quot;);
			break;
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/thread/411490?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 20:48:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:121f411b-94af-49bc-90c5-036c1a958b06</guid><dc:creator>Mustafa</dc:creator><description>&lt;p&gt;Hi Karl,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have implemented the comp peripheral as it is shown below. in the beginning, when the application starts the comp works fine so every time I press the button it shows the correct log ( up or down) but after 10 times of pressing the switch, the comp becomes unstable. and shows two logs (up and down ) in one click. I&amp;#39;m not sure what I&amp;#39;m doing here wrong!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * @brief COMP driver default configuration.
 *
 * This configuration sets up COMP with the following options:
 * - single-ended mode
 * - reference voltage: internal VDD
 * - lower threshold: 0.5 V
 * - upper threshold: 1.0 V
 * - Normal speed mode
 * - hysteresis disabled
 * - current source disabled
 *
 * @param[in] _input Analog input.
 */
const nrfx_comp_config_t config = {
	.reference			=		NRF_COMP_REF_VDD,
	.main_mode			=		NRF_COMP_MAIN_MODE_SE,
	.threshold.th_up	=		NRFX_VOLTAGE_THRESHOLD_TO_INT(1.5, 3),
	.threshold.th_down	=		NRFX_VOLTAGE_THRESHOLD_TO_INT(0.5, 3),
	.speed_mode			=		NRF_COMP_SP_MODE_Normal,
	.hyst				=		NRF_COMP_HYST_50mV,
	.isource			=		NRF_COMP_ISOURCE_Off,
	.input				=		NRF_COMP_INPUT_0,
	.interrupt_priority	=		NRFX_COMP_DEFAULT_CONFIG_IRQ_PRIORITY
};
.......
	if (nrfx_comp_init (&amp;amp;config, comp_handler) == NRFX_SUCCESS) {
		IRQ_DIRECT_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_COMP), IRQ_PRIO_LOWEST, nrfx_comp_irq_handler,0);
		nrfx_comp_start(NRFX_COMP_EVT_EN_UP_MASK | NRFX_COMP_EVT_EN_DOWN_MASK, 
						NRFX_COMP_SHORT_STOP_AFTER_UP_EVT | NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT);
	} else {
		LOG_ERR(&amp;quot;COMP init error&amp;quot;);
	}
	

void comp_handler(nrf_comp_event_t event) {
	nrfx_comp_stop();
	switch (event) {
		case NRF_COMP_EVENT_READY:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_READY&amp;quot;);
			break;
			
		case NRF_COMP_EVENT_DOWN:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_DOWN&amp;quot;);
			nrfx_comp_start(NRFX_COMP_EVT_EN_UP_MASK, NRFX_COMP_SHORT_STOP_AFTER_UP_EVT);
			break;

		case NRF_COMP_EVENT_UP:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_UP&amp;quot;);
			nrfx_comp_start(NRFX_COMP_EVT_EN_DOWN_MASK, NRFX_COMP_SHORT_STOP_AFTER_DOWN_EVT);
			// gpio_pin_toggle_dt(&amp;amp;led);
			break;

		case NRF_COMP_EVENT_CROSS:
			LOG_INF(&amp;quot;COMP : NRF_COMP_EVENT_CROSS&amp;quot;);
			break;
		
		default:
			LOG_INF(&amp;quot;COMP : UNKOWN&amp;quot;);
			break;
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/thread/411313?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 10:28:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb4651f7-8086-43be-b3db-8553c38e0ac7</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Unfortunately we do not have an example in the nRF Connect SDK that demonstrates the COMP peripheral usage, but if you have any trouble using it please do not hesitate to let me know! :)&amp;nbsp;&lt;br /&gt;&lt;br /&gt;To pull in the nrfx_comp driver into your project you will need to set &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/kconfig/index.html#CONFIG_NRFX_COMP"&gt;CONFIG_NRFX_COMP=y&lt;/a&gt;&amp;nbsp;in your prj.conf, and you may then use the nrfx_comp.c file in your project. &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/master/drivers/include/nrfx_comp.h"&gt;You can use the nrfx_comp.h files as your API reference when working with this&lt;/a&gt;.&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: adc windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/thread/411254?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 07:55:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:703b2c88-d7ea-42fe-a4a1-e09444e4a884</guid><dc:creator>Mustafa</dc:creator><description>&lt;p&gt;Hey Karl,&lt;/p&gt;
&lt;p&gt;That is correct, I just need an event for entering and leaving the window area.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is there any example of how COMP can be used in nrf SDK connect (v2.2.0) that I can start with?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks again!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: adc windows mode in nrf sdk connect</title><link>https://devzone.nordicsemi.com/thread/411248?ContentTypeID=1</link><pubDate>Wed, 22 Feb 2023 07:31:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05fcb219-ad94-4362-93f1-3a3982a4f16f</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Do you only need an event for when this area is entered and left?&lt;br /&gt;If so, you&amp;nbsp;could use &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/comp.html"&gt;the COMP&lt;/a&gt; or &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/lpcomp.html"&gt;LPCOMP&lt;/a&gt;&amp;nbsp;peripherals for this, for instance.&lt;br /&gt;&lt;br /&gt;Please elaborate on your requirements if this is not what you are looking for.&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>