<?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>NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/122507/nrf54l15-dk-adc-threshold-event-configuration-using-lpcomp-and-anadetect</link><description>Hello Nordic Team, 
 I am currently working with the NRF54L15-DK. I have successfully configured the simple ADC on AIN4 (P1.11) and am able to read the raw sensor values. 
 Overlay : 
 However, I would like to understand how to configure and set an ADC</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 29 Jul 2025 13:40:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/122507/nrf54l15-dk-adc-threshold-event-configuration-using-lpcomp-and-anadetect" /><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/543965?ContentTypeID=1</link><pubDate>Tue, 29 Jul 2025 13:40:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55344fbf-1d30-4574-b493-a0f7748609b2</guid><dc:creator>runsiv</dc:creator><description>&lt;p&gt;Just an update, the designer in on vacation until Monday. I will update next week&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Runar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/543239?ContentTypeID=1</link><pubDate>Tue, 22 Jul 2025 16:44:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3883ad90-9891-41b4-8770-deeb4d944cf3</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for the confirmation. We need to look into whether this is a bug in documentation, and I do hope we can get back to you within a week or two in order to confirm what are the correct formulas.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/542946?ContentTypeID=1</link><pubDate>Mon, 21 Jul 2025 04:57:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac1f5dc2-33c0-4629-9df8-2b0a7ab1d598</guid><dc:creator>Pratik Panchal</dc:creator><description>&lt;p&gt;Hello Terje,&lt;br /&gt;&lt;br /&gt;Thank you for your response.&lt;/p&gt;
&lt;p data-start="135" data-end="279"&gt;If we define the threshold levels (UP/DOWN) and compare them with the corresponding voltage, we can easily map them using the following formula:&lt;em&gt;&lt;strong&gt; (previous response attached mapping file )&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;ul data-start="281" data-end="348"&gt;
&lt;li data-start="281" data-end="317"&gt;
&lt;p data-start="283" data-end="317"&gt;VDOWN = (THDOWN + 1) / 32 * VREF&lt;/p&gt;
&lt;/li&gt;
&lt;li data-start="318" data-end="348"&gt;
&lt;p data-start="320" data-end="348"&gt;VUP = (THUP + 1) / 32 * VREF&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p data-start="350" data-end="467"&gt;However, the threshold-to-voltage mapping described in the &lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/comp.html#register.TH"&gt;Comparator documentation&lt;/a&gt;&amp;nbsp;does not align with this formula.&lt;br /&gt;&lt;br /&gt;Thanks &amp;amp; Regards,&lt;br /&gt;Pratik Panchal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/542781?ContentTypeID=1</link><pubDate>Thu, 17 Jul 2025 14:07:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23280bb0-ac69-4fb2-8404-28c350357338</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Key person is away, and we will need to look back into this when they are back in 2 weeks.&lt;/p&gt;
&lt;p&gt;In the interim: Does the thresholds work at the correct levels, if you assume the following formulas for setting the threshold values?&lt;/p&gt;
&lt;p&gt;VDOWN = (THDOWN+1)/32*VREF&lt;br /&gt;VUP = (THUP+1)/32*VREF&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/542490?ContentTypeID=1</link><pubDate>Tue, 15 Jul 2025 09:17:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32fc357a-4b86-40e9-b2f3-b96aabaf781e</guid><dc:creator>Pratik Panchal</dc:creator><description>&lt;p&gt;Hello Nordic Team,&lt;br /&gt;&lt;br /&gt;Could you please answer my query?&lt;br /&gt;&lt;br /&gt;Regards,&lt;br /&gt;Pratik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/542003?ContentTypeID=1</link><pubDate>Thu, 10 Jul 2025 04:00:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c55e52cc-b673-4857-8074-c529fe829a8d</guid><dc:creator>Pratik Panchal</dc:creator><description>&lt;p data-start="132" data-end="146"&gt;Hello Kenneth,&lt;/p&gt;
&lt;p data-start="148" data-end="237"&gt;Just a quick reminder&amp;mdash;have there been any updates or findings regarding my query?&lt;br /&gt;&lt;br /&gt;Thanks &amp;amp; Regards,&lt;br /&gt;Pratik&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/540872?ContentTypeID=1</link><pubDate>Mon, 30 Jun 2025 12:48:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2abc390-3914-4deb-95d0-2d9ef82b5fbc</guid><dc:creator>Pratik Panchal</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p data-start="75" data-end="103"&gt;Thank you for your response.&lt;/p&gt;
&lt;p data-start="105" data-end="198"&gt;I have reviewed the documents you provided and, based on that, I have defined the comparator.&lt;/p&gt;
&lt;p data-start="200" data-end="262"&gt;The comparator configuration is provided below in the overlay.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.Overlay&lt;/strong&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;amp;comp {
	compatible = &amp;quot;nordic,nrf-comp&amp;quot;;
	main-mode = &amp;quot;SE&amp;quot;;
	psel = &amp;quot;AIN4&amp;quot;; /* P1.11 */
	refsel = &amp;quot;VDD&amp;quot;;
	sp-mode = &amp;quot;HIGH&amp;quot;;
	th-up = &amp;lt;63&amp;gt;;
	th-down = &amp;lt;31&amp;gt;;//&amp;lt;59&amp;gt;;
	isource = &amp;quot;DISABLED&amp;quot;;
	enable-hyst;
	status = &amp;quot;okay&amp;quot;;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p data-start="64" data-end="238"&gt;and define the &lt;strong&gt;&lt;code data-start="82" data-end="101"&gt;init_comparator()&lt;/code&gt;&lt;/strong&gt; function and the IRQ interrupt. When the threshold is crossed (either upward or downward), the function&amp;nbsp;&lt;strong&gt;&lt;code data-start="197" data-end="219"&gt;comp_event_handler()&lt;/code&gt;&lt;/strong&gt; should be invoked.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Code:&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//comparator node
static const struct device *test_dev = DEVICE_DT_GET(DT_ALIAS(test_comp));

bool event_flag = true;  //&amp;lt;----------- this flag needed because sometime when we adc fall from up to down then both event triggered down and up

void comp_event_handler(void)
{
   if (NRF_COMP-&amp;gt;EVENTS_UP) {
		if(!event_flag)
		{
			printk(&amp;quot;\tEVENTS_UP &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; : [%d]\n&amp;quot;, NRF_COMP-&amp;gt;EVENTS_UP);
        	NRF_COMP-&amp;gt;EVENTS_UP = 0;
			NRF_COMP-&amp;gt;EVENTS_DOWN = 0;
			event_flag = true;
		}
    }

	if (NRF_COMP-&amp;gt;EVENTS_DOWN)
	{
		if (event_flag)
		{
			printk(&amp;quot;\tEVENTS_DOWN &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; : [%d]\n&amp;quot;, NRF_COMP-&amp;gt;EVENTS_DOWN);
			NRF_COMP-&amp;gt;EVENTS_DOWN = 0;
			NRF_COMP-&amp;gt;EVENTS_UP = 0;
			event_flag = false;
		}
	}

int init_comparator()
{
struct comp_nrf_comp_se_config comp_config = {
		.psel = COMP_NRF_COMP_PSEL_AIN4,
		.sp_mode = COMP_NRF_COMP_SP_MODE_HIGH,
		.isource = COMP_NRF_COMP_ISOURCE_DISABLED,
		.refsel = COMP_NRF_COMP_REFSEL_VDD,
		.th_down = 5, //&amp;lt;---- up threshold  
		.th_up = 16, // &amp;lt;----- down threshold
	};
	comp_nrf_comp_configure_se(test_dev, &amp;amp;comp_config);
	
	// Configure event UP to publish
	NRF_COMP-&amp;gt;PUBLISH_UP = COMP_PUBLISH_UP_EN_Enabled;

	// Define handler for event UP
	NRF_COMP-&amp;gt;INTENSET = COMP_INTENSET_UP_Msk;

	// Check if the IRQ is already registered before connecting
	if (!irq_is_enabled(DT_IRQN(DT_NODELABEL(comp)))) {
		// Register the interrupt handler
		IRQ_CONNECT(DT_IRQN(DT_NODELABEL(comp)), DT_IRQ(DT_NODELABEL(comp), priority), comp_event_handler, NULL, 0);

		// Enable the interrupt
		irq_enable(DT_IRQN(DT_NODELABEL(comp)));
	} else {
		printk(&amp;quot;IRQ %d is already registered.\n&amp;quot;, DT_IRQN(DT_NODELABEL(comp)));
	}
	
		// Enable and start COMP
	NRF_COMP-&amp;gt;ENABLE = 2;
	NRF_COMP-&amp;gt;TASKS_START = 1;
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Proj.conf&lt;/strong&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Comparator
CONFIG_COMPARATOR=y
CONFIG_NRFX_COMP=y
CONFIG_SHARED_INTERRUPTS=y&lt;/pre&gt;&lt;/p&gt;
&lt;p data-start="240" data-end="323"&gt;According to the formula provided in the &lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/comp.html#ariaid-title7:~:text=GPIO%20Port%20selection-,TH,-Address%20offset%3A%200x530"&gt;documentation &lt;/a&gt;for the TH threshold registers.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;VDOWN = (THDOWN+1)/64*VREF&lt;/span&gt;&lt;br /&gt;VUP = (THUP+1)/64*VREF&lt;br /&gt;&lt;br /&gt;For example, with a threshold of &lt;strong data-start="432" data-end="437"&gt;5&lt;/strong&gt;, the expected voltage is &lt;strong data-start="463" data-end="473"&gt;104 mV&lt;/strong&gt; based on the given formula.&lt;br /&gt;&lt;br /&gt;e.g, Threshold =&amp;nbsp; 5&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Voltage(mv)&amp;nbsp; = 104&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;I expected mv value as per the above formula, but it is not.&lt;br /&gt;&lt;br /&gt;However, in my testing, I observed:&lt;br /&gt;&lt;br /&gt;&lt;span&gt;e.g, Threshold =&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span&gt;5&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Voltage(mv)&amp;nbsp; = 168.75&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After reverse engineering, I found that the voltage calculation in the system follows this formula:&lt;br /&gt;&lt;br /&gt;V = ((TH + 1)/&lt;strong&gt;32&lt;/strong&gt;) * Vref&amp;nbsp; // divided by 32 not 64&lt;br /&gt;&lt;br /&gt;Please find attached the log table in .txt.&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Could you please clarify what changes or settings are required to achieve the voltage readings as per the formula provided in the &lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/comp.html#ariaid-title7:~:text=GPIO%20Port%20selection-,TH,-Address%20offset%3A%200x530"&gt;documentation&lt;/a&gt;?&lt;br /&gt;&lt;br /&gt;Thanks &amp;amp; Regards,&lt;br /&gt;Pratik&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/th_5F00_adc_5F00_tab.txt"&gt;devzone.nordicsemi.com/.../th_5F00_adc_5F00_tab.txt&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/540849?ContentTypeID=1</link><pubDate>Mon, 30 Jun 2025 11:29:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6712121-5788-4bfa-8d9b-3a81e94ee227</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Dont&amp;#39; have time to test the code, but make sure you understand the difference between COMP and LPCOMP:&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/comp.html"&gt;https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/comp.html&lt;/a&gt;&amp;nbsp;&lt;br /&gt;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/lpcomp.html"&gt;https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/lpcomp.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One can be used in sleep and wakeup the chip (lpcomp), the other is only active while the CPU is running (comp).&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/540843?ContentTypeID=1</link><pubDate>Mon, 30 Jun 2025 11:05:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6a4e871-8456-4214-bcab-f0259cec9f97</guid><dc:creator>Pratik Panchal</dc:creator><description>&lt;p&gt;Hello &lt;a href="https://devzone.nordicsemi.com/members/kme"&gt;Kenneth&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-start="92" data-end="120"&gt;Thank you for your response.&lt;/p&gt;
&lt;p data-start="122" data-end="278"&gt;I reviewed the Nordic thread you shared and used the &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.9.0/tests/benchmarks/multicore/idle_comp/src/main.c"&gt;&lt;em&gt;&lt;strong&gt;referenced code&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt; to configure and integrate a comparator into my application. I connected a potentiometer to the defined ADC pin for input variation.&lt;/p&gt;
&lt;p data-start="468" data-end="583"&gt;However, I expected to receive specific &lt;strong data-start="516" data-end="522"&gt;up&lt;/strong&gt; or &lt;strong data-start="526" data-end="534"&gt;down&lt;/strong&gt; events based on the configured threshold up/down values.&lt;br /&gt;I referred to the &lt;em&gt;&lt;strong&gt;overlay file&lt;/strong&gt;&lt;/em&gt; from the provided GitHub repository, but despite defining &lt;code data-start="156" data-end="163"&gt;th_up&lt;/code&gt; and &lt;code data-start="168" data-end="177"&gt;th_down&lt;/code&gt; values, the &lt;em&gt;&lt;strong&gt;test_callback&lt;/strong&gt; &lt;/em&gt;function does not increment the count on defined up or down threshold, but it&amp;nbsp;only increments when we fully increase the potentiometer value to 4092 = 0.899V, and&amp;nbsp;&lt;span&gt;the event&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;&lt;code data-start="400" data-end="442"&gt;bool event = comparator_get_output(test_dev);&lt;/code&gt;&lt;/strong&gt;&lt;span&gt;&amp;nbsp;Returns 1 on&amp;nbsp;0.899V.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Even I modified the value of th-up to 40, then also the event returns 1 only at 0.899V.&lt;br /&gt;&lt;br /&gt;Here, my application overlay for the comparator :&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;&amp;amp;comp {
	compatible = &amp;quot;nordic,nrf-comp&amp;quot;;
	main-mode = &amp;quot;SE&amp;quot;;
	psel = &amp;quot;AIN4&amp;quot;; /* P1.11 */
	refsel = &amp;quot;VDD&amp;quot;;
	sp-mode = &amp;quot;HIGH&amp;quot;;
	th-up = &amp;lt;63&amp;gt;;
	th-down = &amp;lt;31&amp;gt;;//&amp;lt;59&amp;gt;;
	isource = &amp;quot;DISABLED&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
};&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p data-start="585" data-end="740"&gt;Could you please provide a sample that demonstrates the detailed usage of the APIs for configuring up/down thresholds and handling the corresponding events?&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards,&lt;br /&gt;Pratik Panchal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF54L15-DK : ADC Threshold Event Configuration using LPCOMP and ANADETECT</title><link>https://devzone.nordicsemi.com/thread/540575?ContentTypeID=1</link><pubDate>Thu, 26 Jun 2025 11:37:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f67855b4-e06b-4997-a22c-cedcbb096783</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I suggest to check out this answer:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/118707/using-the-new-lpcomp-driver-in-zephyr"&gt;Using the new LPCOMP driver in Zephyr&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kenneth&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>