<?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>RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/81242/rtc-timer-re-initialization</link><description>Hi, 
 I have nRF52840 DK and am using nRF5_SDK_17.0.2_d674dde. 
 I am not using SoftDevice, and Zephyr RTOS. 
 I have a simple program and using RTC0 timer. My code snippet: 
 const uint32_t m_dwPreScales[10]={ 4095,1365,819,585,455, 315,273,195,151,105</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Nov 2021 10:13:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/81242/rtc-timer-re-initialization" /><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/337032?ContentTypeID=1</link><pubDate>Tue, 02 Nov 2021 10:13:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daff5f15-0943-4091-9461-ec68a1030dd6</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi David&lt;/p&gt;
&lt;p&gt;The peripheral registers are&amp;nbsp;running off of the 16MHz peripheral clock, so&amp;nbsp;you&amp;nbsp;should be able to access these&amp;nbsp;much faster than the LFCLK, but the RTC module itself might not read the value until the next tick happens.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I notice from the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/rtc.html?cp=4_0_0_5_21_9_13#register.PRESCALER"&gt;PRESCALER section&lt;/a&gt; in the product specification that you can only write the PRESCALER value while the RTC is stopped, and quite possibly you need to wait for one LFCLK period after stopping the RTC in order to ensure it is fully stopped.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The CC registers does not have this limitation, and can be changed at any time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;While it is a bit more work to change the PRESCALER value, this is not something that is usually done dynamically. Most applications use a static PRESCALER value, and simply change the CC values instead when changing the wakeup interval.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/336896?ContentTypeID=1</link><pubDate>Mon, 01 Nov 2021 14:00:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ae82128-8b2d-4fb9-93cb-62bdf30cfc90</guid><dc:creator>TigerD</dc:creator><description>&lt;p&gt;Hi Torbjorn,&lt;/p&gt;
&lt;p&gt;I am good and you can close the case for me. Thank you for your help.&lt;/p&gt;
&lt;p&gt;But just as feedback, I have tested that CC[] can be dynamically reinitialized, except prescaler. Although the re-initialization&amp;nbsp; is in the ISR, but the interrupt and tasks are stopped before initialization. So it shouldn&amp;#39;t matter. Also RTC is on LFCLK, but the registers for RTC is on another CLK as CPU? I validated prescaler by read-out into a variable. I am not sure why CC can be reinitialized while Prescaler not. As I said, I am good and I can fix the prescaler all the time, and just change CC values.&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;David Zhou&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/336888?ContentTypeID=1</link><pubDate>Mon, 01 Nov 2021 13:46:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f099f9b-3a17-4f25-890c-0371466c1578</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi David&lt;/p&gt;
&lt;p&gt;Sounds good. Unless you have more questions I will consider the case resolved then &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;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/336863?ContentTypeID=1</link><pubDate>Mon, 01 Nov 2021 12:48:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:163110eb-2dd2-418a-8c97-b5809550cb3b</guid><dc:creator>TigerD</dc:creator><description>&lt;p&gt;Hi Torbjorn&lt;/p&gt;
&lt;p&gt;Thank you so much for your code review, explanation, and solutions for me.&lt;/p&gt;
&lt;p&gt;I now realized that RTC in on LFCLK, it needs time to settle or for prescaler, etc. to take effective. I will resolve it my self based on my application.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/336859?ContentTypeID=1</link><pubDate>Mon, 01 Nov 2021 12:40:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce695792-7c60-4658-b0a6-10b19a5ebf73</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi David&lt;/p&gt;
&lt;p&gt;I can&amp;#39;t see any obvious mistake in the code, other than the fact that it is a bit unorthodox to reconfigure the entire peripheral and it&amp;#39;s interrupt inside&amp;nbsp;its own interrupt handler.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What happens if you rather try just to clear the RTC timer when the&amp;nbsp;&lt;span&gt;EVENTS_COMPARE[1]&amp;nbsp;interrupt happens, and only do a full re-initialize every 10 seconds or so (either by using a separate timer to schedule this, or by checking a counter inside the interrupt and wait for the counter to reach a certain value)?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also, you could try just to run the rtc_initialize() function from main rather than interrupt context, by setting a flag in the interrupt handler that you can check from the main loop.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards&lt;br /&gt;Torbjørn&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/336856?ContentTypeID=1</link><pubDate>Mon, 01 Nov 2021 12:32:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72b0ce44-dc71-416e-a2b5-9167a72869f4</guid><dc:creator>TigerD</dc:creator><description>&lt;p&gt;Hi Dmitry,&lt;/p&gt;
&lt;p&gt;Thank you for your help. I believe this is the case. I will test it out.&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;David Zhou&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC Timer re-initialization</title><link>https://devzone.nordicsemi.com/thread/336747?ContentTypeID=1</link><pubDate>Sat, 30 Oct 2021 10:09:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17211b74-29dd-4b43-b028-58a9250139c3</guid><dc:creator>Dmitry</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;if I understood your question right - RTC is clocked from LFCLK and thus has up to 46 usec delay from writing to TASK register to actual task execution. Try to add nfr_delay_us(50) after stopping timer - this will ensure that PRESCALER is written when timer is stopped.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>