<?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>NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119537/nrfx-pwm-pin-polarity</link><description>Hello, 
 I&amp;#39;m using NRFX PWM directly because I need something more custom than zephyr&amp;#39;s PWM driver provides. I&amp;#39;m trying to understand what .pin_polarity field in the config does. It does not seem to invert the polarity of the signal. 
 All .pin_polarity</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Mar 2025 13:49:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119537/nrfx-pwm-pin-polarity" /><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/526768?ContentTypeID=1</link><pubDate>Tue, 11 Mar 2025 13:49:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:223909fb-2a32-4a07-8675-be10335f9780</guid><dc:creator>Konstantin Klitenik</dc:creator><description>&lt;p&gt;Ok, I think I finally found the relevant section in the nrf pwm docs, which does confirm what I&amp;#39;m seeing:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span&gt;The polarity is set by the most significant bit (MSb) of the 16-bit value read from RAM (see figure&amp;nbsp;&lt;/span&gt;&lt;a class="xref" href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/pwm.html#concept_wxj_hnw_nr__pwm_decoder_mode"&gt;Decoder memory access modes&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;). When the MSb is &amp;#39;1&amp;#39; the channel is configured as FallingEdge polarity, OUT[n] starts high to become low during the given PWM cycle, whereas the inverse occurs when configured for RisingEdge polarity.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span&gt;(&lt;a id="" href="https://docs.nordicsemi.com/bundle/ps_nrf52840/page/pwm.html"&gt;https://docs.nordicsemi.com/bundle/ps_nrf52840/page/pwm.html&lt;/a&gt;)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In any case, the .pin_inverted field is very confusing in this API. It makes it seem you can use it to invert polarity, but all it does is invert the pin before PWM. Not sure what the purpose of that is.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Otherwise, we can consider this closed.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/526654?ContentTypeID=1</link><pubDate>Mon, 10 Mar 2025 22:12:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecee0296-d411-43aa-a38b-6b3c1db5e7d4</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I should likely look into the details here, but on a high level:&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t compare the zephyr pwm driver with the nrfx pwm driver, the configuration and setup is completely different.&lt;/p&gt;
&lt;p&gt;When using the zephyr pwm driver it will setup the interface as configured by devicetree as part of the pre-kernel before running to main, in which case the pwm will be controlled according to the zephyr pwm driver.&lt;/p&gt;
&lt;p&gt;If you are using nrfx instead, then the pins are completely untouched by zephyr, it&amp;#39;s you that need to manually setup the pins to behave as you want, that include potentially setting pins as output pins with desired level, normally this will occur when you call nrfx_pwm_init, until then the pins are likely&amp;nbsp;floating input input pins. The pwm sequence itself will only occur when calling the nrfx_pwm_simple_playback(), in which case the pwm will behave directly according to pwm hardware.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/526635?ContentTypeID=1</link><pubDate>Mon, 10 Mar 2025 18:17:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de3a279f-4559-4043-b64b-e3928618460e</guid><dc:creator>Konstantin Klitenik</dc:creator><description>&lt;p&gt;Any update here?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/526048?ContentTypeID=1</link><pubDate>Wed, 05 Mar 2025 16:32:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9347d177-d79f-4772-953b-9bfe3cc165dd</guid><dc:creator>Konstantin Klitenik</dc:creator><description>&lt;p&gt;I read that as well and doing that gets me what I want. I&amp;#39;m just confused because the documentation says it should default to active high but what I&amp;#39;m seeing is that it default to active low (hence the need to invert).&lt;/p&gt;
&lt;p&gt;I would expected it to work the opposite, based on the documentation.&lt;/p&gt;
&lt;p&gt;And if the inversion is done with setting bit 15, what&amp;#39;s the purpose of .pin_invert field?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/526038?ContentTypeID=1</link><pubDate>Wed, 05 Mar 2025 15:25:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d0880a1-15b1-426b-9f8f-cbf8982ab7a5</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello again,&lt;/p&gt;
&lt;p&gt;Think I understand the problem now, see documentation for the PWM:&lt;br /&gt;&amp;quot;PWM parameters are organized into a sequence containing at least one half word (16 bit). Its most significant bit[15] denotes the polarity of the OUT[n] while bit[14:0] is the 15-bit compare value.&amp;quot;&lt;br /&gt;From:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/ps_nrf9151/page/pwm.html#ariaid-title3"&gt;https://docs.nordicsemi.com/bundle/ps_nrf9151/page/pwm.html#ariaid-title3&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So please try to or&amp;nbsp;with | &lt;span&gt;0x8000.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kenneth&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/526007?ContentTypeID=1</link><pubDate>Wed, 05 Mar 2025 14:13:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3d8c11c2-1353-45c0-bac8-6eddbf6d5075</guid><dc:creator>Konstantin Klitenik</dc:creator><description>&lt;p&gt;Sorry, yes. .pin_polarity meant to be .pin_inverted. I&amp;#39;ve also since added&amp;nbsp;&lt;span&gt;.skip_gpio_cfg&amp;nbsp;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;false and&amp;nbsp;&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;skip_psel_cfg&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;false.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;We do have PWM0 in the device tree. That&amp;#39;s a separate instance controlling something else. This particular example is using PWM1 and that PWM is NOT defined in the device tree.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also, binding file for nordic,invert says:&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;nordic,invert&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;type&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;boolean&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;description&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;|&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt; Invert pin polarity (set the active state to low).&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;which would imply that normal (non-inverted state) should be active high, which is not what I&amp;#39;m seeing above.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM Pin Polarity</title><link>https://devzone.nordicsemi.com/thread/525942?ContentTypeID=1</link><pubDate>Wed, 05 Mar 2025 11:03:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9aec837-8e20-4276-8607-3d9f834052e1</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I would expect the state of the PWM pins to occur when you call&amp;nbsp;&lt;span&gt;nrfx_pwm_init(), since I can see it&amp;#39;s then&amp;nbsp;&lt;/span&gt;pwm_configure()-&amp;gt;pins_configure() is applied.&lt;/p&gt;
&lt;p&gt;You refer to .&lt;span&gt;pin_polarity, I assume you means .pin_inverted.&amp;nbsp;&lt;/span&gt;&lt;span&gt;I notice your&amp;nbsp;config is missing the &lt;/span&gt;&lt;span&gt;.skip_gpio_cfg &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;false.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you also have the pwm node in the devicetree I expect you need to use&amp;nbsp;nordic,invert; for the pin control of the pins.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kenneth&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>