<?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>Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/117325/accuracy-issue-between-k_uptime_ticks-and-hardware-pwm-outputs</link><description>Running into a slight issue where the timebase for system (reference time + uptime aka k_uptime_ticks()) drifts relative to sensor sampling rates. Attempt to synchronize the timebases by using nRF53 pwm system to output clock for external sensors still</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Jan 2025 14:19:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/117325/accuracy-issue-between-k_uptime_ticks-and-hardware-pwm-outputs" /><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/517734?ContentTypeID=1</link><pubDate>Thu, 09 Jan 2025 14:19:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8264af5a-3b0d-48c7-98e0-8fd671b8513d</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;I can confirm with the PPKII that the power consumption is back to expected level and the hack using 1 timer and RTC0 with the DPPI system did not increase consumption much at all.&lt;/p&gt;
&lt;p&gt;Zephyr appears to use RTC1 however and ideally one would just want to use a tick event from that instead of enabling an extra RTC. I tried this and it appears to either throw off Zephyr task scheduling or confuse it. I assume this is because Zephyr does not expect anyone to&amp;nbsp;change anything on it&amp;#39;s RTC and I believe it must be stopped in order to do so as well.&lt;br /&gt;Since there was not&amp;nbsp;any noticeable extra draw I think this is ok.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/517733?ContentTypeID=1</link><pubDate>Thu, 09 Jan 2025 14:15:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:edbdff98-c1d2-4e53-aab4-7594fb55f6c2</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;I see, that sounds like a probable root cause, indeed. I hope taking care of this stray function call let you get down to the expected current consumption numbers again. If not, let me know, and I will take another look.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/517607?ContentTypeID=1</link><pubDate>Thu, 09 Jan 2025 08:08:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9666c317-e7ae-40be-9d88-3dd414540938</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;I think I have narrowed it down to the TIMER that is started by the event and stopped by it&amp;#39;s own COMPARE. Configuring the timer appears to enable the interrupts for the timer by default in nrfx.&lt;/p&gt;
&lt;p&gt;Edit: After digging some more I found a stray&amp;nbsp;nrfx_gpiote_trigger_enable() which basically meant enabling input trigger for the output pin. Every time it changed state this would wake the CPU leading to my excessive power draw!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/517525?ContentTypeID=1</link><pubDate>Wed, 08 Jan 2025 15:16:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe1d1367-8823-476e-8496-184ad7ba40ee</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;One question... It appears my &amp;quot;hack&amp;quot; has a side effect of keeping Zephyr from sleeping.&lt;br /&gt;I believe Zephyr uses RTC1&amp;nbsp;for some of it&amp;#39;s scheduling, and it appears to use the WFE instruction for sleeping.&lt;br /&gt;I have not found any way to avoid waking from the TICK event on RTC0 even though the reason for enabling it is only to generate events for the DPPI system. Is there no disabling this effect?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515889?ContentTypeID=1</link><pubDate>Fri, 20 Dec 2024 10:43:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5d6cc28c-a457-4342-a666-febdfc72fb1d</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;In case anyone else reads this with the same problem, yes it was possible!&lt;/p&gt;
&lt;p&gt;Using a GPIOTE task channel, and assigning it&amp;#39;s SET task address together with a timers START task address in a DPPI channel (this is nrf5340 so DPPI not PPI) with the RTC TICK event address allows for setting a pin for every clock tick, and starting the timer at same time.&lt;/p&gt;
&lt;p&gt;Then connecting the timers COMPARE event to a second DPPI channel to the same GPIOTE task channel CLR task allows for clearing pin after a suitable half period that can be accurate enough for this use.&lt;/p&gt;
&lt;p&gt;Finally the SHORT in the timer must be set to RESET timer and STOP timer upon&amp;nbsp;COMPARE.&lt;/p&gt;
&lt;p&gt;This all results in reproducing the LFCLK coming from the LF XTAL on a pin so external sensors can use this as reference and the internal RTC and systick now matches any external exactly. This completely eliminates clock drift between sensor and internal timekeeping in Zephyr.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515502?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 13:19:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5f74e892-7404-4303-a66d-7cdc4f5fc80e</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;This would probably create an event only every tick which is once every clock cycle, and thus toggle would cause it to output at half frequency. I guess it could be possible to trigger a one shot timer based on same event and instead use SET task with the timer expiring and triggering a CLR task? The duty cycle would be close enough by using a fixed on time of approx half the cycle length.&lt;/p&gt;
&lt;p&gt;This is getting complicated but is it possible? &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515470?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 12:15:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:455df5a2-0ab8-41f2-8290-09cf3d91ca51</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;The RTC (that runs off the LFCLK) appear to have a&amp;nbsp;EVENTS_TICK for when counter is incremented. Could this serve as a source for PPI?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515467?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 12:06:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b38afe2-c58b-46b4-8f43-5f4f5ec97871</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;I am using a quite good LF XTAL but the external sensor uses a (rather poorly) calibrated internal oscillator unless I can feed it a better reference. When I tried using the SYNTH option BLE connections would fail to complete although unit was still discoverable.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515465?ContentTypeID=1</link><pubDate>Wed, 18 Dec 2024 12:03:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4660efba-9a2d-4c6e-b273-7d8d759ae6a0</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Using the pins for XL1 and XL2 as&amp;nbsp;&lt;strong&gt;both&lt;/strong&gt; GPIOs and clock pins won&amp;#39;t be possible as far as I&amp;#39;m aware. How low do you require to keep the power consumption exactly? This will be a trade-off between the need for accuracy versus the need for low power consumption I think. Using the K32SRC_SYNTH source as the LF clock source will definitely be the most accurate way, but it will also keep the HF clock on when using the LF clock, so it will affect the power consumption quite a bit. Using a more accurate LF XTAL could also be an option, if you find a &amp;quot;high-end&amp;quot; 32.768kHz crystal for your design with a lower PPM drift that might be an idea to keep it accurate but also at low power.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515126?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2024 13:46:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24cebf63-0bd1-4c4c-add1-8ca0ea9bbd01</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;XL1 and XL2 are technically on GPIO pins for nRF53 so I am wondering if there is a way to use for example pin-change interrupts (edge mode, low-&amp;gt;high and high-&amp;gt;low) without enameling actual software interrupt, and instead using PPI to trigger a &amp;quot;out high&amp;quot; and &amp;quot;out low&amp;quot; task. This would drive a pin at same frequency as the LFCLK and let me use this as a clock input for the sensor while avoiding external hardware with buffering if I were to tap the XL2 signal directly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515108?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2024 13:06:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8934c6f8-4d18-4f01-ab48-7704bae3b2a3</guid><dc:creator>Kyrre Aalerud</dc:creator><description>&lt;p&gt;I can only find calibration in drivers for using the RC oscillator. The external LF Xtal does not alow calibration. Same goes for the external HF Xtal oscillator. I have tried using &lt;span&gt;CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH&amp;nbsp;and this breaks BLE communication. I do not know if this is due to timing or the stopping of HF clock in sleep modes. From what I understand Zephyr idle thread does this automatically.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simply using PWM and outputting a reference clock did not work due to the difference between the two Xtal&amp;#39;s and 1 tick change in rate was enough to go from positive to negative error meaning the drift would be too large. Since the samplerate is too high for the timer resolution I can not just timestamp the samples using the LFCLK to make&amp;nbsp;this the timebase.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Accuracy issue between k_uptime_ticks() and hardware pwm outputs</title><link>https://devzone.nordicsemi.com/thread/515102?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2024 13:00:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4115d1a8-2aca-479f-ba3c-6955ef3f38e4</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Can you please show me the code on how your trying to synchronize the LFCLK ? I see that this is a genuine problem on trying to get a better accuracy of the ticks than the XTAL for LFCLK can provide. But maybe just use&amp;nbsp;CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH as lfclk source, if you have a dependency on HFCLK to calibrate the tick anyways. Let this calibration happen under the hood instead of your application trying to do it on the top level? This obviously will make HFCLK on most of the time, but seems like you are trying to do that anyways by your manual attempt to sync in your app. Try the solution provided &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/98907/after-setting-config_clock_control_nrf_k32src_rc-the-32mhz-start-working-from-rc-instead-from-xtal/421663"&gt;here&lt;/a&gt;&amp;nbsp;even though it is for the older SDK, it might be helpful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>