<?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>Most efficient way to delay a few microseconds on nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115859/most-efficient-way-to-delay-a-few-microseconds-on-nrf52840</link><description>Just for fun, I thought it&amp;#39;d be interesting to see how to implement a delay on the nrf52840 using the least possible power. 
 For any long period of time, you should use RTC, TIMER, and then put the processor into a lower power state, but I needed some</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Oct 2024 09:26:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115859/most-efficient-way-to-delay-a-few-microseconds-on-nrf52840" /><item><title>RE: Most efficient way to delay a few microseconds on nrf52840</title><link>https://devzone.nordicsemi.com/thread/508475?ContentTypeID=1</link><pubDate>Wed, 30 Oct 2024 09:26:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ae58c6f-406c-4f96-914b-ac3243c23790</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi jthlim,&lt;/p&gt;
&lt;p&gt;I agree. I will forward this internally. Even it&amp;#39;s only applied for short delay, I think there is many use cases that get benefit from this lower power consumption wait.&amp;nbsp;&amp;nbsp;Will let you know when I have a feedback.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Most efficient way to delay a few microseconds on nrf52840</title><link>https://devzone.nordicsemi.com/thread/508224?ContentTypeID=1</link><pubDate>Mon, 28 Oct 2024 16:33:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c4066b3-e0fa-4945-90a6-faafb19cd0c5</guid><dc:creator>jthlim</dc:creator><description>&lt;p&gt;As I mentioned in my original post, yes, any moderate time you should use something other than a busy loop. My use case is just for 5us.&amp;nbsp;I&amp;#39;m also using DCDCEN.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In your tests, if you invert a and b, you&amp;#39;re going to have different power consumption -- that&amp;#39;s completely expected. udiv clock cycles from 2-12 cycles on the M4, so your decode/fetch will be way more active when it&amp;#39;s 2 cycles per instruction rather than 12.&lt;/p&gt;
&lt;p&gt;Optimization is currently at -O2, and no intention to change this for my project. &amp;nbsp;It produces the following:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;00027534 &amp;lt;_ZN9Nrf5Clock11DelayMicrosEm&amp;gt;:&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 27534: f04f 31ff mov.w r1, #4294967295 @ 0xffffffff&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 27538: 2201 movs r2, #1&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 2753a: fbb1 f3f2 udiv r3, r1, r2&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 2753e: fbb1 f3f2 udiv r3, r1, r2&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 27542: fbb1 f3f2 udiv r3, r1, r2&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 27546: fbb1 f3f2 udiv r3, r1, r2&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 2754a: fbb1 f3f2 udiv r3, r1, r2&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 2754e: 3801 subs r0, #1&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 27550: d1f3 bne.n 2753a &amp;lt;_ZN9Nrf5Clock11DelayMicrosEm+0x6&amp;gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt; 27552: 4770 bx lr&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:monospace;"&gt;At the end of the day, it&amp;#39;s not a huge difference as I&amp;#39;m only using it for tiny delays; but afaik no reason not to do it this way :)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Most efficient way to delay a few microseconds on nrf52840</title><link>https://devzone.nordicsemi.com/thread/508216?ContentTypeID=1</link><pubDate>Mon, 28 Oct 2024 15:47:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0176bc51-2dd7-49e8-b1ce-795da398449f</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi jthlim,&amp;nbsp;&lt;br /&gt;Thanks for the interesting post. I can confirm what you reported. I have checked a little bit internally. What I was told is that the consumption of the CPU depends largely on the what&amp;#39;s put on the bus and if the instruction is executed from CACHE or RAM.&amp;nbsp;&lt;br /&gt;The number we provided in the specification was measured when the CPU running CoreMark test, which I assume involve random values on the bus.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;When I invert the value of a and b in your function, I can already see that the power consumption jumped drastically to over what&amp;#39;s the &lt;span&gt;nrf_delay_us()&amp;nbsp;&lt;/span&gt;consume.&amp;nbsp;You can see in the attached graph, the function with inverted a and b is called right after yours&amp;nbsp;&lt;span&gt;DelayMicros:&lt;br /&gt;&lt;br /&gt;&lt;/span&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/pastedimage1730129776544v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;The next one is when I keep b=1 and a=0xFFFF, the power consumption is much lower and near what you have.&amp;nbsp;&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/pastedimage1730130029598v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;We can clearly see that the value on the bus is really affecting the power consumption.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Have you tried to test with different optimization level to see if the power consumption is changed and if the timing is consistent ? I thing the timing may not be the same when you change the optimization level.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;How long do you need the delay ? If it&amp;#39;s &amp;gt;500us, using a TIMER and put the CPU to IDLE maybe a better option.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Most efficient way to delay a few microseconds on nrf52840</title><link>https://devzone.nordicsemi.com/thread/508020?ContentTypeID=1</link><pubDate>Sat, 26 Oct 2024 20:30:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9229a01-54f3-454b-ba96-f8f2b0a10354</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Nice post! I confirm your findings for reduced power consumption on a nRF52832 which I happen to have running with nothing attached to any pins and no errata workarounds; IAR compiler. This is useful.&lt;/p&gt;
&lt;p&gt;Conditions are 3.3VDD supply, DCD enabled&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void TestDelayMicros(void)
{
   NRF_POWER-&amp;gt;DCDCEN = 1;
   while(1)
   {
       DelayMicros(1000);  // 1.96mA with VDD supply 3.3V, DCDCEN enabled
     //nrf_delay_us(1000); // 2.61mA with VDD supply 3.3V, DCDCEN enabled
   }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>