<?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>Timer can&amp;#39;t generate a &amp;lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92626/timer-can-t-generate-a-10-s-clock-what-did-i-do-wrong</link><description>Hi Nordic community, 
 
 I&amp;#39;m trying to generate a 1 MHz base clock with one of the peripheral timer, and in the timer ISR does some GPIO toggling. 
 I followed the nRF5 SDK example and just toggle one GPIO in the ISR to test the clock frequency. I notice</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Dec 2022 12:34:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92626/timer-can-t-generate-a-10-s-clock-what-did-i-do-wrong" /><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/398530?ContentTypeID=1</link><pubDate>Thu, 01 Dec 2022 12:34:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:453c3a53-b4c4-47ce-927c-64c7f55977d3</guid><dc:creator>msedlak</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You haven&amp;#39;t done anything wrong. Your&amp;nbsp;timer configuration is correct.&lt;/p&gt;
&lt;p&gt;As mentioned, you should disable the Softdevice (or better use just a simple periphery/timer sample, where no SD is presented).&lt;/p&gt;
&lt;p&gt;Now to the point - I got similar results as you, the main difference happens when you enable the compiler&amp;nbsp;&lt;span&gt;optimizations&lt;/span&gt;, since you probably have &amp;quot;none&amp;quot; optimizations.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Use optimization level - Level 3 for more speed.&lt;/p&gt;
&lt;p&gt;With this, I was able to get the lowest pin toggle time within the timer callback down to cca 3.5 us.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I doubt you will ever go below 3 us, without touching the SDK itself and replacing all the &amp;quot;generic&amp;quot; stuff around the IRQ handlers and callbacks, to target your specific application.&lt;/p&gt;
&lt;p&gt;namely timer IRQ handler, where all channels are checked.&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/pastedimage1669897894125v2.png" /&gt;&lt;/p&gt;
&lt;p&gt;64 MHz core clock = 15.625 ns, meaning 64 clock cycles per 1 us.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I hope now you know what the issue is.&lt;/p&gt;
&lt;p&gt;Note:&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve simplified the irq_handler just for clearing the event and calling my callback:&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/pastedimage1669898690802v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;And with setting the timer for 1 us, and doing pin toggle in the timer&amp;#39;s callback, the result is:&lt;/p&gt;
&lt;p&gt;Digital:&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/pastedimage1669898744479v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Analog:&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/pastedimage1669898761401v4.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Milan&lt;/p&gt;
&lt;div id="WidgetFloaterPanels" class="LTRStyle" style="direction:ltr;display:none;text-align:left;"&gt;
&lt;div id="WidgetFloater" style="display:none;"&gt;
&lt;div id="WidgetLogoPanel"&gt;&lt;span id="WidgetTranslateWithSpan"&gt;&lt;span&gt;TRANSLATE with &lt;/span&gt;&lt;/span&gt; &lt;span id="WidgetCloseButton" title="Exit Translation"&gt;x&lt;/span&gt;&lt;/div&gt;
&lt;div id="LanguageMenuPanel"&gt;
&lt;div class="DDStyle_outer"&gt;&lt;span id="__LanguageMenu_header" class="DDStyle"&gt;English&lt;/span&gt;
&lt;div style="left:0;position:relative;text-align:left;"&gt;
&lt;div style="position:absolute;"&gt;
&lt;div id="__LanguageMenu_popup" class="DDStyle" style="display:none;"&gt;
&lt;table id="LanguageMenu" border="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#ar"&gt;Arabic&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#he"&gt;Hebrew&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#pl"&gt;Polish&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#bg"&gt;Bulgarian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#hi"&gt;Hindi&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#pt"&gt;Portuguese&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#ca"&gt;Catalan&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#mww"&gt;Hmong Daw&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#ro"&gt;Romanian&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#zh-CHS"&gt;Chinese Simplified&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#hu"&gt;Hungarian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#ru"&gt;Russian&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#zh-CHT"&gt;Chinese Traditional&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#id"&gt;Indonesian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#sk"&gt;Slovak&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#cs"&gt;Czech&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#it"&gt;Italian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#sl"&gt;Slovenian&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#da"&gt;Danish&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#ja"&gt;Japanese&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#es"&gt;Spanish&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#nl"&gt;Dutch&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#tlh"&gt;Klingon&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#sv"&gt;Swedish&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#en"&gt;English&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#ko"&gt;Korean&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#th"&gt;Thai&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#et"&gt;Estonian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#lv"&gt;Latvian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#tr"&gt;Turkish&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#fi"&gt;Finnish&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#lt"&gt;Lithuanian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#uk"&gt;Ukrainian&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#fr"&gt;French&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#ms"&gt;Malay&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#ur"&gt;Urdu&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#de"&gt;German&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#mt"&gt;Maltese&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#vi"&gt;Vietnamese&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#el"&gt;Greek&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#no"&gt;Norwegian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#cy"&gt;Welsh&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="#ht"&gt;Haitian Creole&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="#fa"&gt;Persian&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="CTFLinksPanel"&gt;&lt;span id="ExternalLinksPanel"&gt;&lt;a id="HelpLink" title="Help" href="https://go.microsoft.com/?linkid=9722454" rel="noopener noreferrer" target="_blank"&gt; &lt;/a&gt; &lt;a id="EmbedLink" title="Get this widget for your own site"&gt;&lt;/a&gt;  &lt;a id="ShareLink" title="Share translated page with friends"&gt;&lt;/a&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div id="FloaterProgressBar"&gt;&lt;span id="ProgressFill"&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id="WidgetFloaterCollapsed" style="display:none;"&gt;&lt;span&gt;TRANSLATE with &lt;/span&gt;&lt;/div&gt;
&lt;div id="FloaterSharePanel" style="display:none;"&gt;
&lt;div id="ShareTextDiv"&gt;&lt;span id="ShareTextSpan"&gt; COPY THE URL BELOW &lt;/span&gt;&lt;/div&gt;
&lt;div id="ShareTextboxDiv"&gt;&lt;!--a id="TwitterLink" title="Share on Twitter"&gt; &lt;img id="TwitterImg" /&gt;&lt;/a&gt; &lt;a--&gt;  &lt;a id="EmailLink" title="Email this translation"&gt;&lt;/a&gt; &lt;/div&gt;
&lt;div id="ShareFooter"&gt;&lt;span id="ShareHelpSpan"&gt;&lt;a id="ShareHelpLink"&gt;&lt;/a&gt; &lt;/span&gt; &lt;span id="ShareBackSpan"&gt;&lt;a id="ShareBack" title="Back To Translation"&gt;&lt;/a&gt; Back&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id="FloaterEmbed" style="display:none;"&gt;
&lt;div id="EmbedTextDiv"&gt;&lt;span id="EmbedTextSpan"&gt;EMBED THE SNIPPET BELOW IN YOUR SITE&lt;/span&gt; &lt;a id="EmbedHelpLink" title="Copy this code and place it into your HTML."&gt;&lt;/a&gt; &lt;/div&gt;
&lt;div id="EmbedTextboxDiv"&gt;&lt;/div&gt;
&lt;div id="EmbedNoticeDiv"&gt;&lt;span id="EmbedNoticeSpan"&gt;Enable collaborative features and customize widget: &lt;a href="http://www.bing.com/widget/translator" rel="noopener noreferrer" target="_blank"&gt;Bing Webmaster Portal&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div id="EmbedFooterDiv"&gt;&lt;span id="EmbedBackSpan"&gt;Back&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="TnITTtw-translate-selection-button" style="left:10.3438px;top:518px;"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389819?ContentTypeID=1</link><pubDate>Fri, 07 Oct 2022 12:17:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abcad2d0-30fb-4f80-b642-5f62fe89e68f</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I will advice against using stalling for creating delays, regardless of the SDK version used. By default, the system clock in Zephyr runs from the 32.768 kHz clcok, which will not allow you to achieve the frequency you want. Using interrupts will allow you to set the priority of the task higher than other tasks in the application, and it will allow you to put the CPU to sleep for longer periods of time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389679?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 15:33:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cddc28b6-aaf4-499d-8cf4-d2cf3057a2ff</guid><dc:creator>xxb9075</dc:creator><description>&lt;p&gt;I will try your recommendations. The PPI does not work since I need more than 8 GPIOs. But nRF52840 has only 8 GPIOTEs.&lt;/p&gt;
&lt;p&gt;May I also ask, since we are shifting to nRF Connect SDK, the Zephyr k_sleep function seem to be a function to implement the delay while not keeping CPU engaged. Would you suggest if it&amp;#39;s a viable idea to use some blocking delay APIs from Zephyr instead?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389676?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 15:20:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60140fea-9e2a-475f-b0aa-83b01f7540cf</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You may try polling the register directly instead of using interrupt, but it is not a good long-term solution if you want to keep low power and allow the CPU to perform other tasks.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You should also try the timer code in a standalone application without the Softdevice present, to see if you get the expected latency.&lt;/p&gt;
&lt;p&gt;If you want fully predictable latency, you need to use PPI to trigger tasks when the timer fires, but if this is a viable solution in your application depends on what you want the timer to do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389606?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 11:47:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4a21deb-f20a-4cbc-8fe5-4ad11a82b36c</guid><dc:creator>xxb9075</dc:creator><description>&lt;p&gt;I think I tried removing __WFI() too though.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Would you suggest how to disable softdevice so I can try to locate if it is the problem?&lt;/p&gt;
&lt;p&gt;And would it be better to just use no interrupt?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389593?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 11:21:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e978daeb-341c-4ecf-8963-c8382cb3f1fd</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Some of the latency might also come from the device starting up from sleep, see&amp;nbsp;&lt;span&gt;t&lt;/span&gt;&lt;sub&gt;IDLE2CPU&lt;/sub&gt;&amp;nbsp;in&amp;nbsp;&lt;a title="Device startup times" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=4_0_0_4_2_7_2#unique_1752780615"&gt;Device startup times&lt;/a&gt;. You can try to remove the call to __WFI() and check if this reduces the latency time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389580?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 10:44:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b06dbef3-c623-4f06-bb99-6877e18b6fda</guid><dc:creator>xxb9075</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;J&amp;oslash;rgen,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m using the ble_app_template from nRF5 SDK examples, thus I think the Softdevice is present. How can I know for sure if it is from the softdevice alone? Since after all, I&amp;#39;m trying to set the timer period to 1 &amp;mu;s, but I got 10.6&amp;mu;s, which added more than 4 &amp;mu;s.&lt;/p&gt;
&lt;p&gt;Is it only going to affect interrupts, meaning I can probably just poll the timer compare event instead of using interrupts?&lt;/p&gt;
&lt;p&gt;And I did tried to switch between 16 MHz / 1MHz and check nrfx_timer_us_to_ticks () return value, the value makes sense.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Richard&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Timer can't generate a &lt;10 μs clock, what did I do wrong?</title><link>https://devzone.nordicsemi.com/thread/389573?ContentTypeID=1</link><pubDate>Thu, 06 Oct 2022 10:23:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b587731-2fbc-4bca-ba74-0e2be5b4de94</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Is this your full code, or just a part of it? Do you have a Softdevice on your chip? The Softdevice will increase interrupt latency up to 4 us, see&amp;nbsp;&lt;a title="Interrupt latency due to System on Chip framework" href="https://infocenter.nordicsemi.com/topic/sds_s132/SDS/s1xx/processor_avail_interrupt_latency/interrupt_latency_soc_framework.html?cp=4_7_3_0_15_0_1"&gt;Interrupt latency due to System on Chip framework&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If there is no Softdevice and no other peripherals enabled; did you check if the value returned from&amp;nbsp;nrfx_timer_us_to_ticks() makes sense? Have you tried increasing the frequency of the timer to 16 MHz?&lt;/p&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>