<?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>LPCOMP sampling rate</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27442/lpcomp-sampling-rate</link><description>Hi, 
 I want to sample lpcomp result at 50us, I&amp;#39;m doing so by using the following statements and set/clear a gpio based on the lpcomp result: 
 nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_SAMPLE);
lpcomp_result = nrf_lpcomp_result_get(); 
 This is done</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 Nov 2017 10:00:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27442/lpcomp-sampling-rate" /><item><title>RE: LPCOMP sampling rate</title><link>https://devzone.nordicsemi.com/thread/108377?ContentTypeID=1</link><pubDate>Tue, 28 Nov 2017 10:00:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6238f11b-68d5-4885-9844-540ba166a4ff</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;I tested this with a PWM input signal. Note that according to basic sampling theorems, you need a minimum sampling frequency that is 2 times higher than the maximum frequency of the input signal.&lt;/p&gt;
&lt;p&gt;Have you tried increasing the sampling rate?&lt;/p&gt;
&lt;p&gt;Again, you don&amp;#39;t need to use a TIMER for this. The LPCOMP does automatically detection when the signal goes below/over your reference ( LPCOMP can generate separate events on rising and falling edges of a signal), so you don&amp;#39;t need to periodically sample the state from a timer interrupt, the LPCOMP can generate the events itself when the input signal changes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPCOMP sampling rate</title><link>https://devzone.nordicsemi.com/thread/108376?ContentTypeID=1</link><pubDate>Mon, 27 Nov 2017 03:42:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da6efb2d-f27f-421a-9fb1-71add2e55642</guid><dc:creator>Sourabh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;Currently we are not using a
softdevice, but the final solution
will have ble.
2.How was it verified
that the LPCOMP worked fine?&lt;/li&gt;
&lt;li&gt;What was the signal input to the LPCOMP.&lt;/li&gt;
&lt;li&gt;We are taking over the code from an already working product where all these time parameters are tuned to detect motions accurately from the pir. The only thing that has changed from the previous circuitry is the comparator. Earlier we used comparator from the stm family MCU, which is now replaced with the nrf52 LPCOMP.&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPCOMP sampling rate</title><link>https://devzone.nordicsemi.com/thread/108375?ContentTypeID=1</link><pubDate>Fri, 24 Nov 2017 13:14:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33e70144-7b8a-415d-bb43-1593e62e7d8d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Are you using the SoftDevice/BLE at the same time? Does it make any difference if you increase the IRQ priority ?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://gist.github.com/anonymous/20095a9f2e6b7f38f55ea5e91935ca58"&gt;Here&lt;/a&gt; some code I used to test this, and it worked fine. I&amp;#39;m here sampling at 20 us. Signal input at pin 4, and lpcomp result output at pin 28. I used reference voltage Supply 4/8 when I tested this.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Is there a reason why you need to sample every 50us? Note that you can get an interrupt every time the signal crosses your voltage reference. That way you don’t need to pool/sample the result every 50 us... Also if the signal changes faster than you are pooling, you will lose data. So using the LPCOMP interrupt is generally preferred over sampling in a timer interrupt.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPCOMP sampling rate</title><link>https://devzone.nordicsemi.com/thread/108374?ContentTypeID=1</link><pubDate>Thu, 23 Nov 2017 05:17:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aad2f96c-68f2-42ab-966a-f027db55d288</guid><dc:creator>Sourabh</dc:creator><description>&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lpcomp initialisation:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;void md_lpcomp_init(void)
{
uint32_t                err_code;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_lpcomp_config_t lpcomp_config = NRF_DRV_LPCOMP_DEFAULT_CONFIG;
lpcomp_config.input = NRF_LPCOMP_INPUT_4;

// initialize LPCOMP driver, from this point LPCOMP will be active and provided
// event handler will be executed when defined action is detected
err_code = nrf_drv_lpcomp_init(&amp;amp;lpcomp_config, lpcomp_event_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_lpcomp_enable();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;em&gt;I have commented the &lt;strong&gt;nrf_drv_common_irq_enable(LPCOMP_IRQn, p_config-&amp;gt;interrupt_priority)&lt;/strong&gt; in &lt;strong&gt;nrf_lpcomp_init&lt;/strong&gt; function&lt;/em&gt;&lt;/p&gt;
&lt;ol start="2"&gt;
&lt;li&gt;
&lt;p&gt;Timer instance 0 is used with IRQ priority 7.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We are sampling a PIR sensor signal via software implemented sigma delta ADC.&lt;a href="https://www.nxp.com/docs/en/application-note/AN4305.pdf"&gt;Based on this Application Note&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code&gt;  static __inline void md_sample_measurement(void)
 { 
     /*Get the last compare result. If 0 then VIN+ &amp;lt; VIN-, if 1 then the opposite. */
     nrf_lpcomp_task_trigger(NRF_LPCOMP_TASK_SAMPLE);
     lpcomp_result = nrf_lpcomp_result_get();

     if (0 == lpcomp_result)
     {
       /* lpcomp result is zero i.e. reference higher than input so need more vtg. in*/	 
       NRF_GPIO-&amp;gt;OUTSET = (1 &amp;lt;&amp;lt; PIR_CHARGE);
       lpcomp_result_count++;
     }
     else
     {
       /* lpcomp result is non zero i.e. input higher than reference so need less vtg.*/
      NRF_GPIO-&amp;gt;OUTCLR = (1 &amp;lt;&amp;lt; PIR_CHARGE);
      lpcomp_result_count--;		 			 
     }

   }
   
 } 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the function called in the timer interrupt.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LPCOMP sampling rate</title><link>https://devzone.nordicsemi.com/thread/108373?ContentTypeID=1</link><pubDate>Wed, 22 Nov 2017 16:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0609574-77f6-4e66-bf9c-aa2762d5ee09</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How are you initializing the lpcomp?&lt;/li&gt;
&lt;li&gt;What IRQ priority are you using on the Timer ?&lt;/li&gt;
&lt;li&gt;What kind of signal are you sampling? How often does it change ?&lt;/li&gt;
&lt;li&gt;Could you post your complete code on how you are doing this?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;From the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/lpcomp.html?cp=2_1_0_38#concept_tdv_zkx_lr"&gt;spec&lt;/a&gt; you have that:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The immediate value of the LPCOMP can
be sampled to RESULT by triggering the
SAMPLE task.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So 50us rate should be fine.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>