<?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>Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/15690/synchronizing-dma-saadc-with-pwm-using-nrf52</link><description>We have an optical measurement system where we need to pulse LED and sample a phototransistor precisely during the LED pulse. The rate of sampling is 1 kHz and we plan to use 1:10 pulse ratio for the LED. 
 This far, I have written a working system than</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 22 Aug 2016 13:50:24 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/15690/synchronizing-dma-saadc-with-pwm-using-nrf52" /><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59922?ContentTypeID=1</link><pubDate>Mon, 22 Aug 2016 13:50:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37513a02-1589-4ee3-a9bc-165f83199a8c</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Hi and thanks. It looks like I am getting closer, led is blinking on timer PPI event and ADC seems also to work. However, now I would need a simple example how to set up PWM with say, 10% up/down ratio, and link an event from the PWM into the GPIO led toggle task. What kind of code would be that, can you help? I did not find an example of PWM with PPI.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59921?ContentTypeID=1</link><pubDate>Sat, 20 Aug 2016 15:59:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7915f214-ba05-4dfe-9939-c8b17aaeecf0</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Replying from a phone atm so not able to verify. But did you check the PPI example in our SDK? It should show a example on using the PPI driver. You can find it under &lt;code&gt;examples/peripheral&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59920?ContentTypeID=1</link><pubDate>Fri, 19 Aug 2016 07:29:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:726d50ba-5041-4b36-b24b-d465c199040d</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Okay, I am now trying to set up that system. However, it seems like there&amp;#39;s some confusion when trying to map your example into the software API instead of poking directly the hardware. Sorry to say, but most of your APIs are nothing but easy to understand. My code looks like below, I have commented away your original lines and tried to replace them with the API calls:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    nrf_ppi_channel_t ch;
    uint32_t timerEvent = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer, NRF_TIMER_CC_CHANNEL0);
    nrf_drv_ppi_channel_alloc(&amp;amp;ch);
    // Configure GPIOTE to toggle debug pin 
    NRF_GPIOTE-&amp;gt;CONFIG[0] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                            GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                            MCU_DEBUG_LED &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos | 
                            GPIOTE_CONFIG_OUTINIT_Low &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos;
    // Set up PPI to connect the timer compare event with the GPIOTE toggle task
    nrf_drv_ppi_channel_assign(ch, timerEvent, 0); // ???
    // NRF_PPI-&amp;gt;CH[ch].EEP = (uint32_t) &amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];
    / /NRF_PPI-&amp;gt;CH[ch].TEP = (uint32_t) &amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0];
    nrf_drv_ppi_channel_enable(ch);
    // NRF_PPI-&amp;gt;CHENSET = PPI_CHENSET_CH0_Enabled &amp;lt;&amp;lt; PPI_CHENSET_CH0_Pos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As you might guess, this does not work. I am wondering if the index zero in NRF_GPIOTE-&amp;gt;CONFIG[0] refers to PPI channel or what is it? What is wrong with this code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59919?ContentTypeID=1</link><pubDate>Fri, 12 Aug 2016 07:02:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:654954d0-2c72-4c5f-bf82-68e35d845b7b</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;Thanks a lot, sounds very good! I will try that when we get the project that far :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59918?ContentTypeID=1</link><pubDate>Fri, 12 Aug 2016 06:35:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70e1b6f8-04b2-4c59-bcaf-cf0d3380c750</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I think this should be very feasible using PPI, it will require some fine tuning. Programmable peripheral interconnect (PPI) is essentially configurable hardware shorts, so that on a timer capture compare you can trigger a measurement all without waking up the CPU. In the example below I set up some code that will generate a 8 MHz output on pin 18 using PPI, TIMER and GPIOTE.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void)
{
    // Set up GPIO as output
    nrf_gpio_range_cfg_output(17, 18);
    nrf_gpio_pin_clear(17); // Light LED 1 to indicate that the code is running

    // Start high frequency clock
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
    while (NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0)
    {
        // Wait for clock to start
    }
    NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED = 0;

    // Configure GPIOTE to toggle pin 18 
    NRF_GPIOTE-&amp;gt;CONFIG[0] = GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos |
                            GPIOTE_CONFIG_POLARITY_Toggle &amp;lt;&amp;lt; GPIOTE_CONFIG_POLARITY_Pos |
                            18 &amp;lt;&amp;lt; GPIOTE_CONFIG_PSEL_Pos | 
                            GPIOTE_CONFIG_OUTINIT_Low &amp;lt;&amp;lt; GPIOTE_CONFIG_OUTINIT_Pos;

    // Set up timer
    NRF_TIMER1-&amp;gt;PRESCALER = 0;
    NRF_TIMER1-&amp;gt;CC[0] = 2; // Adjust the output frequency by adjusting the CC.
    NRF_TIMER1-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE0_CLEAR_Pos;
    NRF_TIMER1-&amp;gt;TASKS_START = 1;

    // Set up PPI to connect the timer compare event with the GPIOTE toggle task
    NRF_PPI-&amp;gt;CH[0].EEP = (uint32_t) &amp;amp;NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];
    NRF_PPI-&amp;gt;CH[0].TEP = (uint32_t) &amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0];

    NRF_PPI-&amp;gt;CHENSET = PPI_CHENSET_CH0_Enabled &amp;lt;&amp;lt; PPI_CHENSET_CH0_Pos;

    while (true)
    {

    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Similarly you will be able to configure ADC and PWM modules to use PPI.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TIMER uses the high-frequency clock source (HFCLK, 16 MHz), which means better resolution (62.5 ns) and higher power consumption (typ. 5 or 70 uA depending on HFCLK source).&lt;/li&gt;
&lt;li&gt;RTC uses the low-frequency clock source (LFCLK, 32 KHz), which means less resolution (~30 us) and lower power consumption (typ. 0.1 uA).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So for your case I believe you will be able to get away with using the RTC.&lt;/p&gt;
&lt;p&gt;In particular look into the FORK register of the PPI module, this will allow you to start several modules at the same time.&lt;/p&gt;
&lt;p&gt;Finally here&amp;#39;s a link to the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/ppi.html?cp=2_2_0_21#concept_sxf_21l_1s"&gt;PPI documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Øyvind&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59917?ContentTypeID=1</link><pubDate>Fri, 12 Aug 2016 06:28:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79bc79c3-3ed3-4082-8f75-c2908c7a171d</guid><dc:creator>&amp;#216;yvind Karlsen</dc:creator><description>&lt;p&gt;Starting them at the same time is easily done by using PPI and the FORK register. This allows you to get a event, for example a timer compare, and then trigger ADC-&amp;gt;TASKS_START and PWM-&amp;gt;TASKS_START off of that event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronizing DMA SAADC with PWM using nRF52</title><link>https://devzone.nordicsemi.com/thread/59916?ContentTypeID=1</link><pubDate>Thu, 11 Aug 2016 13:38:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6f14ff2-476e-4bae-abe9-1f3ae07eeb54</guid><dc:creator>Jarmo</dc:creator><description>&lt;p&gt;I think that since both ADC and PWM are driven by the same clock (rtc or core clock), the problem converges into the question how to set rate parameters identically for both and how to start PWM and ADC processes at the same time (or at least almost).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>