<?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>Control two pwms in sequence</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65195/control-two-pwms-in-sequence</link><description>Hi, 
 Keywords: nrf52832, pwm_driver, two pwms, 6 channels, pwm in sequence 
 
 I have four LEDs: three mono white LEDs, one RGB LEDs(three color leds) that produce white color, so occupy six GPIOs. 
 I am using 2 pwms to control 6 channels for these</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Aug 2020 13:58:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65195/control-two-pwms-in-sequence" /><item><title>RE: Control two pwms in sequence</title><link>https://devzone.nordicsemi.com/thread/266531?ContentTypeID=1</link><pubDate>Wed, 26 Aug 2020 13:58:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b9e5593-8582-45cd-a27d-b4fdf2a13e82</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You have probably considered this, but it is not possible to change out the color LED with a normal LED, so that you can use only one channel for that one as well? In that case, you would only need 4 channels -&amp;gt; 1 PWM instance. Or alternatively, use one pin to power all 3 colors of the color LED. But I assume you want to be able to control the colors as well, so therefore you need 6 channels:&lt;/p&gt;
&lt;p&gt;I agree that it is not efficient to use thw while (!nrfx_pwm_is_stopped());&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Before the call to nrf_drv_pwm_simple_playback(), you probably have a call looking something like this:&lt;/p&gt;
&lt;p&gt;nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, my_callback_handler);&lt;/p&gt;
&lt;p&gt;(my_callback_handler&amp;nbsp;probably has a different name)&lt;/p&gt;
&lt;p&gt;But this event handler is an event handler that will be called when the sequence is finished. Look at how this is used in the SDK\examples\peripheral\pwm_driver example, in the demo1() function.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now, if you use NRF_DRV_PWM_FLAG_STOP in nrf_drv_pwm_simple_playback, you will get an event in the event handler. NB: You will get more, so you need to check the event type:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void my_callback_handler(nrf_drv_pwm_evt_type_t event_type)
{
    if (event_type == NRFX_PWM_EVT_STOPPED)
    {
        NRF_LOG_INFO(&amp;quot;PWM sequence done&amp;quot;);
        start_next_sequence(); //custom function starting the next pwm sequence.
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Try this, and let me know if it doesn&amp;#39;t work.&lt;/p&gt;
&lt;p&gt;&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>