<?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>Achieving Nanosecond Precise Timing using ASM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105982/achieving-nanosecond-precise-timing-using-asm</link><description>I&amp;#39;m attempting to achieve nano-second precision delays by injecting ASM code like so: 
 
 
 
 
 
 
 
 This works relatively consistently, however, the delay time doesn&amp;#39;t amount to what I expect. 
 
 This particular code is supposed to delay 296.875 ns;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 27 Nov 2023 08:45:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105982/achieving-nanosecond-precise-timing-using-asm" /><item><title>RE: Achieving Nanosecond Precise Timing using ASM</title><link>https://devzone.nordicsemi.com/thread/457475?ContentTypeID=1</link><pubDate>Mon, 27 Nov 2023 08:45:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6f16de0-151e-4b07-9d31-bc574679be86</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;&lt;span&gt;Sorry, I must have overlooked the fact that you wanted nanosecond precision when I wrote my reply. For nanosecond accuracy, you will need to create your own delay implementation as you initially tried. However, instead of using NOPs, you might get better results by basing your implementation on one of the delay functions in nrfx_coredep_delay_us&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;/p&gt;
[quote user="Michael Zeng"]Also, could you elaborate on what you mean by &amp;quot;&lt;span&gt;requesting the 64M crystal oscillator (HFXO)&amp;quot;?&amp;nbsp;Is the nRF52840 not already using its 64M crystal?&lt;/span&gt;[/quote]
&lt;p&gt;It is running of the less accurate&amp;nbsp;&lt;a title="64 MHz internal oscillator (HFINT)" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/clock.html?cp=5_0_0_4_3_3_0#unique_1277246493"&gt;64 MHz internal oscillator (HFINT)&lt;/a&gt;&amp;nbsp;clock source by default.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Achieving Nanosecond Precise Timing using ASM</title><link>https://devzone.nordicsemi.com/thread/457399?ContentTypeID=1</link><pubDate>Sat, 25 Nov 2023 02:46:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:847be6e2-6fcb-4bdb-8dbc-5b271dc10035</guid><dc:creator>Michael Zeng</dc:creator><description>&lt;p&gt;Sorry, I&amp;#39;m not totally sure what you&amp;#39;re suggesting. Form the first link you send, I agree that NOP does not produce a deterministic delay. However, the functions you linked all delay an integer number of microseconds, but I need another order of magnitude of precision--down to a hundred nanoseconds of 0.1 microseconds. Is there any way to achieve that without, for example modifying the functions in &lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/56e0b052dff311c2f8eb08c6804e60fc79feb56f/nrfx/soc/nrfx_coredep.h#L140"&gt;hal_nordic/nrfx/soc/nrfx_coredep.h at 56e0b052dff311c2f8eb08c6804e60fc79feb56f &amp;middot; zephyrproject-rtos/hal_nordic (github.com)&lt;/a&gt;&amp;nbsp;(which I&amp;#39;m not sure would even work)?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, could you elaborate on what you mean by &amp;quot;&lt;span&gt;requesting the 64M crystal oscillator (HFXO)&amp;quot;?&amp;nbsp;Is the nRF52840 not already using its 64M crystal?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Achieving Nanosecond Precise Timing using ASM</title><link>https://devzone.nordicsemi.com/thread/457138?ContentTypeID=1</link><pubDate>Thu, 23 Nov 2023 11:37:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:261e16bb-f34b-4ed3-9604-8de7f2e4d4d5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The NOP instruction is not guaranteed to produce a deterministic delay:&amp;nbsp;&lt;a href="https://developer.arm.com/documentation/100235/0004/the-cortex-m33-instruction-set/miscellaneous-instructions/nop"&gt;https://developer.arm.com/documentation/100235/0004/the-cortex-m33-instruction-set/miscellaneous-instructions/nop&lt;/a&gt;. Instead, I would recommend you try using&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.5.0/zephyr/kernel/services/threads/index.html#c.k_busy_wait"&gt;k_busy_wait()&lt;/a&gt;. To further improve the timing, you may also consider requesting the 64M crystal oscillator (HFXO) as done in the radio test sample here:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/72e0f9a63481181994f35f4d2646117ed56d8778/samples/peripheral/radio_test/src/main.c#L11"&gt;https://github.com/nrfconnect/sdk-nrf/blob/72e0f9a63481181994f35f4d2646117ed56d8778/samples/peripheral/radio_test/src/main.c#L11&lt;/a&gt;.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Delay function used by k_busy_wait():&amp;nbsp;&lt;a href="https://github.com/zephyrproject-rtos/hal_nordic/blob/56e0b052dff311c2f8eb08c6804e60fc79feb56f/nrfx/soc/nrfx_coredep.h#L140"&gt;https://github.com/zephyrproject-rtos/hal_nordic/blob/56e0b052dff311c2f8eb08c6804e60fc79feb56f/nrfx/soc/nrfx_coredep.h#L140&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>