<?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>Updating PWM sequence in NCS using nrfx driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/117261/updating-pwm-sequence-in-ncs-using-nrfx-driver</link><description>Hi, 
 I am working on nrf52840DK with NCS v2.7.0. I want to send the data to the addressable led strip using the pwm interface. 
 I am using the NRF PWM driver ( nrfx_pwm ) in my project, and I am encountering an issue with missing events when operating</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Dec 2024 13:24:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/117261/updating-pwm-sequence-in-ncs-using-nrfx-driver" /><item><title>RE: Updating PWM sequence in NCS using nrfx driver</title><link>https://devzone.nordicsemi.com/thread/515273?ContentTypeID=1</link><pubDate>Tue, 17 Dec 2024 13:24:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:97865742-b9f1-4492-814e-d876eb90aab8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am sorry for the delay. Continuing in your private support ticket for now as that has updated information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating PWM sequence in NCS using nrfx driver</title><link>https://devzone.nordicsemi.com/thread/514905?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2024 13:55:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f879a20-2ce9-47a6-bdf5-2d7d184b8147</guid><dc:creator>Haresh05</dc:creator><description>&lt;p&gt;I know it should work and same thing is working on nrf52832 with sdk13. So it should work with nrf52840 with NCS.&lt;/p&gt;
&lt;p&gt;But strange thing is I am not even getting the sequence completion interrupt when I increase the frequency.&lt;/p&gt;
&lt;p&gt;Sharing the example code I am using and the output I am getting&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;nrfx_pwm.h&amp;gt;
#include &amp;lt;hal/nrf_gpio.h&amp;gt; // Required for NRF_GPIO_PIN_MAP

#define PWM_OUTPUT_PIN  NRF_GPIO_PIN_MAP(1, 13) // Port 1, Pin 13
#define LED0_PIN        NRF_GPIO_PIN_MAP(0, 13) // LED1 pin
#define LED1_PIN        NRF_GPIO_PIN_MAP(0, 14) // LED1 pin
#define LED2_PIN        NRF_GPIO_PIN_MAP(0, 15) // LED1 pin

#define PWM_TOP_VALUE               1000
#define PWM_INST_IDX                0
#define DIGITAL_BYTES_PER_WRITE     24
#define MULTIPLY_FACTOR             1

static nrfx_pwm_t pwm_instance = NRFX_PWM_INSTANCE(0);
static nrf_pwm_values_common_t pwm_values[DIGITAL_BYTES_PER_WRITE * MULTIPLY_FACTOR] = {
    [0 ... (DIGITAL_BYTES_PER_WRITE * MULTIPLY_FACTOR) - 1] = PWM_TOP_VALUE / 2
};

static nrf_pwm_sequence_t pwm_seq0 = {
    .values.p_common = pwm_values,
    .length = NRF_PWM_VALUES_LENGTH(pwm_values),
    .repeats = 0,
    .end_delay = 0,
};

static nrf_pwm_sequence_t pwm_seq1 = {
    .values.p_common = pwm_values,
    .length = NRF_PWM_VALUES_LENGTH(pwm_values),
    .repeats = 0,
    .end_delay = 0,
};

static void pwm_interrupt_callback(nrfx_pwm_evt_type_t event_type, void *context) {
    if (event_type == NRFX_PWM_EVT_END_SEQ0) {
        printf(&amp;quot;NRFX_PWM_EVT_END_SEQ0 triggered\n&amp;quot;);
    }
    if (event_type == NRFX_PWM_EVT_END_SEQ1) {
        printf(&amp;quot;NRFX_PWM_EVT_END_SEQ1 triggered\n&amp;quot;);
    }
}

void main(void)
{
    nrfx_pwm_config_t pwm_config = NRFX_PWM_DEFAULT_CONFIG(PWM_OUTPUT_PIN, LED0_PIN, LED1_PIN,LED2_PIN);
    //pwm_config.base_clock = NRF_PWM_CLK_16MHz;
    pwm_config.output_pins[0] = PWM_OUTPUT_PIN;
    pwm_config.top_value = PWM_TOP_VALUE;

 #if defined(__ZEPHYR__)
    IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_PWM_INST_GET(PWM_INST_IDX)), IRQ_PRIO_LOWEST,
                NRFX_PWM_INST_HANDLER_GET(PWM_INST_IDX), 0, 0);
#endif

   if (nrfx_pwm_init(&amp;amp;pwm_instance, &amp;amp;pwm_config, pwm_interrupt_callback, NULL) != NRFX_SUCCESS) {
        printk(&amp;quot;PWM initialization failed\n&amp;quot;);
        return;
    }

    printk(&amp;quot;PWM initialized\n&amp;quot;);
    nrfx_pwm_complex_playback(&amp;amp;pwm_instance, &amp;amp;pwm_seq0, &amp;amp;pwm_seq1, 8, 
            NRFX_PWM_FLAG_SIGNAL_END_SEQ0 | NRFX_PWM_FLAG_SIGNAL_END_SEQ1 | NRFX_PWM_FLAG_STOP);
    while (1) {
        k_sleep(K_MSEC(5000));
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;For this I am getting following output&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[2024-12-13 19:12:39.341] *** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
[2024-12-13 19:12:39.344] *** Using Zephyr OS v3.6.99-100befc70c74 ***
[2024-12-13 19:12:39.348] PWM initialized
[2024-12-13 19:12:39.374] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.398] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.422] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.446] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.469] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.493] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.517] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.541] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.565] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.589] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.613] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.637] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.661] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.685] NRFX_PWM_EVT_END_SEQ1 triggered
[2024-12-13 19:12:39.709] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:12:39.733] NRFX_PWM_EVT_END_SEQ1 triggered&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now if I change the PWM_TOP_VALUE to 28 and set the clock to 16MHz, I am getting following output&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[2024-12-13 19:13:33.322] *** Booting nRF Connect SDK v2.7.0-5cb85570ca43 ***
[2024-12-13 19:13:33.326] *** Using Zephyr OS v3.6.99-100befc70c74 ***
[2024-12-13 19:13:33.330] PWM initialized
[2024-12-13 19:13:33.332] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:13:33.335] NRFX_PWM_EVT_END_SEQ0 triggered
[2024-12-13 19:13:33.337] NRFX_PWM_EVT_END_SEQ1 triggered&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In My understanding this should have worked but not sure what is wrong in this.&lt;/p&gt;
&lt;p&gt;Please let me know if I have configured something incorrectly or what changes should I do to make it work.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Updating PWM sequence in NCS using nrfx driver</title><link>https://devzone.nordicsemi.com/thread/514901?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2024 13:35:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:150d44a3-76bb-404c-a22e-5f200cc15504</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The dequence pointers are double buffered, so there should normally not be a problem with higher data rate either. That said, LED strip control is&amp;nbsp;often doen usint the I2S peripheral which while not designed for it, is well suited.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>