<?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>App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94292/app-timer-in-repeated-mode-always-runs-with-the-same-delay</link><description>Hello, 
 I am starting a new ticket as per the suggestion from a previous ticket . 
 I have RTC configured to trigger every 1 ms and that keeps track on milliseconds since startup. I use that variable to log(using RTT) when the timer is triggered. 
 There</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Mar 2023 10:38:50 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94292/app-timer-in-repeated-mode-always-runs-with-the-same-delay" /><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/415656?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2023 10:38:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:928c872c-e4e8-41df-b399-76e1535b02ce</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>[quote user="exsurgo_ankit"]&lt;p&gt;Could you please clarify this statement:&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;&lt;blockquote&gt;&lt;div&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/94292/app-timer-in-repeated-mode-always-runs-with-the-same-delay/414082"&gt;Jørgen Holmefjord said:&lt;/a&gt;&lt;/div&gt;&lt;div&gt;Note that you will have to start one app_timer before the RTC is started.&amp;nbsp;&lt;/div&gt;&lt;/blockquote&gt;&lt;div&gt;&lt;/div&gt;
&lt;p&gt;I do not initialise RTC anymore as I use the counter from app timer&amp;#39;s rtc (RTC1)&lt;/p&gt;[/quote]
&lt;p&gt;I was referring to the RTC instance used by app_timer. As far as I know, this RTC instance is not started until you start an app_timer timer, but if you are getting sensible readings from the API, this should not be an issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/415353?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2023 03:09:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c750c596-e813-4445-9d3a-9cc2e4b31582</guid><dc:creator>exsurgo_ankit</dc:creator><description>&lt;p&gt;Hello &lt;a href="https://devzone.nordicsemi.com/members/joh2"&gt;Jørgen Holmefjord&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for further inforamtion on this. I did not have&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__app__timer__config.html#ga0d10afa54afc4b68394f69c2367b1b11"&gt;APP_TIMER_KEEPS_RTC_ACTIVE&lt;/a&gt;&amp;nbsp;enabled.&lt;/p&gt;
&lt;p&gt;I am getting the counter value roughly every second so catching overflows will not be an issue.&lt;/p&gt;
&lt;p&gt;Could you please clarify this statement:&lt;/p&gt;
[quote userid="14926" url="~/f/nordic-q-a/94292/app-timer-in-repeated-mode-always-runs-with-the-same-delay/414082"]Note that you will have to start one app_timer before the RTC is started.&amp;nbsp;[/quote]
&lt;p&gt;I do not initialise RTC anymore as I use the counter from app timer&amp;#39;s rtc (RTC1)&lt;/p&gt;
&lt;p&gt;Startup sequence in my application looks like this:&lt;/p&gt;
&lt;p&gt;1. wdt init&lt;/p&gt;
&lt;p&gt;2. uart init&lt;/p&gt;
&lt;p&gt;3. app timer init (to run every 1000 ms)&lt;/p&gt;
&lt;p&gt;4. power management init&lt;/p&gt;
&lt;p&gt;5. lfclk_config (Function starting the internal LFCLK XTAL oscillator)&lt;/p&gt;
&lt;p&gt;6. gpio init and so on...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/414082?ContentTypeID=1</link><pubDate>Wed, 08 Mar 2023 10:44:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3faa99ec-a9b8-49fb-aa56-6ae21bcff062</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You can get the time from RTC1 as long as you have configured it to run when all app_timers have stopped (&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__app__timer__config.html#ga0d10afa54afc4b68394f69c2367b1b11"&gt;APP_TIMER_KEEPS_RTC_ACTIVE&lt;/a&gt;). The APIs&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__app__timer.html#gae36265bac1480fbb1522f63f70ac369f"&gt;app_timer_cnt_get&lt;/a&gt;() and&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.1.0/group__app__timer.html#ga19d88a7d3da7d03f8a2c956a2ac5ccf3"&gt;app_timer_cnt_diff_compute&lt;/a&gt;() are provided for this.&amp;nbsp;Note that you will have to start one app_timer before the RTC is started.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You will not be informed about overflows on the RTC in case you use the app_timer RTC. If you expect long time between each time you get the counter, this could be a problem, but on the lowest prescaler setting, the RTC will run for 512 seconds between each overflow.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/413674?ContentTypeID=1</link><pubDate>Tue, 07 Mar 2023 00:13:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d9826c73-a7ac-4345-b31c-fbd4c42402da</guid><dc:creator>exsurgo_ankit</dc:creator><description>&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/emil-lenngren"&gt;Emil Lenngren&lt;/a&gt;&amp;nbsp;, Thank you for the suggestion. I have been experimenting with your suggestion. I understand that RTC0 is used by the softdevice and RTC1 is used by the app _timer. Do I need to initialise RTC2 without an interrupt for this purpose or can I just get the counter for RTC1?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/405776?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2023 08:18:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96ed64a1-4cf0-4f04-b960-176abc14d784</guid><dc:creator>Emil Lenngren</dc:creator><description>&lt;p&gt;Sounds a bit wasteful to run an interrupt every ms just to increment a counter, since that will cost energy.&lt;/p&gt;
&lt;p&gt;Why don&amp;#39;t you simply instead access the COUNTER register on the RTC peripheral or similar, when you need to get the current time?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/405758?ContentTypeID=1</link><pubDate>Fri, 20 Jan 2023 03:13:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:564cb55e-250a-4da9-a509-b0b7d7ab715c</guid><dc:creator>exsurgo_ankit</dc:creator><description>&lt;p&gt;Hello &lt;a href="https://devzone.nordicsemi.com/members/joh2"&gt;Jørgen Holmefjord&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Apologies for the delay in the response. Based on the your comment,&lt;/p&gt;
[quote userid="14926" url="~/f/nordic-q-a/94292/app-timer-in-repeated-mode-always-runs-with-the-same-delay/399514"] you will need to count to 1024 &amp;quot;ms&amp;quot; before you reach 1000 ms (32768/32)[/quote]
&lt;p&gt;am I right in understanding that ticks don&amp;#39;t correspond to milliseconds in this case?&lt;/p&gt;
&lt;p&gt;Hence 1024 ticks counted by the rtc counter indicate 1000 ms have elapsed?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/399514?ContentTypeID=1</link><pubDate>Wed, 07 Dec 2022 16:46:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d14cf28d-497e-47b6-abdd-16ce158e4ae9</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>[quote user="exsurgo_ankit"]My final aim is to ensure that the the timer runs every 1000ms and if that requires modifying the rtc counter&amp;nbsp;then what changes do I need to make?[/quote]
&lt;p&gt;Do you need to count each millisecond? If you start an RTC or a app_timer instance with the CC/TICK set to the same as the frequency of the RTC (32768/(PRESCALER + 1), then that should run at every 1000 ms. If you need to count each millisecond, you need to check your ticks and make sure you count the right amount of events in a second. I.e. if the RTC runs as 32.768 kHz, and you configure a each &amp;quot;ms&amp;quot; to tick at CC=32, you will need to count to 1024 &amp;quot;ms&amp;quot; before you reach 1000 ms (32768/32).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/398219?ContentTypeID=1</link><pubDate>Wed, 30 Nov 2022 01:23:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5518e443-7147-42a9-b5a2-cdda847cf382</guid><dc:creator>exsurgo_ankit</dc:creator><description>&lt;p&gt;I am going to be offline until 11th Dec 2022. Please don&amp;#39;t close this case due to inactivity. I will respond as soon as I am back online.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/397971?ContentTypeID=1</link><pubDate>Mon, 28 Nov 2022 20:21:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5201b791-2cf9-48f5-9378-5e304aa08b48</guid><dc:creator>exsurgo_ankit</dc:creator><description>&lt;p&gt;Hello Jorgen,&lt;/p&gt;
&lt;p&gt;I use the rtc counter to measure the 1ms ticks.&lt;/p&gt;
&lt;p&gt;Yes I am using app_timer2 and the SDK version is&amp;nbsp;nRF5_SDK_17.0.2.&lt;/p&gt;
&lt;p&gt;The&amp;nbsp;APP_TIMER_TICKS(1000) outputs 16384.&lt;/p&gt;
&lt;p&gt;Here is the rtc_config function&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define LF_CLK_FREQ_HZ                  32768U
#define RTC_CTR_FREQ_HZ                 1000U
#define COMPARE_COUNTERTIME             (1UL)  

/** @brief Function initialization and configuration of RTC driver instance.
 */
static void rtc_config(void)
{
    uint32_t err_code;

    //Initialize RTC instance, every 10 ms
    nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG;
    config.prescaler = (uint16_t)((LF_CLK_FREQ_HZ / RTC_CTR_FREQ_HZ) - 1U); //e.g PRESCALER = round(32.768 kHz / 100 Hz) - 1 = 327
    err_code = nrf_drv_rtc_init(&amp;amp;rtc, &amp;amp;config, rtc_handler);
    APP_ERROR_CHECK(err_code);

    //Enable tick event &amp;amp; interrupt
    nrf_drv_rtc_tick_enable(&amp;amp;rtc,true);

    //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds
    err_code = nrf_drv_rtc_cc_set(&amp;amp;rtc, 2U, (COMPARE_COUNTERTIME * RTC_CTR_FREQ_HZ), true);
    APP_ERROR_CHECK(err_code);

    //Power on RTC instance
    nrf_drv_rtc_enable(&amp;amp;rtc);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Based on your comment I am measuring the 1ms ticks incorrectly. My final aim is to ensure that the the timer runs every 1000ms and if that requires modifying the rtc counter&amp;nbsp;then what changes do I need to make?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Ankit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: App timer in repeated mode always runs with the same delay</title><link>https://devzone.nordicsemi.com/thread/397837?ContentTypeID=1</link><pubDate>Mon, 28 Nov 2022 11:30:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15223285-d401-4ed9-980a-8ced62c5b21a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;How do you measure the 1024 ms? Are you using toggling GPIOs and measure the timing externally using a logic analyzer, or do you use the 1ms RTC counter to measure the time? The RTC runs off the 32.768 kHz LFCLK, which makes it not possible to trigger in interrupt at exactly 1 ms. If you run&amp;nbsp;at maximum frequency RTC Prescaler = 0, the closest would be ~&lt;span&gt;976&amp;nbsp;&lt;/span&gt;us (32 / 32768Hz), or ~&lt;span&gt;1007&amp;nbsp;&lt;/span&gt;us (33 / 32768Hz). The app_timer should be able to trigger at 1000ms intervals, but note that the interrupts/event handling might be delayed by other higher priority interrupts in the system.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What is the output from the&amp;nbsp;APP_TIMER_TICKS() macro?&lt;/li&gt;
&lt;li&gt;Are you using app_timer2 in your application?&lt;/li&gt;
&lt;li&gt;Which SDK version are you using?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>