<?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>Invert PWM PIN, PWM, PWM intialize</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/34157/invert-pwm-pin-pwm-pwm-intialize</link><description>I try to invert the Signal on a PIN of the PWM module 0. It sould give out the inverted Signal of another PIN from the same PWM module. 
 
 
 I tried it like the code below shows. Why does NRF_DRC_PWM_PIN_INVERTED doesn&amp;#39;t have any influence? 
 
 Thanks</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 May 2018 13:52:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/34157/invert-pwm-pin-pwm-pwm-intialize" /><item><title>RE: Invert PWM PIN, PWM, PWM intialize</title><link>https://devzone.nordicsemi.com/thread/131723?ContentTypeID=1</link><pubDate>Fri, 11 May 2018 13:52:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c903c8b-2ee3-46b7-a106-8983a1e45a89</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You are right. It looks like the NRF_DRV_PWM_PIN_INVERTED does not affect the pin at all. In fact, it doesn&amp;#39;t while the PWM module is running. It only controls the pin when it is stopped (to keep any PWM device in a safe state).&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You might see in several of the demos that the number 0x8000 appears quite often. This is because the PWM module uses the 15th bit to determine whether the pin is active low or active high. So when the PWM module receives an input 0xNNNN, it is split in two. the first bit 0x8000 decides which state that is active high, and the other bits determines the length of the duty cycle.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to change one of the pins to be inverted e.g. in demo1, you must change the demo1_handler() to only check the 14 LSB. If you replace the demo1_handler with this, it should work:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void demo1_handler(nrf_drv_pwm_evt_type_t event_type)
{
    if (event_type == NRF_DRV_PWM_EVT_FINISHED)
    {
        uint8_t channel    = m_demo1_phase &amp;gt;&amp;gt; 1;
        bool    down       = m_demo1_phase &amp;amp; 1;
        bool    next_phase = false;

        uint16_t * p_channels = (uint16_t *)&amp;amp;m_demo1_seq_values;
        uint16_t value = p_channels[channel] &amp;amp; 0x7FFF;
        if (down)
        {
            value -= m_demo1_step;
            if (value == 0)
            {
                next_phase = true;
            }
        }
        else
        {
            value += m_demo1_step;
            if (value &amp;gt;= m_demo1_top)
            {
                next_phase = true;
            }
        }
        p_channels[channel] = (p_channels[channel] &amp;amp; 0x8000) | value;

        if (next_phase)
        {
            if (++m_demo1_phase &amp;gt;= 2 * NRF_PWM_CHANNEL_COUNT)
            {
                m_demo1_phase = 0;
            }
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can also remove the NRF_DRV_PWM_PIN_INVERTED, but it does not affect the pin when the PWM module is running.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>