<?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>initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/41616/initial-pulse-while-starting-a-pwm-application</link><description>Hi, 
 A short summary, while using the app_PWM on our application I noticed an initial pulse on the PWM pin, its a 3V 1ms pulse that happens about 1 sec after powering on the nRF52832... 
 The PWM configuration and initializations code is quite standard</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 20 Dec 2018 14:25:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/41616/initial-pulse-while-starting-a-pwm-application" /><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/162686?ContentTypeID=1</link><pubDate>Thu, 20 Dec 2018 14:25:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87996e79-c59e-4722-ba21-afd2fa0ace5d</guid><dc:creator>PM Bubblynet</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;Thanks for the info, very useful indeed, and just to clarify, I used 1000 because I also edited the PWM driver library and set the range 0 to 1000 to have better control of the PWM on a logarithmic scale thats quite important in lighting, actually I might even go to 0 to 10000... in lighting the 0% to 10% its quite important and difficult to manage due to the non linear response from our eyes...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/162339?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 15:35:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f438714c-75de-4f6b-8d5d-33a97e2a9ce7</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;There is a problem with the code you described in your last post, which is that you should call&amp;nbsp;app_pwm_enable() before you call&amp;nbsp;app_pwm_channel_duty_set(). Calling it the other way around causes the library to misbehave. This is unfortunately not documented as far as I can see and not obvious. There is also a problem that you set the duty cycle to 1000, which is not in the valid range (0 - 100).&lt;/p&gt;
&lt;p&gt;You could update the code to be like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, ON_OFF_LED);
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW;
err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);
app_pwm_enable(&amp;amp;PWM1);
while ( app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 100) == NRF_ERROR_BUSY);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this case the pin state will be like the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;After reset before the pin is configured it will be the default state (disconnected input) = high impedance.&lt;/li&gt;
&lt;li&gt;After executing line 3 the pin will be configured as an output pin and set to the non-active state - high in this case.&lt;/li&gt;
&lt;li&gt;After executing line with the duty cycle is set to 100%, the pin should stay in the active state - low in this case.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So in this case you get the 1 ms pulse you have described and that is expected.&lt;/p&gt;
&lt;p&gt;If you do the trick I mentioned you would have something like this instead. In that case you will not see any pulse:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, ON_OFF_LED);
pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;
err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);
app_pwm_enable(&amp;amp;PWM1);
while ( app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 100-100) == NRF_ERROR_BUSY);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/162310?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 14:23:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8b66783-8d2c-4637-b56b-82f22266e165</guid><dc:creator>PM Bubblynet</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;When you say&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/41616/initial-pulse-while-starting-a-pwm-application/162304"]simply reversing the polarity in the initialization and reversing the duty cycle in your call to&amp;nbsp;app_pwm_channel_duty_set()[/quote]
&lt;p&gt;what it means is that I would need to reverse all my calls to app_pwm_duty_set()... in other words, I would need to reverse the whole dimming logic... thats what I meant...&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/41616/initial-pulse-while-starting-a-pwm-application/162304"] It keeps that state until you configure a duty cycle.&amp;nbsp;What you are seeing is not a bug, but is the behavior you should expect with the code you are using.[/quote]
&lt;p&gt;thats my question, so lets see, I do the configuration:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, ON_OFF_LED); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then set polarity:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Then initialization:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Then I set the duty cycle:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;while ( app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 1000) == NRF_ERROR_BUSY); &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And finally I enable the PWM:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;app_pwm_enable(&amp;amp;PWM1);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And then&amp;nbsp;the PWM is at 100%? shouldn&amp;#39;t&amp;nbsp;the set instruction set the PWM to 0%? and when enabling the PWM should be 0%?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/162304?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 14:06:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bc6c06c-2e1f-4c8c-a76c-4323afe2a08b</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;I was not commenting on the problem where you mixed up the channels, as you wrote that you had solved it. Everything in my previous answer related to the initial pulse.&lt;/p&gt;
&lt;p&gt;What I attempted to describe was that the initial pulse is because during initialization the output pin is set to high if the pin polarity is configure&amp;nbsp;APP_PWM_POLARITY_ACTIVE_LOW (and vise versa). It keeps that state until you configure a duty cycle.&amp;nbsp;What you are seeing is not a bug, but is the behavior you should expect with the code you are using. Therefore I mentioned how you can get the behaviour (I think) you want by simply reversing the polarity in the initialization and reversing the duty cycle in your call to&amp;nbsp;app_pwm_channel_duty_set(). That way you will not get the initial pulse.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/162294?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 13:20:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30ab5e47-7966-4a1c-ac0f-9027660438f3</guid><dc:creator>PM Bubblynet</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The question is not about polarity... its about an unwanted/ unexpected initial pulse... in short, there is an initial pulse when enabling a PWM even when set:&amp;nbsp;&lt;span&gt;&amp;nbsp;app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 1000), as I mentioned I tried:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;[quote userid="73023" url="~/f/nordic-q-a/41616/initial-pulse-while-starting-a-pwm-application/161940"]int main(void) { initialize(); // Initializing the PWM instance in main() function ret_code_t err_code; app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, ON_OFF_LED); pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW; err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);&lt;br /&gt; while ( app_pwm_channel_duty_set(&amp;amp;PWM1, 0, MIN_LIGHT_INTENSITY) == NRF_ERROR_BUSY); app_pwm_enable(&amp;amp;PWM1); APP_ERROR_CHECK(err_code); execution_start(start);[/quote]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;And it still has that initial pulse... so it looks like the&amp;nbsp;app_pwm_channel_duty_set dont work until the&amp;nbsp;app_pwm_enable is called?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;About the logic being reversed, the initial code had a bug: instead of setting polarity on channel 0 it was setting the polarity on channel 1... that is not in use... I didn&amp;#39;t catch that one until now... so all my dimming logic was written with the default polarity LOW... if I change the polarity now to&amp;nbsp;HIGH I would need to rewrite the dimming logic, anyways... my question is: is there a way to&amp;nbsp;keep the default active polarity (LOW) without that initial pulse? It&lt;span&gt;&amp;nbsp;looks like the&amp;nbsp;app_pwm_channel_duty_set dont work&amp;nbsp;if used before&amp;nbsp;&lt;/span&gt;&lt;span&gt;app_pwm_enable... in other words it seems we cant set the duty cycle and then enable the PWM?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/162243?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 10:16:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da44e1e4-f72c-4f8f-a92d-6b7c693ffe61</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The GPIO output pin is initially configured based on the pin polarity. So when you call&amp;nbsp;app_pwm_init() with the polarity&amp;nbsp;configuration set to&amp;nbsp;APP_PWM_POLARITY_ACTIVE_LOW this will set the pin high. It will not change state until you call&amp;nbsp;app_pwm_channel_duty_set(). If you want the default state to be low, you should use&amp;nbsp;&lt;span&gt;APP_PWM_POLARITY_ACTIVE_HIGH.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t follow what you mean by logic being reversed.&amp;nbsp;If you want to keep the same scale for duty cycle after changing polarity you could set the duty cycle as (100 - duty_cycle).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: initial pulse while starting a PWM application</title><link>https://devzone.nordicsemi.com/thread/161940?ContentTypeID=1</link><pubDate>Fri, 14 Dec 2018 21:18:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bd6966b-f756-4ce7-8f6a-11eee3693298</guid><dc:creator>PM Bubblynet</dc:creator><description>&lt;p&gt;The good news is: I found the &amp;quot;problem&amp;quot;:&lt;/p&gt;
[quote userid="73023" url="~/f/nordic-q-a/41616/initial-pulse-while-starting-a-pwm-application"]pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_LOW;[/quote]
&lt;p&gt;that should be:&lt;/p&gt;
&lt;pre&gt;pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The bad news is that now all the logic behind&amp;nbsp;my usage of the PWM is reversed... this was a question we had few weeks ago:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/40002/pwm-library-issues/156496#156496"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/40002/pwm-library-issues/156496#156496&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;so before I rewrite all the logic of my application, is there any way to keep current implementation with:&lt;/p&gt;
&lt;pre&gt;pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_HIGH;&lt;/pre&gt;
&lt;p&gt;Without getting this initial pulse? I tracked down this to the&amp;nbsp;app_pwm_enable(&amp;amp;PWM1);&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;it doesn&amp;#39;t help to invert&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;while ( app_pwm_channel_duty_set(&amp;amp;PWM1, 0, MIN_LIGHT_INTENSITY) == NRF_ERROR_BUSY);
&lt;/pre&gt;
&lt;pre&gt;And&lt;/pre&gt;
&lt;pre&gt;app_pwm_enable(&amp;amp;PWM1);&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried:&lt;/p&gt;
&lt;pre&gt;int main(void)

{
    initialize();
    // Initializing the PWM instance in main() function
    ret_code_t err_code;
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_1CH(1000L, ON_OFF_LED);
    pwm1_cfg.pin_polarity[0] = APP_PWM_POLARITY_ACTIVE_LOW;
    err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);&lt;br /&gt;    while ( app_pwm_channel_duty_set(&amp;amp;PWM1, 0, MIN_LIGHT_INTENSITY) == NRF_ERROR_BUSY);
    app_pwm_enable(&amp;amp;PWM1);
    
    APP_ERROR_CHECK(err_code);

    execution_start(start);&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But didn&amp;#39;t help, when executing&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;app_pwm_enable(&amp;amp;PWM1);&lt;/pre&gt;
&lt;p&gt;I get that initial pulse anyways...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>