<?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>nrf5340 rtc  imprecise</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74844/nrf5340-rtc-imprecise</link><description>Hello, 
 ncs1.5.0 
 As shown in the question, 
 I use rtc to generate a 1kHz square wave, and use an oscilloscope to measure only 964 Hz. 
 Is there a problem with where I set it? Attached is my code. Thank you for your help.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 May 2021 06:51:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74844/nrf5340-rtc-imprecise" /><item><title>RE: nrf5340 rtc  imprecise</title><link>https://devzone.nordicsemi.com/thread/309371?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 06:51:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8d72bc15-fb49-4bf8-a5bf-aa9204ef9ec5</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You should select an frequency that&amp;#39;s a power of 2 (i.e., 1024,2048,4096..) to avoid deviation due to division errors like you first saw with 2000/1000 Hz if the goal is to test the accuracy of your crystal.&lt;/p&gt;
&lt;p&gt;488us will result in an RTC compare event frequency of exactly 2048 Hz instead of the 1927 Hz you got when the desired frequency was 2000 Hz.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 rtc  imprecise</title><link>https://devzone.nordicsemi.com/thread/309347?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 00:40:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27c06e3b-37f0-4905-aef9-59f7d78b1e02</guid><dc:creator>Август</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;Thank you for your response.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But why am I changing it to 488 us? I am confused. I am measuring the external crystal oscillator not just to get a 1khz square wave.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 rtc  imprecise</title><link>https://devzone.nordicsemi.com/thread/308998?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 13:22:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e83efda3-aae6-40c4-97bd-6195354d2377</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Yes, I agree that 36 Hz seems a bit much. I suspect it may be have to do with how the compare register is being updated for every compare event. Are you familiar with the DPPI peripheral on the device? I think a better option could be to use RTC + DPPI + GPIOTE to toggle the pin without CPU involvment.&lt;/p&gt;
&lt;p&gt;Some references you may find useful:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;- &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/boards/nrf/nrfx/README.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/boards/nrf/nrfx/README.html&lt;/a&gt; - Working with nRFX drivers in Zephyr&lt;/p&gt;
&lt;p&gt;- &lt;span&gt;&lt;a title="nrfx v2.5.0" href="https://infocenter.nordicsemi.com/topic/struct_drivers/struct/nrfx_latest.html?cp=8_0"&gt;nrfx v2.5.0&lt;/a&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;- &lt;span&gt;&lt;a title="DPPI - Distributed programmable peripheral interconnect" href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/dppi.html?cp=3_0_0_6_8"&gt;DPPI - Distributed programmable peripheral interconnect&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;*Update*&lt;/strong&gt; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I was forgetting that the input frequency had to be 2 times the output frequency, which effectively increases the division error. Sorry for the confusion. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Closest you can get to 2000 Hz is ~1927 Hz. Which, if you divide by 2, is 963.7 Hz. In the code you uploaded earlier, please try to set the timeout to 488 uS instead of 500 uS. Did should give you a 1024 Hz output signal.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 rtc  imprecise</title><link>https://devzone.nordicsemi.com/thread/308993?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 13:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:abbff6fa-861f-4e59-a216-3e68ec891c3e</guid><dc:creator>Август</dc:creator><description>&lt;p&gt;hi,&lt;/p&gt;
&lt;p&gt;Thans for your quick response.&lt;/p&gt;
&lt;p&gt;I need to test the&amp;nbsp;&lt;span&gt;&amp;nbsp;low frequency clock, 36 Hz deviation is a bit far from what I expected.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf5340 rtc  imprecise</title><link>https://devzone.nordicsemi.com/thread/308989?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 13:10:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:189062bd-d7a2-45c5-bce3-fcc728ba7a77</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The RTC runs off the 32768 Hz low frequency clock so you will not be able to output exactly 1000 Hz, but around 993 Hz should be possible (~33 ticks with 0 prescaler). Would that be close enough, or must it be 1000 Hz? Otherwise you will have to consider the TIMER peripheral which has a higher run current &lt;span&gt;&lt;a title="TIMER running" href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/current_consumption/doc/current_consumption.html?cp=3_0_0_3_3_0_15#unique_2030858605"&gt;TIMER running&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>