<?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>Checking time difference between 2 gpiote events (when chip is in sleep between events) - code get stuck</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/102290/checking-time-difference-between-2-gpiote-events-when-chip-is-in-sleep-between-events---code-get-stuck</link><description>Hi 
 I am trying to run this code: 
 void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { current_event_timestamp = get_current_time_ms(); 
 // Calculate the time difference in milliseconds uint32_t time_diff_ms = (current_event_timestamp</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 Jul 2023 15:29:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/102290/checking-time-difference-between-2-gpiote-events-when-chip-is-in-sleep-between-events---code-get-stuck" /><item><title>RE: Checking time difference between 2 gpiote events (when chip is in sleep between events) - code get stuck</title><link>https://devzone.nordicsemi.com/thread/438594?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 15:29:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a7839f7-83cb-470e-b815-d29e3804fec4</guid><dc:creator>Avi</dc:creator><description>&lt;p&gt;OK, done it:&lt;/p&gt;
&lt;p&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)&lt;br /&gt;{&lt;br /&gt; nrf_drv_gpiote_in_event_disable(PIN_IN);&lt;br /&gt; uint32_t previous_pin_state = nrf_gpio_pin_read(PIN_IN);&lt;br /&gt; nrf_delay_ms(500);&lt;br /&gt; uint32_t current_pin_state = nrf_gpio_pin_read(PIN_IN);&lt;br /&gt; if (current_pin_state == previous_pin_state)&lt;br /&gt; {&lt;/p&gt;
&lt;p&gt;if (counter&amp;lt;50)&lt;br /&gt; counter++;&lt;br /&gt; else&lt;br /&gt; counter=0;&lt;/p&gt;
&lt;p&gt;sd_ble_gap_adv_stop(m_adv_handle);&lt;br /&gt; advertising_init();&lt;br /&gt; advertising_start(); &lt;br /&gt; }&lt;br /&gt; nrf_drv_gpiote_in_event_enable(PIN_IN,true);&lt;br /&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking time difference between 2 gpiote events (when chip is in sleep between events) - code get stuck</title><link>https://devzone.nordicsemi.com/thread/438575?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 14:46:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:baa9241d-089d-43bd-891d-a11bfb0af22a</guid><dc:creator>Avi</dc:creator><description>&lt;p&gt;My mistake, I forgot to include:&amp;nbsp;&lt;span&gt;advertising_start inside the handle.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yet, it is not solving my main problem,&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I want to detect if a switch is open or closed. If it changes state too fast and it is back to the same level I want to ignore. For example, It was closed and then it was opened&amp;nbsp;and closed within 100msec. I want to ignore it and say it is still closed.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I thought about reading the GPIN state, but looks like I cannot since I am using it also for GPIOTE&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How can I do it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking time difference between 2 gpiote events (when chip is in sleep between events) - code get stuck</title><link>https://devzone.nordicsemi.com/thread/438572?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 14:33:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d1ac932-56d7-4345-ad01-d7da89b53d67</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;There is nothing in your code that loops, so please explain what you mean by &amp;quot;stuck&amp;quot;? In a microcontroller applicaition there is app error check loops, hardfaults or loops that the app inserted. There is no other stuck state.&lt;/p&gt;
[quote user="Avi"]If I remove the timestamp comparison it works.[/quote]
&lt;p&gt;Removing which exact line makes it work? maybe there is a hardfault in your case which you presume to be stuck. Do you have any logs in enabled in the application? if so add some logs to see if some errors are thrown out.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Checking time difference between 2 gpiote events (when chip is in sleep between events) - code get stuck</title><link>https://devzone.nordicsemi.com/thread/438452?ContentTypeID=1</link><pubDate>Thu, 27 Jul 2023 08:42:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23ac4c1f-117c-4aa8-bc52-356b1e122102</guid><dc:creator>Avi</dc:creator><description>&lt;p&gt;I tried also this:&lt;/p&gt;
&lt;p&gt;void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)&lt;br /&gt;{&lt;br /&gt; current_event_timestamp = get_current_time_ms();&lt;br /&gt; uint32_t time_diff_ms;&lt;/p&gt;
&lt;p&gt;// Calculate the time difference in milliseconds&lt;br /&gt; if (current_event_timestamp &amp;gt;= last_event_timestamp)&lt;br /&gt; {&lt;br /&gt; time_diff_ms = current_event_timestamp - last_event_timestamp;&lt;br /&gt; // Update the last event timestamp&lt;br /&gt; last_event_timestamp = current_event_timestamp;&lt;br /&gt; // Ignore the event if it occurred too soon (less than 100ms) after the last event&lt;br /&gt; if (time_diff_ms &amp;gt; 100)&lt;br /&gt; {&lt;/p&gt;
&lt;p&gt;if (counter&amp;lt;50)&lt;br /&gt; counter++;&lt;br /&gt; else&lt;br /&gt; counter=0;&lt;/p&gt;
&lt;p&gt;sd_ble_gap_adv_stop(m_adv_handle);&lt;br /&gt; advertising_init(); &lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And I see that it still gets stuck&lt;/p&gt;
&lt;p&gt;If I remove the timestamp comparison it works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>