<?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>Reasoning behind nrf51-pwm-library implementation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9155/reasoning-behind-nrf51-pwm-library-implementation</link><description>Greetings, 
 Kudos for implementing a no glitch version of PWM with and without using timeslot. 
 github.com/.../nrf_pwm_noglitch.c. 
 Could the reasoning for the following be explained with the above PWM driver: 
 
 Why is pwm_max_value and pwm_value</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Sep 2015 13:02:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9155/reasoning-behind-nrf51-pwm-library-implementation" /><item><title>RE: Reasoning behind nrf51-pwm-library implementation</title><link>https://devzone.nordicsemi.com/thread/33738?ContentTypeID=1</link><pubDate>Mon, 14 Sep 2015 13:02:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59804666-c387-4f26-bcb2-ae991f250823</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Answering my second question: yes, it is possible to wait longer and not use the timer IRQ to disable the PPI. But there is a better way. A bit of optimization of the library to remove the blocking of the processor for a PWM period which can be many microseconds. Could be costly when updating frequently.&lt;/p&gt;
&lt;p&gt;This can be done by commenting out &lt;code&gt;nrf_delay_us(pwm_period_us);&lt;/code&gt; and changing the Timer IRQ to&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void PWM_IRQHandler(void)
{
    PWM_TIMER-&amp;gt;EVENTS_COMPARE[3] = 0;
    static bool alternate_flag = false;

    if(true == alternate_flag){
      PWM_TIMER-&amp;gt;INTENCLR          = TIMER_INTENCLR_COMPARE3_Msk;

      ppi_disable_channels((1 &amp;lt;&amp;lt; (PWM_MAX_CHANNELS * 2)) | (1 &amp;lt;&amp;lt; (PWM_MAX_CHANNELS * 2 + 1)) | (1 &amp;lt;&amp;lt; (PWM_MAX_CHANNELS * 2 + 2)));
      ppi_configure_channel_group(pwm_ppi_chg, 0);
      ppi_disable_channel_group(pwm_ppi_chg);
    }
    alternate_flag = (true == alternate_flag)?false:true;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now the IRQ gets called twice with the actual PPI disabling done the second time. Since it is a low priority IRQ it does not block critical stuff. The CPU gets kept on for lesser time. The &lt;code&gt;nrf_pwm_set_value()&lt;/code&gt; now returns immediately.&lt;/p&gt;
&lt;p&gt;With not using softdevice calls for configuring PPIs it is possible to call &lt;code&gt;nrf_pwm_set_value()&lt;/code&gt; from high priority IRQ, especially now that the call is non-blocking.&lt;/p&gt;
&lt;p&gt;Makes sense to send a pull request to the library?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reasoning behind nrf51-pwm-library implementation</title><link>https://devzone.nordicsemi.com/thread/33737?ContentTypeID=1</link><pubDate>Fri, 11 Sep 2015 11:52:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ee39378-3b2c-4c47-a3e5-37f5c2f5ba0d</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Updates from digging in: If I make sure that all the values that I pass to &lt;code&gt;nrf_pwm_set_value&lt;/code&gt; is an even number it works well without multiplying &lt;code&gt;pwm_max_value&lt;/code&gt; and &lt;code&gt;pwm_value&lt;/code&gt; by two. Next step, figuring out why &lt;code&gt;nrf_pwm_set_value&lt;/code&gt; can&amp;#39;t handle odd numbers.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reasoning behind nrf51-pwm-library implementation</title><link>https://devzone.nordicsemi.com/thread/33736?ContentTypeID=1</link><pubDate>Fri, 11 Sep 2015 09:15:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c1c902f-60e2-4cf9-ae01-cd2d2b1227ee</guid><dc:creator>FormerMember</dc:creator><description>&lt;p&gt;Thanks! This helps clear some stuff up. I&amp;#39;m looking for PWM for a max value of 1023 and with no prescalar of TIMER. This would result in ~15 kHz freq of PWM signal, but with the multiplication of 2 (question 1), the PWM freq reduces to ~7 kHz. Since the PWM freq is still below 64kHz limit mentioned in the link you sent, what is the reason that this is done?&lt;/p&gt;
&lt;p&gt;I have changed the code where the multiplying by 2 is not done and the PWM gets messed up. I still can&amp;#39;t get my head around why though.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reasoning behind nrf51-pwm-library implementation</title><link>https://devzone.nordicsemi.com/thread/33735?ContentTypeID=1</link><pubDate>Thu, 10 Sep 2015 15:57:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29fac7ca-4897-4e10-84e6-971878bd0a0c</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Not yet sure about the two first questions that you ask. For your last question, &lt;a href="https://devzone.nordicsemi.com/question/42518/random-pwm-dutycycle-inversion-in-softdevice-80/?answer=43270#post-id-43270"&gt;this thread&lt;/a&gt; provides some reasoning for why the signal would flip and how to avoid it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>