<?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>Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/51946/accurate-sample-rate-with-ncs</link><description>Are there any examples of sampling something like an I2C bus at a constant sample rate? I have seen issues myself with the k_sleep and k_busy_wait not giving accurate delays. Tested with a salae logic analyser. I haven&amp;#39;t tested the timings of the k_timer</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Sep 2019 12:17:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/51946/accurate-sample-rate-with-ncs" /><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/209420?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 12:17:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e209c4b-2bb6-4765-a267-7684097326ce</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Glad to hear that you got it working.&lt;/p&gt;
[quote user="RonanB96"]Is there a reason there is manual changes needed in the SDK to enable RTC0 in the non-secure domain?[/quote]
&lt;p&gt;I do not have a good answer here, other than the inherited behavior from Cortex M33 core, as all peripherals reset value is secure mode. Since the modem requires you to be in non-secure mode in order to communicate with it, it is then normal that the application would also reside in this defined area. I&amp;#39;ll input this to the developers as a feature request, ie: set most peripherals to non-secure.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/209421?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2019 12:17:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d7f53ab-b65b-4114-a340-5a2f1c373c2d</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Glad to hear that you got it working.&lt;/p&gt;
[quote user="RonanB96"]Is there a reason there is manual changes needed in the SDK to enable RTC0 in the non-secure domain?[/quote]
&lt;p&gt;I do not have a good answer here, other than the inherited behavior from Cortex M33 core, as all peripherals reset value is secure mode. Since the modem requires you to be in non-secure mode in order to communicate with it, it is then normal that the application would also reside in this defined area. I&amp;#39;ll input this to the developers as a feature request, ie: set most peripherals to non-secure.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/209275?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 21:28:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59462256-816e-4d01-a8e5-f4ed35e51c6a</guid><dc:creator>RonanB96</dc:creator><description>&lt;p&gt;Ok got it working now, didn&amp;#39;t know I needed to add this to&amp;nbsp;ncs/nrf/subsys/spm/Kconfig as well make the change in spm.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;config SPM_NRF_RTC0_NS
	bool &amp;quot;RTC0 is Non-Secure&amp;quot;
	default y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is there a reason there is manual changes needed in the SDK to enable RTC0 in the non-secure domain?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/209118?ContentTypeID=1</link><pubDate>Wed, 11 Sep 2019 09:27:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9c35a6cf-850f-4cf7-a01c-ae671b94b655</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I took the rtc sample from nRF5 SDK and did a port of it and put it here:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/nrfx/rtc"&gt;https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/nrfx/rtc&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try it and see if it works at your end?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/209005?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 14:53:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1e399ca-9f13-4c47-852a-97ed0bed649e</guid><dc:creator>RonanB96</dc:creator><description>&lt;p&gt;Hi Hakon,&lt;/p&gt;
&lt;p&gt;I tried implementing the timer with RTC0 but it is crashing when I try writing to the Prescaler register within&amp;nbsp;nrfx_rtc_init.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;__STATIC_INLINE void nrf_rtc_prescaler_set(NRF_RTC_Type * p_reg, uint32_t val)
{
    NRFX_ASSERT(val &amp;lt;= (RTC_PRESCALER_PRESCALER_Msk &amp;gt;&amp;gt; RTC_PRESCALER_PRESCALER_Pos));
    p_reg-&amp;gt;PRESCALER = val;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The timer instance and configuration seem ok&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;__func__                      &amp;quot;nrfx_rtc_init&amp;quot;    0x00030aec    14    const char[14]                
handler                       0x0002a9f7         r2            4     void(nrfx_rtc_int_type_t)*    
    *                         rtc_handler        0x0002a9f7    2     void(nrfx_rtc_int_type_t)     
p_config                      0x20024be0         r1            6     const nrfx_rtc_config_t*      
    *                         &amp;lt;struct&amp;gt;           0x20024be0    6     struct                        
        prescaler             327                0x20024be0    2     short unsigned int            
        interrupt_priority    7                  0x20024be2    1     unsigned char                 
        tick_latency          65                 0x20024be3    1     unsigned char                 
        reliable              false              0x20024be4    0     _Bool                         
p_instance                    0x00030a88         r0            8     const nrfx_rtc_t*             
    *                         &amp;lt;struct&amp;gt;           0x00030a88    8     struct                        
        p_reg                 0x40014000         0x00030a88    4     NRF_RTC_Type*                 
        irq                   RTC0_IRQn          0x00030a8c    1     enum                          
        instance_id           0x00               0x00030a8d    1     unsigned char                 
        cc_channel_count      0x04               0x00030a8e    1     unsigned char                 
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And I made this change in spm to move it to the non-secure domain&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;diff --git a/subsys/spm/spm.c b/subsys/spm/spm.c
index ec00037..23b7ecf 100644
--- a/subsys/spm/spm.c
+++ b/subsys/spm/spm.c
@@ -287,6 +287,7 @@ static void spm_config_peripherals(void)
        static const struct periph_cfg periph[] = {
                PERIPH(&amp;quot;NRF_P0&amp;quot;, NRF_P0, CONFIG_SPM_NRF_P0_NS),
                PERIPH(&amp;quot;NRF_CLOCK&amp;quot;, NRF_CLOCK, CONFIG_SPM_NRF_CLOCK_NS),
+               PERIPH(&amp;quot;NRF_RTC0&amp;quot;, NRF_RTC0, CONFIG_SPM_NRF_RTC0_NS),
                PERIPH(&amp;quot;NRF_RTC1&amp;quot;, NRF_RTC1, CONFIG_SPM_NRF_RTC1_NS),
                PERIPH(&amp;quot;NRF_NVMC&amp;quot;, NRF_NVMC, CONFIG_SPM_NRF_NVMC_NS),
                PERIPH(&amp;quot;NRF_UARTE1&amp;quot;, NRF_UARTE1, CONFIG_SPM_NRF_UARTE1_NS),&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;See what the issue is here?&lt;/p&gt;
&lt;p&gt;Also I added &amp;quot;CONFIG_COMPILER_OPT=&amp;quot;-DNRFX_RTC_ENABLED=1 -DNRFX_RTC0_ENABLED=1&amp;quot;&amp;quot; to get it to compile&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/208824?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 07:53:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6c7065f4-2c8e-40b3-bbf7-ef4b80caf174</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I can confirm that k_* timed functions in &amp;lt; 10 ms are very jittery. Even a k_timer instance will not be matching 100 Hz directly (measured to 12 ms at my end).&lt;/p&gt;
&lt;p&gt;What I can recommend is to use either a high speed TIMER, or use RTC0 (RTC1 used by the kernel), to generate this event. RTC0 will be able to give 32768/328 Hz = ~99,9 Hz, but would require the use of either nrfx driver or bare metal implementation. If you want to look at selecting the nrfx driver, I have a project here where other nrfx components are manually selected in the application kconfig (required at this time, due to entries having no prompt):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/nrfx_timed_signal/Kconfig"&gt;https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/nrfx_timed_signal/Kconfig&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/208802?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 06:59:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b3a6003-70f5-4ae2-be59-333ef3169b74</guid><dc:creator>RonanB96</dc:creator><description>&lt;p&gt;We require a sample rate of 100hz for a Max of 60s.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is there issues with the accuracy of the k_timers on the nrf91 similar to the zpehyr issue above?&lt;/p&gt;
&lt;p&gt;When I was checking&amp;nbsp; k_delay and k_busywait with a delay of 1ms, I was measuring a delay between&amp;nbsp; 2-8ms, I was toggling an led and measuring with a logic analyser. There was no other tasks running and this was being called in a loop&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accurate sample rate with ncs</title><link>https://devzone.nordicsemi.com/thread/208796?ContentTypeID=1</link><pubDate>Tue, 10 Sep 2019 06:43:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69d4732a-e4d5-41ad-a0ad-5f3ebd45f8be</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;What are your requirements in terms of constant? What delay (us/ms/s?) are you looking for?&lt;/p&gt;
&lt;p&gt;Have you tried running a &lt;a href="https://docs.zephyrproject.org/1.9.0/kernel/threads/workqueues.html"&gt;work queue&lt;/a&gt; or a &lt;a href="https://docs.zephyrproject.org/1.11.0/kernel/timing/timers.html"&gt;kernel timer&lt;/a&gt; instance?&lt;/p&gt;
&lt;p&gt;Note that the K_TIMER runs in interrupt context, so taking semaphores shouldn&amp;#39;t be done directly in the callback.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>