<?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>GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/64298/gpiote-ppi-timer-errors</link><description>Hello, 
 nRF52832 BLE project using SDK 15.3.0 and SoftDevice 112 v6.1.1. Circuit has the output of a comparator connected to two GPIO pins (COMPARATOR_PIN1, COMPARATOR_PIN2). From time to time, a sensor will cause the comparator output to go LoToHi and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 07 Aug 2020 19:16:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/64298/gpiote-ppi-timer-errors" /><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/263689?ContentTypeID=1</link><pubDate>Fri, 07 Aug 2020 19:16:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7315ec7e-2b0c-4d81-b96b-1052518b87ea</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;Thanks Dmitry. Under normal use, there are random trailing pulses after the initial measured pulse. In testing, though, I&amp;#39;m using a function generator to generate a single 250ms pulse every 5 seconds. There are no trailing random pulses.&lt;/p&gt;
&lt;p&gt;I continue to see good results with current code that uses&amp;nbsp;nrfx_gpiote calls. I wonder if&amp;nbsp;nrfx_gpiote_in_event_disable/enable calls are setting MODE of GPIOTE-&amp;gt;CONFIG[] to 0/1 rather than disabling/enabling GPIOTE interrupts.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Tim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/263361?ContentTypeID=1</link><pubDate>Thu, 06 Aug 2020 08:16:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca2cf410-1a28-4e94-8167-d0d058d1159c</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I think the problem is that GPIOTE event is not cleared when you enable an interrupt (sd_nvic_ClearPendingIRQ is not enough), and right after enabling interrupts you&amp;#39;re receiving an event from some random pulse.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/263303?ContentTypeID=1</link><pubDate>Wed, 05 Aug 2020 17:06:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ae4fa6f-df1b-4495-9d2e-45c5a5a77ab3</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
&lt;p&gt;I may have discovered the source of intermittent errors. The code is designed to measure a pulse (LoToHi followed by HiToLo) of a signal. Our&amp;nbsp;circuit connects the signal to two GPIO pins so I don&amp;#39;t break the one-pin-one-GPIOTE event rule.&lt;/p&gt;
&lt;p&gt;After detecting and measuring a pulse, other random pulses are expected for a couple seconds following the initial pulse. Only the first pulse is of interest, so in the GPIOTE interrupt routine (which is called on HiToLo marking the end of the pulse) I disable GPIOTE interrupts with&lt;/p&gt;
&lt;pre&gt;&lt;span&gt;sd_nvic_DisableIRQ(GPIOTE_IRQn);&lt;/span&gt;
&lt;/pre&gt;
&lt;p&gt;I set up a timer to fire three seconds later and execute:&lt;/p&gt;
&lt;pre&gt;sd_nvic_SetPriority(GPIOTE_IRQn,APP_IRQ_PRIORITY_HIGH);
sd_nvic_ClearPendingIRQ(GPIOTE_IRQn);
sd_nvic_EnableIRQ(GPIOTE_IRQn);
&lt;/pre&gt;
&lt;p&gt;Is it possible that this can result in an erroneous GPIOTE event?&lt;/p&gt;
&lt;p&gt;I changed the GPIOTE code to use nrfx_gpiote instead of manipulating GPIOTE registers directly.&lt;/p&gt;
&lt;pre&gt;&lt;pre class="ui-code" data-mode="text"&gt;nrfx_err_t err_code = NRF_SUCCESS;

nrfx_gpiote_in_config_t configLoToHi = NRFX_GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
configLoToHi.pull = NRF_GPIO_PIN_PULLUP;

// do not interrupt on LoToHi
err_code = nrfx_gpiote_in_init(COMPARATOR_PIN1,&amp;amp;configLoToHi,NULL);
APP_ERROR_CHECK(err_code);

nrfx_gpiote_in_config_t configHiToLo = NRFX_GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
configLoToHi.pull = NRF_GPIO_PIN_PULLUP;

// interrupt on HiToLo
err_code = nrfx_gpiote_in_init(COMPARATOR_PIN2,&amp;amp;configHiToLo,gpiote_event_handler);
APP_ERROR_CHECK(err_code);

nrfx_gpiote_in_event_enable(COMPARATOR_PIN1,false);
nrfx_gpiote_in_event_enable(COMPARATOR_PIN2,true);&lt;/pre&gt;&lt;/pre&gt;
&lt;p&gt;Then to ignore events following initial pulse, I use:&lt;/p&gt;
&lt;pre&gt;nrfx_gpiote_in_event_disable(COMPARATOR_PIN1);
nrfx_gpiote_in_event_disable(COMPARATOR_PIN2);
&lt;/pre&gt;
&lt;p&gt;And to enable 3 seconds&amp;nbsp;later:&lt;/p&gt;
&lt;pre&gt;nrfx_gpiote_in_event_enable(COMPARATOR_PIN1,false);
nrfx_gpiote_in_event_enable(COMPARATOR_PIN2,true);
&lt;/pre&gt;
&lt;p&gt;I imagine that the nrfx calls to enable/disable an event are manipulating&amp;nbsp;the NRF_GPIOTE-&amp;gt;INTENSET and&amp;nbsp;NRF_GPIOTE-&amp;gt;INTENCLR registers and not enabling/disabling GPIOTE interrupts.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been running tests and finding zero errors. I would be glad to hear from Nordic or others confirmation that disabling/enabling GPIOTE interrupts (sd_nvic_EnableIRQ(GPIOTE_IRQn)/sd_nvic_DisableIRQ(GPIOTE_IRQn)) could have been&amp;nbsp;a source of previous intermittent errors. Then I would be confident that current code is stable and reliable.&lt;/p&gt;
&lt;p&gt;Many thanks,&lt;/p&gt;
&lt;p&gt;Tim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/262491?ContentTypeID=1</link><pubDate>Fri, 31 Jul 2020 06:03:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:faf56c99-c151-435a-ab49-cf47f9111255</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;Thanks again Dmitry. I&amp;#39;ve simplified code as you suggest and am running tests. Still finding errors.&amp;nbsp;Will try to offer more information that might be helpful investigating.&lt;/p&gt;
&lt;p&gt;Again, thanks.&lt;/p&gt;
&lt;p&gt;Tim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/262362?ContentTypeID=1</link><pubDate>Thu, 30 Jul 2020 10:22:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e382de4c-e2f2-4dcb-8e1e-5b1bd39faf25</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;It&amp;#39;s hard to debug a floating problem, perhaps there&amp;#39;s a race condition somewhere.&lt;/p&gt;
&lt;p&gt;With a single timer, assing one PPI channel to start timer on rising edge, and a second one to stop and capture timer value on falling edge - that&amp;#39;s all you need.&lt;/p&gt;
[quote userid="7638" url="~/f/nordic-q-a/64298/gpiote-ppi-timer-errors/262265"]Do you know when to use nrfx_ppi_channel_alloc() and when to use&amp;nbsp;sd_ppi_channel_alloc()?[/quote]
&lt;p&gt;sd_ppi_... functions are softdevice API calls, they should be used when softdevice is enabled, as some resources are blocked by softdevice from direct access.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/262265?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 21:07:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07adcfb2-f77d-4953-b1f8-8fd19a0f904c</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;Hi Dmitry,&lt;/p&gt;
&lt;p&gt;Thanks for replying. Good point. I didn&amp;#39;t realize all timers on nRF52832 can be used in 32-bit mode. I will need to back port this to work on nRF51822 and the two available timers (TIMER1, TIMER2) are limited to 16 bit. (TIMER0, which supports 32-bit mode, is reserved for SoftDevice.) At maximum prescaler (9), timer will overflow in&amp;nbsp;2.097152 seconds which, while unlikely, is within my use case.&lt;/p&gt;
&lt;p&gt;Would you suggest other ways to simplify?&amp;nbsp;Can you see any issues with code as it is? Anything that might explain the very occasional errors?&lt;/p&gt;
&lt;p&gt;Do you know when to use nrfx_ppi_channel_alloc() and when to use&amp;nbsp;sd_ppi_channel_alloc()?&lt;/p&gt;
&lt;p&gt;Thanks, appreciate it.&lt;/p&gt;
&lt;p&gt;Tim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/262264?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 20:12:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4e84e14-85b1-4639-a1a7-4a1f2f63f0f3</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi Tim,&lt;/p&gt;
&lt;p&gt;your solution looks too complex.. the tick value is converted to uint32_t, why not to use a single timer in 32-bit mode?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE/PPI/TIMER errors</title><link>https://devzone.nordicsemi.com/thread/262225?ContentTypeID=1</link><pubDate>Wed, 29 Jul 2020 14:08:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd0355e1-0400-4597-8f6c-bef0f55bdfda</guid><dc:creator>Tim</dc:creator><description>&lt;p&gt;I forgot to include a few lines of code in&amp;nbsp;gpiote_ppi_init() to enable GPIOTE interrupts. I&amp;#39;ve edited the original post.&lt;/p&gt;
&lt;p&gt;Also will mention, during setup the application sets:&lt;/p&gt;
&lt;pre&gt;NRF_POWER-&amp;gt;TASKS_CONSTLAT = 1;
&lt;/pre&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Tim&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>