<?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>NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105757/nrf-hardware-timer-issue</link><description>Hi, 
 I am currently working on hardware timer (nrfx) with configured timing as 40 ms and facing some issue with the timing , have attached two scenarios please have a look. 
 (please refer the code attached) 
 
 1) Senario 1 (please refer code attached</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 Nov 2023 11:25:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105757/nrf-hardware-timer-issue" /><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457810?ContentTypeID=1</link><pubDate>Tue, 28 Nov 2023 11:25:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e89d488-bab5-4035-8e42-73105de6aa0a</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Good to hear that this solved the issue &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;I will consider the case resolved then.&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: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457524?ContentTypeID=1</link><pubDate>Mon, 27 Nov 2023 10:44:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bee5ca2-e437-484e-98f1-a2cc6f2c0719</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks Overbekk for your valuable replies.&lt;/p&gt;
&lt;p&gt;our current issue is solve by adding&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;span&gt;ISR_DIRECT_HEADER();&lt;br /&gt;/* ISR code */&lt;br /&gt;ISR_DIRECT_PM();&lt;br /&gt;ISR_DIRECT_FOOTER(1)&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;in callback.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457477?ContentTypeID=1</link><pubDate>Mon, 27 Nov 2023 08:47:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ddde3b8-e54b-4a06-8daa-9f52bc20bd33</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This does sound like a classic issue of not setting the interrupt up properly in Zephyr.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1) I can&amp;#39;t see that you call the irq_enable(..) function anywhere, is this true?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2) I can&amp;#39;t remember seeing the&amp;nbsp;&lt;em&gt;#if defined(__ZEPHYR__)&lt;/em&gt; check in code before. Are you sure that this actually gets enabled?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;3) When using the IRQ_DIRECT_CONNECT macro it is also necessary to add some additional lines of code to the interrupt handler itself, as shown &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/subsys/esb/esb.c#L1359-L1366"&gt;here&lt;/a&gt;. Could you try to add the call to ISR_DIRECT_PM(); at the end of the timer handler function and see if it fixes the issue?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457310?ContentTypeID=1</link><pubDate>Fri, 24 Nov 2023 10:57:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37d109ad-18f8-4f2c-ae46-e8c8d805e70f</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Thanks&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/ovrebekk"&gt;ovrebekk&lt;/a&gt;&amp;nbsp;for the reply.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;1) There are no other threads.&lt;/p&gt;
&lt;p&gt;2) In main loop&amp;nbsp;k_event_init and starting the hardware timer then toggle led.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3)&amp;nbsp;&amp;nbsp;nrf5340dk_nrf5340_cpuapp is the&amp;nbsp;board file used&amp;nbsp;to build code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;4) checked and conform that&amp;nbsp;&lt;/p&gt;
&lt;p&gt;CONFIG_CLOCK_CONTROL_NRF=y&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC is not set&lt;br /&gt;CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH is not set&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM is not set&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM is not set&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM is not set&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM is not set&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM is not set&lt;br /&gt;CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM=y&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM is not set&lt;br /&gt;# CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM is not set&lt;br /&gt;CONFIG_CLOCK_CONTROL_NRF_ACCURACY=50&lt;br /&gt;# CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK is not set&lt;/p&gt;
&lt;p&gt;these configurations are there in&amp;nbsp;&lt;span&gt;build/zephyr..&amp;nbsp; .&lt;/span&gt;config file.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My question is,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Our Hardware timer is triggering properly, and we are able to pass the timer trigger using a global variable and it works fine. See the scenario one above. But when we change this to an OS event / semaphore it&amp;#39;s not working properly, seems like OS is not triggering when I&amp;nbsp;enable the&amp;nbsp;event&amp;nbsp;flag or giving the semaphore inside the timer function.&lt;/p&gt;
&lt;p&gt;DO you have any thoughts on this?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457284?ContentTypeID=1</link><pubDate>Fri, 24 Nov 2023 09:23:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb1c06f8-5b22-48eb-8ecd-059ad5e87ad7</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
[quote user="c3_nithin"]when I try with 20ms, Iam not able to get desired output inside the thread function.[/quote]
&lt;p&gt;Could there be any other threads in your application that is using a lot of CPU time?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What are you doing in the main loop?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It seems the thread processing is getting delayed intermittently, since you suddenly get a long delay, and then you get a quick toggle as the thread is running twice in rapid succession. Are you doing nothing in the thread other than setting the pin state?&amp;nbsp;&lt;/p&gt;
[quote user="c3_nithin"]&lt;p&gt;&lt;strong&gt;1) how&amp;nbsp;to switch to LFXO (external LF crystal) . con you guide me on it?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1) how to enable&amp;nbsp;LFXO&amp;nbsp;in prj.confg&amp;nbsp; ?&lt;/strong&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Which board file are you using to build your code?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Typically the board file will automatically enable the external LF crystal if your board supports it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As an example, if you build for the nrf5340dk_nrf5340_cpuapp board this will be set by default.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In other words it should be sufficient to remove the configuration where you enable the internal clock source.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In order to verify which LF clock source is enabled you can open the .config file in the build/zephyr folder. It should include a section like this if you have successfully enabled LFXO:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_CLOCK_CONTROL_NRF=y
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC is not set
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM is not set
CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM=y
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM is not set
# CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM is not set
CONFIG_CLOCK_CONTROL_NRF_ACCURACY=50
# CONFIG_CLOCK_CONTROL_FIXED_RATE_CLOCK is not set&lt;/pre&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: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457172?ContentTypeID=1</link><pubDate>Thu, 23 Nov 2023 13:13:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2976c8e9-f91e-40dc-97c0-de3da664f7b4</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;when&amp;nbsp;I try with 100ms the timer with semaphore, it works fine.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/hardware_5F00_semaphore_5F00_100ms_5F00_timer.jpg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;when I try with 20ms, Iam not able to get desired output inside the thread function.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/hardware_5F00_semaphore_5F00_20ms_5F00_timer.mp4"&gt;devzone.nordicsemi.com/.../hardware_5F00_semaphore_5F00_20ms_5F00_timer.mp4&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/hardware_5F00_semaphore_5F00_20ms_5F00_timer.jpg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1) how&amp;nbsp;to switch to LFXO (external LF crystal) . con you guide me on it?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1) how to enable&amp;nbsp;LFXO&amp;nbsp;in prj.confg&amp;nbsp; ?&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/457106?ContentTypeID=1</link><pubDate>Thu, 23 Nov 2023 09:54:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:268232fb-813e-4e29-b5b5-696216cbd480</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nithin&lt;/p&gt;
[quote user="c3_nithin"]Iam getting the pulse&amp;nbsp;of width 21.2ms in the callback as well as in the thread function.[/quote]
&lt;p&gt;If you are using internal RC source for the LF clock then you will not get a very accurate clock source.&amp;nbsp;You would either have to switch to LFXO (external LF crystal), or use a TIMER module and request external HFXO like described in my previous reply.&amp;nbsp;&lt;/p&gt;
[quote user="c3_nithin"]I need precise 20ms.[/quote]
&lt;p&gt;How precise?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;No clock source is 100% correct. It is important to define how much drift/offset you can accept, and design your system&amp;nbsp;with this in mind.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you can define this it is also easier for us to advice you.&amp;nbsp;&lt;/p&gt;
[quote user="c3_nithin"]&lt;p&gt;Iam passing the control from timer to thread function using OS flag:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;strong&gt;k_event_set(event_data, TIMER_EVENT_BIT);&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;do I need to call any other Api&amp;nbsp;other than&amp;nbsp;this.&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;[/quote]
&lt;p&gt;I don&amp;#39;t have a lot of experience using events for this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you try to use a semaphore instead and see if it works better?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Using a semaphore is very easy, and is documented in more detail &lt;a href="https://docs.zephyrproject.org/latest/kernel/services/synchronization/semaphores.html"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;All you should need is the following code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// At the top of main, declare your semaphore
K_SEM_DEFINE(my_sem, 0, 1);

// Inside your timer callback, give the semaphore
k_sem_give(&amp;amp;my_sem);

// In your thread, take the semaphore and use infinite timeout
k_sem_take(&amp;amp;my_sem, K_FOREVER);&lt;/pre&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: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/456871?ContentTypeID=1</link><pubDate>Wed, 22 Nov 2023 10:39:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:28d3aee7-b02a-464e-a36c-7342c61031e4</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;1)&amp;nbsp;&lt;strong&gt;while using software timer&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Iam getting the pulse&amp;nbsp;of width 21.2ms in the callback as well as in the thread function.&lt;/p&gt;
&lt;p&gt;attaching the pulse image.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/software_5F00_timer.jpeg" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;span&gt;&lt;br /&gt;prj.conf&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;CONFIG_CLOCK_CONTROL&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;CONFIG_SYS_CLOCK_TICKS_PER_SEC&lt;/span&gt;&lt;span&gt;=655&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;I need precise 20ms.&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;2) &lt;/span&gt;&lt;strong style="font-family:inherit;"&gt;while using hardware timer&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Iam&amp;nbsp;able&amp;nbsp;to get the precise 20ms (pulse) timing at the callback but unable to get the pulse at the thread function.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;note that Iam having only one thread function. which means max priority.&lt;/p&gt;
&lt;p&gt;Iam passing the control from timer to thread function using OS flag:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;strong&gt;k_event_set(event_data, TIMER_EVENT_BIT);&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;do I need to call any other Api&amp;nbsp;other than&amp;nbsp;this.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;prj.conf&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;CONFIG_CLOCK_CONTROL&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC&lt;/span&gt;&lt;span&gt;=y&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;CONFIG_SYS_CLOCK_TICKS_PER_SEC&lt;/span&gt;&lt;span&gt;=655&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;strong&gt;for your information we are toggling two different GPIOs one in ISR and other in thread.&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;attaching the video&amp;nbsp;recorded of the waveform.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;pink pulse - call back&amp;nbsp;function (timer)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;yellow - thread function.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/hardware_5F00_timer.mp4"&gt;devzone.nordicsemi.com/.../hardware_5F00_timer.mp4&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/456671?ContentTypeID=1</link><pubDate>Tue, 21 Nov 2023 12:41:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c77521cb-361d-473f-8e15-5d1e0a2b64fc</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nithin&lt;/p&gt;
[quote user="c3_nithin"]&amp;nbsp; &amp;nbsp; 1) I need &lt;span&gt;extremely accurate 20 ms timing , so that Iam&amp;nbsp;using hardware timer (nrfx).&lt;/span&gt;[/quote]
&lt;p&gt;k_timer is based on the RTC timer, which is running&amp;nbsp;from the 32.768kHz LF clock source. If you want to time 20ms exactly you will get around 550ppm of offset (not including clock drift),&amp;nbsp;since the closest you get based on the LF source is around 19.989ms (655 ticks at 32.768kHz).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to use the TIMER module you can have a look at an nrfx_timer example I made some while back:&lt;br /&gt;&lt;a href="https://github.com/too1/ncs-nrfx-timer-example"&gt;https://github.com/too1/ncs-nrfx-timer-example&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please note that for the most accurate timing when using the TIMER you need to enable the external HF crystal, which by default will only be enabled when needed by the radio.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For an example of how to permanently enable the external HF crystal please refer to &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/samples/esb/esb_ptx/src/main.c#L71-L102"&gt;this code snippet&lt;/a&gt;.&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: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/456513?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 16:01:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd29563e-85fb-47a9-861d-94faa2b745c0</guid><dc:creator>c3_nithin</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; 1) I need &lt;span&gt;extremely accurate 20 ms timing , so that Iam&amp;nbsp;using hardware timer (nrfx).&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; 2) have attached the clock configuration (clock-source = &amp;quot;ACLK&amp;quot; &amp;amp; &amp;quot;PCLK32M&amp;quot;&amp;nbsp; =&amp;gt; same result).&lt;br /&gt;&amp;nbsp; &amp;nbsp; 3) NRF5340 (FANSTEL EVM-BC40-V0) is the board.&lt;br /&gt;&amp;nbsp; &amp;nbsp; 4)&amp;nbsp;not using external crystal.&lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;b&gt;can you guide&amp;nbsp;me how I could use external timer for k_timer so we can test the&amp;nbsp;same.&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;br /&gt;Attaching overlay configuration (please have a look )&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;clock {
	hfclkaudio-frequency = &amp;lt;12288000&amp;gt;;
};

&amp;amp;uart0 {
    compatible = &amp;quot;nordic,nrf-uarte&amp;quot;;
	current-speed = &amp;lt;921600&amp;gt;;
    status = &amp;quot;okay&amp;quot;;

};

&amp;amp;timer0 {
    status = &amp;quot;okay&amp;quot;;
};

&amp;amp;timer1 {
    status = &amp;quot;okay&amp;quot;;
};


&amp;amp;pinctrl {
	pdm0_default_alt: pdm0_default_alt {
		group1 {
			psels = &amp;lt;NRF_PSEL(PDM_CLK, 1, 12)&amp;gt;,
				&amp;lt;NRF_PSEL(PDM_DIN, 1, 8)&amp;gt;;
		};
	};
};

dmic_dev: &amp;amp;pdm0 {
	status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;pdm0_default_alt&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;;
	clock-source = &amp;quot;ACLK&amp;quot;;
	// clock-source = &amp;quot;PCLK32M_HFXO&amp;quot;;
	// clock-source = &amp;quot;PCLK32M&amp;quot;;
};&lt;/pre&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Attaching prj.config (Please have a look)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_LOG=y
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_LOG_RUNTIME_FILTERING=y
CONFIG_LOG_BUFFER_SIZE=65536
CONFIG_LOG_PRINTK=y
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=0
CONFIG_COVERAGE=n
CONFIG_LOG_TAG_MAX_LEN=8


CONFIG_HEAP_MEM_POOL_SIZE=256


#for RTOS
CONFIG_ASSERT=y
CONFIG_ASSERT_LEVEL=2
CONFIG_CMSIS_RTOS_V2=y
CONFIG_NUM_PREEMPT_PRIORITIES=56
CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_THREAD_NAME=y
CONFIG_THREAD_STACK_INFO=y
CONFIG_THREAD_MONITOR=y
CONFIG_INIT_STACKS=y
CONFIG_POLL=y
CONFIG_SCHED_SCALABLE=y
#CONFIG_SYS_CLOCK_TICKS_PER_SEC=2000
CONFIG_CMSIS_V2_THREAD_MAX_STACK_SIZE=2048
CONFIG_CMSIS_V2_THREAD_DYNAMIC_STACK_SIZE=2048


#for timer
CONFIG_NRFX_TIMER0=y

#for events
CONFIG_EVENTS=y

#for fuel gauge
CONFIG_FUEL_GAUGE=y
CONFIG_MAX17048=y

#for I2C
CONFIG_I2C=y

#for dmic
CONFIG_AUDIO=y
CONFIG_AUDIO_DMIC=y
CONFIG_DMA=y

CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000
CONFIG_SYS_CLOCK_TICKS_PER_SEC=1000
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/456486?ContentTypeID=1</link><pubDate>Mon, 20 Nov 2023 14:59:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f87602d-efa5-422f-a7dc-64ecd688a471</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Nithin&lt;/p&gt;
&lt;p&gt;I will help Jared out with this ticket since he is a bit busy at the moment.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Setting up a k_timer(..) should be the best option from a current consumption point of view, as long as you don&amp;#39;t need extremely accurate timing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If the pulse is only 19.5ms long it is most likely caused by selecting a less accurate LF clock source.&amp;nbsp;&lt;br /&gt;Can you let me know which board you are using, and if you are using an external LF crystal or not?&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF hardware timer issue</title><link>https://devzone.nordicsemi.com/thread/456202?ContentTypeID=1</link><pubDate>Fri, 17 Nov 2023 14:57:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:afe65743-4723-432d-8648-540872fe083f</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I need to get back to you on this question sometime next week,&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>