<?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 driver timing</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/35541/nrfx-pwm-driver-timing</link><description>Hello, 
 I&amp;#39;m working on some LED sequences using the NRFX PWM driver and I can&amp;#39;t get the durations I want right. 
 Let&amp;#39;s say that I want a semi-blinking LED (100% - 50% - 100%...) with a period of 500 ms on each state and I initialize the PWM driver as</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 25 Jun 2018 15:09:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/35541/nrfx-pwm-driver-timing" /><item><title>RE: NRFX PWM driver timing</title><link>https://devzone.nordicsemi.com/thread/137495?ContentTypeID=1</link><pubDate>Mon, 25 Jun 2018 15:09:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab39ab42-4293-47b2-ae73-ef9ecd1a883d</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;Hi Martin, just to let you know that I still haven&amp;#39;t been able to make it work, but it looks like there&amp;#39;s something else wrong with my implementation. I&amp;#39;ll update here when I figure it out&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM driver timing</title><link>https://devzone.nordicsemi.com/thread/137057?ContentTypeID=1</link><pubDate>Thu, 21 Jun 2018 10:37:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:983d1802-91a3-4dc1-aca0-5ef1c186e026</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Maybe you can try something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_pwm_t m_pwm0 = NRFX_PWM_INSTANCE(0);

#define PWM_TOP_VALUE 100

static void pwm_init(void)
{
    nrfx_pwm_config_t const pwm_config =
    {
	    .output_pins =
	    {
		    LED_1,     // Channel 0
		    NRFX_PWM_PIN_NOT_USED,   // Channel 1
		    NRFX_PWM_PIN_NOT_USED,    // Channel 2
		    NRFX_PWM_PIN_NOT_USED       // Channel 3
	    },
	    .irq_priority = APP_IRQ_PRIORITY_LOW,
	    .base_clock   = NRF_PWM_CLK_16MHz,						// NRF_PWM_CLK_125kHz,
	    .count_mode   = NRF_PWM_MODE_UP_AND_DOWN,				// For symmetric color mixing
	    .top_value    = PWM_TOP_VALUE,
	    .load_mode    = NRF_PWM_LOAD_INDIVIDUAL,
	    .step_mode    = NRF_PWM_STEP_AUTO
    };
    uint32_t err_code = nrfx_pwm_init(&amp;amp;m_pwm0, &amp;amp;pwm_config, NULL);
    APP_ERROR_CHECK(err_code);
}


static nrf_pwm_values_individual_t pwm_values[2]; 

nrf_pwm_sequence_t static pwm_sequence =
{
    .values.p_individual = pwm_values,
    .length          = NRF_PWM_VALUES_LENGTH(pwm_values),
    .repeats         = 1,
    .end_delay       = 0
};


void make_sequence(uint32_t duration_us)
{
    uint32_t pwm_period = 2 * PWM_TOP_VALUE / 16; // In &amp;#181;s (top / clock_frequency in MHz). Multiply by 2 if using NRF_PWM_MODE_UP_AND_DOWN
    uint32_t repeats = duration_us / pwm_period;
    
    pwm_sequence.repeats = repeats;
    
    pwm_values[0].channel_0 = 100;
    pwm_values[1].channel_0 = 5;
}


int main(void)
{    
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1;
    
    LEDS_CONFIGURE(LEDS_MASK);
    LEDS_OFF(LEDS_MASK);

    pwm_init();
    
    make_sequence(500000);
    nrfx_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;pwm_sequence, 1, NRFX_PWM_FLAG_LOOP);

    for (;;)
    {

    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This code will blink LED_1 with a frequency&amp;nbsp;of 1 Hz.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM driver timing</title><link>https://devzone.nordicsemi.com/thread/136815?ContentTypeID=1</link><pubDate>Tue, 19 Jun 2018 17:10:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fa2cb4d-268c-4276-b0b8-d0eff13228b0</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;And the periods are maybe half as long as they should be maybe. So it&amp;#39;s noticeable.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM driver timing</title><link>https://devzone.nordicsemi.com/thread/136814?ContentTypeID=1</link><pubDate>Tue, 19 Jun 2018 17:09:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2e7303e-9b71-4322-8809-93c47c930787</guid><dc:creator>Andy</dc:creator><description>&lt;p&gt;If I understand correctly I have two options:&lt;/p&gt;
&lt;p&gt;Create a sequence with both values, i.e. [100%, 50%] and call the function with a duration of 1 second. This probably wouldn&amp;#39;t work because of the size of repeats (uint16), but I could do [100%, 100%, 50%, 50%] and maybe then it&amp;#39;d work. The code then would look like this maybe:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for (uint8_t i = 0; i &amp;lt; 4; i++) {
    // Make the second half at 50%
    uint8_t divide = (i &amp;gt;= 2) ? 2 : 1;
    
	pwm_values_single_color[i].channel_0 = color.r / divide;
	pwm_values_single_color[i].channel_1 = color.g / divide;
	pwm_values_single_color[i].channel_2 = color.b / divide;
	pwm_values_single_color[i].channel_3 = 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is not what I&amp;#39;m doing.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m doing is the second choice which would be to create two sequences and then playing them one after the other like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_pwm_complex_playback(&amp;amp;m_pwm0, &amp;amp;pwm_sequence_1, &amp;amp;pwm_sequence_2, 1, NRFX_PWM_FLAG_LOOP);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I am doing this because I&amp;#39;m not using just a static full lit LED, but rather I&amp;#39;m playing back a fade in/out sequence with a sine sequence. I want to use a single color at 0% or 50% as sequence #2 to space the waveform. So I would then call&amp;nbsp;setup_single_color_sequence() to generate this pause with a specific duration.&lt;/p&gt;
&lt;p&gt;I hope that makes sense.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRFX PWM driver timing</title><link>https://devzone.nordicsemi.com/thread/136808?ContentTypeID=1</link><pubDate>Tue, 19 Jun 2018 15:48:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25c2956f-c093-4579-9367-b7a990f7e74a</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;I&amp;#39;m not sure if I follow your logic. Can you show me how&amp;nbsp; you would use this function to generate a signal of &amp;quot;(100% - 50% - 100%...) with a period of 500 ms on each state &amp;quot;?&lt;/p&gt;
&lt;p&gt;How much shorter than expected are the periods?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>