<?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>How to get a base of time from an ISR and preserve the low power consumption.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69090/how-to-get-a-base-of-time-from-an-isr-and-preserve-the-low-power-consumption</link><description>Hi, Currently, we work on a project that uses: nRF9160 Zyphre OS Segger Embedded Studio for Arm (Nordic Edition) V5.10d SDK v1.4 
 
 This is our situation. 
 We want to measure the pulse width that enters a digital input of the nrf9160. After the above</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Dec 2020 01:29:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69090/how-to-get-a-base-of-time-from-an-isr-and-preserve-the-low-power-consumption" /><item><title>RE: How to get a base of time from an ISR and preserve the low power consumption.</title><link>https://devzone.nordicsemi.com/thread/283684?ContentTypeID=1</link><pubDate>Tue, 08 Dec 2020 01:29:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6e38e48-cc77-4771-84fd-caa987402d04</guid><dc:creator>ReneDelgado</dc:creator><description>&lt;p&gt;Hi &amp;Oslash;yvind,&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It was clear enough to solve our doubts.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thanks a lot,&lt;br /&gt;&lt;br /&gt;Ren&amp;eacute; D.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a base of time from an ISR and preserve the low power consumption.</title><link>https://devzone.nordicsemi.com/thread/283481?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 09:37:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1b11635-5ed8-4721-ad87-fc86cf20455c</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hi René,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="ReneDelgado"]&lt;span style="color:rgba(153, 51, 0, 1);"&gt;&lt;span style="color:rgba(0, 0, 0, 1);"&gt; &lt;strong&gt;1)&lt;/strong&gt; From the example &lt;span style="font-size:75%;"&gt;(we attached an image),&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style="font-size:75%;"&gt;&amp;quot;button_pressed(...)&amp;quot;&amp;nbsp;&lt;/span&gt; function is in ISR context?[/quote]
&lt;p&gt;&amp;nbsp;The function button_pressed() is called by the gpio callback. You can find &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/zephyr/guides/design_guidelines.html#using-callbacks"&gt;more information about callbacks here&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;More &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/zephyr/reference/kernel/other/interrupts.html"&gt;information on the Zephyr ISR can be found here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Remember that NCS is using Zephyr OS to enable more complex applications with&amp;nbsp;Scheduling, Interrupts, and Synchronization, introducing amongst other &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/zephyr/reference/kernel/threads/index.html"&gt;Threads&lt;/a&gt;&amp;nbsp;to offload ISR.&lt;/p&gt;
[quote user="ReneDelgado"]&lt;span style="color:rgba(153, 51, 0, 1);"&gt;&lt;span style="color:rgba(0, 0, 0, 1);"&gt;&lt;span style="font-size:75%;"&gt;&amp;nbsp;&lt;strong&gt;&amp;nbsp; &lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;strong&gt;2)&lt;/strong&gt; It is safe call &lt;span style="font-size:75%;"&gt;&amp;quot;k_cycle_get_32()&amp;quot;&lt;/span&gt; from an isr context?[/quote]
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief Read the hardware clock.
 *
 * This routine returns the current time, as measured by the system&amp;#39;s hardware
 * clock.
 *
 * @return Current hardware clock up-counter (in cycles).
 */
static inline uint32_t k_cycle_get_32(void)
{
	return arch_k_cycle_get_32();
}&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This should be safe. This function is called using threads, offloading the ISR. T&lt;span&gt;he intent is that this counter represents the fastest cycle counter that the operating system is able to present to the user (for example, a CPU cycle counter) and that the read operation is very fast.&lt;/span&gt;&lt;/p&gt;
[quote user="ReneDelgado"]&lt;strong&gt;3)&lt;/strong&gt;&lt;span style="font-size:75%;"&gt; &amp;quot;__get_IPSR()&amp;quot;&lt;/span&gt; is in the nrf9160 available to validate if some functions is in an ISR context?[/quote]
&lt;p&gt;&amp;nbsp;This is a function from Arm CMSIS&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;  \brief   Get IPSR Register
  \details Returns the content of the IPSR Register.
  \return               IPSR Register value
 */
__STATIC_INLINE uint32_t __get_IPSR(void)
{
  register uint32_t __regIPSR          __ASM(&amp;quot;ipsr&amp;quot;);
  return(__regIPSR);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m afraid I don&amp;#39;t have a complete overview of this part. You might find &lt;a href="https://github.com/ARM-software/CMSIS_5"&gt;more information from this page&lt;/a&gt;&lt;/p&gt;
[quote user="ReneDelgado"]&lt;strong&gt; 4)&lt;/strong&gt; &lt;span style="font-size:75%;"&gt;&amp;quot;date_time_now(...)&amp;quot;&lt;/span&gt; use some socket to get the UTC and is &lt;span style="font-size:75%;"&gt;&amp;quot;date_time_now(...)&amp;quot;&lt;/span&gt; safe to use in ISR context?[/quote]
&lt;p&gt;I would recommend using the Zephyr OS scheduling for this usage. There is &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/nrf/include/date_time.html#date-time"&gt;more information about Date and Time here&lt;/a&gt;. We have some samples which use this e.g. &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/nrf9160/aws_iot/README.html#nrf9160-aws-iot"&gt;AWS IoT sample&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Hope this answers your questions. Let me know if anything is unclear &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a base of time from an ISR and preserve the low power consumption.</title><link>https://devzone.nordicsemi.com/thread/283442?ContentTypeID=1</link><pubDate>Mon, 07 Dec 2020 01:03:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:356ffdcb-f202-46c5-836e-cf31a578547f</guid><dc:creator>ReneDelgado</dc:creator><description>&lt;p&gt;Hello &amp;Oslash;yvind,&lt;/p&gt;
&lt;p&gt;Thanks for the prompt response,&amp;nbsp; I took a look at &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/rtc.html?cp=2_0_0_5_10"&gt;RTC &amp;mdash; Real-time counter&lt;/a&gt; and &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/dppi.html?cp=2_0_0_5_1"&gt;the Distributed Programmable Peripheral Interconnect (DPPI)&lt;/a&gt; and it is very interesting but in this case, it is not that I need.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;We think found what we need in a Zephyr example &lt;span style="color:#993300;"&gt;&amp;quot;c:\...\zephyr\samples\basic\button&amp;quot;. &lt;span style="color:#000000;"&gt;But we still have some concerns, would you help us to solve them&lt;span style="font-size:inherit;"&gt;?&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;span style="color:#000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;1)&lt;/strong&gt; From the example &lt;span style="font-size:75%;"&gt;(we attached an image),&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span style="font-size:75%;"&gt;&amp;quot;button_pressed(...)&amp;quot;&amp;nbsp;&lt;/span&gt; function is in ISR context?&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;span style="color:#000000;"&gt;&lt;span style="font-size:75%;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;&amp;nbsp; &lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;strong&gt;2)&lt;/strong&gt; It is safe call &lt;span style="font-size:75%;"&gt;&amp;quot;k_cycle_get_32()&amp;quot;&lt;/span&gt; from an isr context?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;3)&lt;/strong&gt;&lt;span style="font-size:75%;"&gt; &amp;quot;__get_IPSR()&amp;quot;&lt;/span&gt; is in the nrf9160 available to validate if some functions is in an ISR context?&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;span style="color:#000000;"&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1607302682711v1.png" /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#993300;"&gt;&lt;span style="color:#000000;"&gt;And the last extra question, &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;strong&gt;&amp;nbsp; 4)&lt;/strong&gt; &lt;span style="font-size:75%;"&gt;&amp;quot;date_time_now(...)&amp;quot;&lt;/span&gt; use some socket to get the UTC and is &lt;span style="font-size:75%;"&gt;&amp;quot;date_time_now(...)&amp;quot;&lt;/span&gt; safe to use in ISR context?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks a lot and kind regards,&lt;br /&gt;Ren&amp;eacute; D.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to get a base of time from an ISR and preserve the low power consumption.</title><link>https://devzone.nordicsemi.com/thread/283272?ContentTypeID=1</link><pubDate>Fri, 04 Dec 2020 09:43:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20a1b9ff-3879-416d-a1a6-f235686a40cc</guid><dc:creator>&amp;#216;yvind</dc:creator><description>&lt;p&gt;Hello René,&lt;/p&gt;
&lt;p&gt;It sounds that you should &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/rtc.html?cp=2_0_0_5_10"&gt;look at the Real Time Counter in the nRF9160&lt;/a&gt;&amp;nbsp;and &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf9160/dppi.html?cp=2_0_0_5_1"&gt;the Distributed Programmable Peripheral Interconnect (DPPI)&lt;/a&gt;.&lt;/p&gt;
[quote user=""]&amp;nbsp;&lt;strong&gt; 1)&lt;/strong&gt; What method should we use to obtain the ticks within a digital input ISR?[/quote]
&lt;p&gt;&amp;nbsp;Have a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/nrf/samples/debug/ppi_trace/README.html"&gt;look at our PPI sample&lt;/a&gt;&amp;nbsp;which uses DPPI and RTC to &lt;span&gt;trace hardware events on GPIO pins.&lt;/span&gt;&lt;/p&gt;
[quote user=""]&lt;strong&gt;&amp;nbsp;&amp;nbsp; 2) &lt;/strong&gt;Is the clock source for that tick available during low power states?[/quote]
&lt;p&gt;&amp;nbsp;Yes, it should. By &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/zephyr/reference/kernel/scheduling/index.html"&gt;using k_sleep, part of the Zephyr scheduling&lt;/a&gt;&amp;nbsp;and &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/zephyr/reference/power_management/index.html#power-management"&gt;Power Management&lt;/a&gt; the application can put the thread where it is called into low power mode. Have a &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/68527/sleep-modes-on-the-nrf9160-dk"&gt;look at this thread about the sleep modes&lt;/a&gt;.&lt;/p&gt;
[quote user=""]&amp;nbsp;&lt;strong&gt; 3)&lt;/strong&gt; What is the resolution that we can expect with this method?[/quote]
&lt;p&gt;&amp;nbsp;What resolution do you need? The counter API &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.4.0/zephyr/reference/peripherals/counter.html#c.counter_ticks_to_us"&gt;includes a function counter_ticks_to_us()&lt;/a&gt;&amp;nbsp;which may be a starting point.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]As always, we appreciate the excellent support you have given us so far.[/quote]
&lt;p&gt;&amp;nbsp;Thank you! We do our best to support our customer the best we can :)&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Let me know if you need more information.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Kind regards,&lt;br /&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>