<?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>Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77132/capture-timer-using-ppi-adc-done-event</link><description>Hello, 
 First time post and brand new to the nRF52832 chip. I am tasked with building firmware that will synchronize ADC samples across multiple devices. I have started with the BLE time_sync demo and have verified that the BLE time synchronization is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Jul 2021 08:15:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77132/capture-timer-using-ppi-adc-done-event" /><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/321973?ContentTypeID=1</link><pubDate>Tue, 27 Jul 2021 08:15:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1db188a5-67ca-4bd6-ad8b-959c8ed10a73</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Mike,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m glad to hear you solved the issue. The PPI system is alot of fun, but there&amp;#39;s also quite a few avenues for issues with strange symptoms :P&amp;nbsp;&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Håkon.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/321450?ContentTypeID=1</link><pubDate>Fri, 23 Jul 2021 00:50:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a29c414f-051e-433f-a4a2-9e35b4c4c9ff</guid><dc:creator>mkurtzsd</dc:creator><description>&lt;p&gt;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have been doing lots of experimenting and searching my provided code base. I found the issue with my PPI configuration...turns out that CHANNEL7 was used elsewhere in the code that I had not seen previously and CH 7 was being enabled and disabled which explains why my setup wasn&amp;#39;t working. I tested using CHANNEL 8 and things started working properly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;On the timing side, I experimented with triggering the timer capture on the&amp;nbsp;NRF_SAADC-&amp;gt;EVENTS_END (end of ADC capture and transfer via DMA) using CHANNEL 8 and found that my timestamp fluctuated&amp;nbsp;around ~1.1us but occasionally got as high as 75us. I would guess this is due to the timing of the ADC acquisition and DMA transfer. Since this is not accurate enough for our application, I decided to setup the PPI timer capture to trigger off of the start of ADC acquisition which is always very accurate using CHANNEL6 which was already setup to begin the ADC capture.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My PPI setup looks like this now:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Setup PPI Channel 6 to trigger an ADC sample upon TIMER3 reaching compare register 0 (CC[0])
nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL6, (uint32_t) nrf_timer_event_address_get(NRF_TIMER3, NRF_TIMER_EVENT_COMPARE0), nrf_drv_saadc_sample_task_get());

// Setup PPI Channel 6 to also capture the high-speed timer tick when an ADC event is triggered
nrf_ppi_fork_endpoint_setup(NRF_PPI_CHANNEL6, (uint32_t) &amp;amp;NRF_TIMER3-&amp;gt;TASKS_CAPTURE[4]);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I believe that I am out of the woods and have gained a good understanding of the Nordic PPI system through this work.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for your time and insights.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Mike&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/321204?ContentTypeID=1</link><pubDate>Wed, 21 Jul 2021 21:05:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:77e9fce3-ad62-44d2-81aa-bb662a914cf1</guid><dc:creator>mkurtzsd</dc:creator><description>&lt;div class="author"&gt;
&lt;div&gt;H&amp;aring;kon,&lt;/div&gt;
&lt;div class="avatar"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="content full threaded-reply-content user-defined-markup"&gt;
&lt;div class="content"&gt;
&lt;p&gt;&lt;span&gt;Thanks for getting back to me. The code you referenced is in the initialization section and only executes once. In my testing, I tried enabling and commenting out / disabling the line that sets CC[4] specifically. What I am hoping for is to get a PPI event to update CC[4] with the current TIMER3 value which isn&amp;#39;t working. Whatever I set into CC[4] in the initialization routine is what I find whenever I read it back. It is not being updated.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Mike&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/321203?ContentTypeID=1</link><pubDate>Wed, 21 Jul 2021 21:05:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55102dbe-716c-483e-8fc0-526dc04f2fcc</guid><dc:creator>mkurtzsd</dc:creator><description>&lt;p&gt;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for getting back to me. The code you referenced is in the initialization section and only executes once. In my testing, I tried enabling and commenting out / disabling the line that sets CC[4] specifically. What I am hoping for is to get a PPI event to update CC[4] with the current TIMER3 value which isn&amp;#39;t working. Whatever I set into CC[4] in the initialization routine is what I find whenever I read it back. It is not being updated.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Mike&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/320879?ContentTypeID=1</link><pubDate>Tue, 20 Jul 2021 11:59:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ff3a7f6a-e77e-4cf0-903b-f0b49884ad13</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Mike, sorry for the delay, I was away on summer vacation.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;If TIMER3&amp;#39;s COMPARE[4] register is not updated then I assume the the following code is never executed:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// I&amp;#39;m not sure what this code does; but removing the setup of CC[4] also causes things to not work
if (m_params.high_freq_timer[0] == NRF_TIMER3 || m_params.high_freq_timer[0] == NRF_TIMER4)
{
    // TIMERS 0,1, and 2 only have 4 compare registers
    m_params.high_freq_timer[0]-&amp;gt;CC[4]   = time_sync_max_val / 2; // Only used for debugging purposes such as pin toggling
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I suggest you verify this by setting a breakpoint here while debugging.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I also suggest you read the TIMER2 and 3&amp;#39;s registers after you&amp;#39;ve initialized everything to verify that they are in the proper state, the same goes for the PPI and EGU registers.&lt;br /&gt;&lt;br /&gt;Also, to answer your code comment I found this comment the might help in time_synch.h, line 64:&lt;br /&gt;&lt;span&gt;/*&lt;/span&gt;&lt;span&gt;* 16 MHz timer (e.g. NRF_TIMER2). NOTE: debug toggling only available if TIMER3 or TIMER4 is used for high_freq_timer[0]&lt;/span&gt;&lt;span&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;BR,&lt;br /&gt;Håkon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/319241?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 16:35:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:146d7d35-fb11-4550-8d22-74e400ffe015</guid><dc:creator>mkurtzsd</dc:creator><description>&lt;p&gt;I should add that the following code is called in my saadc_callback method and it&amp;#39;s output always shows:&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; time_sync: Sample LS: 0, HS: -1&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ts_timestamp_get_sample_ticks()
{
    uint32_t sync_timer_val = m_params.high_freq_timer[0]-&amp;gt;CC[4];
    uint32_t count_timer_val = m_params.high_freq_timer[1]-&amp;gt;CC[4];
    uint32_t peer_count = 0;

    NRF_LOG_INFO(&amp;quot;Sample LS: %d, HS: %d&amp;quot;, count_timer_val, sync_timer_val);

    return (((count_timer_val + peer_count) * time_sync_max_val) + sync_timer_val);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Which means that TIMER3-&amp;gt;CC[4] is not being updated. It still contains the 0xFFFFFFFF that it was initialized with.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;-Mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/319239?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 16:26:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aaa22cc6-2160-4939-9516-ec9269c17fab</guid><dc:creator>mkurtzsd</dc:creator><description>[deleted]&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/319151?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 11:57:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3d1b9c9-f7c9-44a9-ae5b-76f6c41e6343</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Do you mind sharing the rest of the relevant parts of your code?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;It&amp;#39;s a bit hard to see what exactly you are doing.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;It will also help me if you can explain exactly what TIMER2 is supposed to do. I assume TIMER3 is the synchronous clock.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/319048?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 02:04:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fcefa558-fb49-45cb-8e8c-055082ac7790</guid><dc:creator>mkurtzsd</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for the feedback. Getting &amp;lt; 125ns timing would be fantastic. I believe I have setup the configuration as you suggested but it isn&amp;#39;t working. It appears that whenever the timer is captured, it&amp;#39;s counter or some other event is occurring that prevents my other PPI connections from firing. At least that&amp;#39;s my guess. I have a secondary counter (again from the BLE timer sync example) that is not being incremented as it should be.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Here is my configuration logic:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;    nrf_ppi_channel_disable(NRF_PPI_CHANNEL7);
    nrf_ppi_channel_endpoint_setup(NRF_PPI_CHANNEL7,
        (uint32_t) &amp;amp;NRF_SAADC-&amp;gt;EVENTS_END,
        (uint32_t) &amp;amp;NRF_TIMER3-&amp;gt;TASKS_CAPTURE[4]);

    //nrf_ppi_fork_endpoint_setup(NRF_PPI_CHANNEL7, (uint32_t) &amp;amp;TIMER2-&amp;gt;TASKS_CAPTURE[4]);
    nrf_ppi_channel_enable(NRF_PPI_CHANNEL7);
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have commented out the TEP for TIMER2 for the moment as I am just trying to get at least one of them to work. My interrupt that normally occurs when TIMER2 is incremented is no longer firing when I configure this PPI. It seems that configuring this PPI completely breaks the rest of the program flow. If I comment out this code, then everything works again, along with my very jittery timing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This seems like a pretty simple configuration; but not being very familiar with the Nordic architecture I&amp;#39;m sure I&amp;#39;m missing something.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Any additional pointers?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks again,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-Mike&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Capture timer using PPI adc DONE event</title><link>https://devzone.nordicsemi.com/thread/318778?ContentTypeID=1</link><pubDate>Tue, 06 Jul 2021 12:01:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b2bc85a-0e14-4c2a-a379-a212e35fe97f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Hey Mike,&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Note that the PPI system allows you to connect ANY event to ANY task.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I suggest you connect the SAADC&amp;#39;s&amp;nbsp;&lt;span&gt;EVENTS_END to the TIMER&amp;#39;s&amp;nbsp;TASKS_CAPTURE. When this is done the TIMER will store its current value into one of the given CC registers at the moment in time where the SAADC has finished sampling and all the samples have all been transferred to RAM. &lt;br /&gt;Because&amp;nbsp;the PPI system operates from a 16MHz clock source the expected jitter is more than one, but less than two clock cycles, i.e. between 62.5ns and 125ns.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;BR,&lt;br /&gt;Håkon.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>