<?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>Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79270/please-give-me-advice-on-nrf-pwm-driver</link><description>I want a waveform as below for motor control. I am trying to create this using nrf pwm driver. 
 I set the pwm sequence as below and checked the output. 2nd duty repeat does not work. 
 I added an unused 3rd dummy duty (line 91). It seems to be working</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Sep 2021 08:25:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79270/please-give-me-advice-on-nrf-pwm-driver" /><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328732?ContentTypeID=1</link><pubDate>Thu, 09 Sep 2021 08:25:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63f83b22-6053-4910-b6e5-c04654cc12e3</guid><dc:creator>John Lee</dc:creator><description>&lt;p&gt;&lt;span&gt;I solved it.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Thank you for the answer.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328691?ContentTypeID=1</link><pubDate>Thu, 09 Sep 2021 04:31:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5ada162d-3da8-4079-8af7-f78fc27689b3</guid><dc:creator>John Lee</dc:creator><description>&lt;p&gt;In the example code I posted, repeat is set to a constant 4.&lt;br /&gt;But in my actual application repeat needs to depend on external settings.&lt;br /&gt;In this case, the sequence cannot be pre-coded.&lt;br /&gt;Any other options?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328541?ContentTypeID=1</link><pubDate>Wed, 08 Sep 2021 09:30:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d8a0e39-900e-465c-aef0-8964381a0b8f</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;Although it&amp;#39;s not well explained in the product specification, the PWM peripheral has a limitation in that it will stop the execution of a sequence too early. Some effort has been done to explain it in some part in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/22572/nrf52832-pwm-sequence-endlessly-by-easydma/88803#88803&amp;#39;"&gt;this thread&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Nevertheless, the best way for your use case is to something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_drv_pwm.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);

#define PERIOD 1000

#define DUTY		75
#define HIGH		(PERIOD * (100 - DUTY) / 100) //250
#define LOW			PERIOD //1000 

static nrf_pwm_values_individual_t /*const*/ seq_values[] =
{
    
	{HIGH, LOW, LOW, LOW},
	{HIGH, LOW, LOW, LOW},
    {HIGH, LOW, LOW, LOW},
    {HIGH, LOW, LOW, LOW},
    {LOW, HIGH, LOW, LOW},
    {LOW, HIGH, LOW, LOW},
    {LOW, HIGH, LOW, LOW},
    {LOW, HIGH, LOW, LOW},
};
nrf_pwm_sequence_t const seq =
{
	.values.p_individual = seq_values,
	.length              = NRF_PWM_VALUES_LENGTH(seq_values),
	.repeats             = 0
	,
	.end_delay           = 0
};

static void demo(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            3,
            4,
            NRFX_PWM_PIN_NOT_USED,
            NRFX_PWM_PIN_NOT_USED
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_1MHz,
        .count_mode   = NRF_PWM_MODE_UP,
		.top_value    = 1000,
        .load_mode    = PWM_DECODER_LOAD_Individual,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    APP_ERROR_CHECK(nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, NULL));
}


void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
    app_error_save_and_stop(id, pc, info);
}

int main(void)
{

	demo();
	
    for (;;)
    {
		(void)nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 4 , NRFX_PWM_FLAG_STOP);

		nrf_delay_ms(1000);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note, I changed the pins so you should probably change them back ;)&lt;/p&gt;
&lt;p&gt;Instead of using the repeat, I hardcoded the sequence pattern and use the playback_count parameter to&amp;nbsp;nrfx_pwm_simple_playback() to decide the number of times the pattern should be repeated. Here is a trace from the logic analyzer with playback_count set to 4:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/3730.pastedimage1631093400568v1.png" alt=" " /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;best regards&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;Jared&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328372?ContentTypeID=1</link><pubDate>Tue, 07 Sep 2021 11:41:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dccaeb83-48fa-469c-8671-5d4462ddfd3b</guid><dc:creator>John Lee</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf_drv_pwm.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;bsp.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);

#define PERIOD 1000

#define DUTY		75
#define HIGH		(PERIOD * (100 - DUTY) / 100)
#define LOW			PERIOD

static nrf_pwm_values_individual_t /*const*/ seq_values[] =
{
	{HIGH, LOW, LOW, LOW},
	{LOW, HIGH, LOW, LOW},
};
nrf_pwm_sequence_t const seq =
{
	.values.p_individual = seq_values,
	.length              = NRF_PWM_VALUES_LENGTH(seq_values),
	.repeats             = 4
	,
	.end_delay           = 0
};

static void demo(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            24,
            25,
            NRFX_PWM_PIN_NOT_USED,
            NRFX_PWM_PIN_NOT_USED
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_1MHz,
        .count_mode   = NRF_PWM_MODE_UP,
		.top_value    = 1000,
        .load_mode    = PWM_DECODER_LOAD_Individual,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    APP_ERROR_CHECK(nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, NULL));
}


void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info)
{
    app_error_save_and_stop(id, pc, info);
}

int main(void)
{

	demo();
	
    for (;;)
    {
		(void)nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 1, NRFX_PWM_FLAG_STOP);

		nrf_delay_ms(1000);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pwm.jpg" /&gt;&lt;br /&gt;&lt;br /&gt;Code and output waveform&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328364?ContentTypeID=1</link><pubDate>Tue, 07 Sep 2021 11:21:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ab030eb-cfbd-44c1-835b-9830d24e415d</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi there,&lt;/p&gt;
&lt;p&gt;Would you mind sharing a minimal example that can be flashed on a DK that highlights the issue? It would make it much easier for me to understand the issue if I could reproduce it at my side.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328260?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 16:40:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea49d9e6-a88b-4b27-8da3-a7031b5ef354</guid><dc:creator>John Lee</dc:creator><description>&lt;p&gt;&lt;span&gt;What I want to do is avoid &amp;quot;For sequences with configured repeating of duty cycle values, this might result in less than the requested number of repeats of the last value.&amp;quot; in the description of NRFX_PWM_FLAG_STOP.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Why is this happening?&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Is there any way to avoid this by using a trick?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328069?ContentTypeID=1</link><pubDate>Mon, 06 Sep 2021 00:47:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf27b5c1-adbb-412a-bbd9-aca71cf1c509</guid><dc:creator>John Lee</dc:creator><description>&lt;p&gt;I want to change the output cycle to be variable.&lt;br /&gt;So we use playback_count, NRFX_PWM_FLAG_STOP.&lt;/p&gt;
&lt;p&gt;Is there a way to repeat as many times as I want using NRF_DRV_PWM_FLAG_LOOP?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/328005?ContentTypeID=1</link><pubDate>Fri, 03 Sep 2021 14:37:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae548ed1-73a0-4fce-9e38-658ba9af348e</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you tried passing&amp;nbsp;NRF_DRV_PWM_FLAG_LOOP to&amp;nbsp;nrf_drv_pwm_simple_playback()? Could you also share your code?&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Please give me advice on nrf pwm driver.</title><link>https://devzone.nordicsemi.com/thread/327923?ContentTypeID=1</link><pubDate>Fri, 03 Sep 2021 09:00:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59effd64-9866-4e23-8513-3f7a6af95f51</guid><dc:creator>John Lee</dc:creator><description>&lt;p&gt;I want a waveform as below for motor control.&lt;br /&gt;I am trying to create this using nrf pwm driver.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pwm_5F00_1.png" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;I set the pwm sequence as below and checked the output.&lt;br /&gt;2nd duty repeat does not work.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pwm_5F00_5.JPG" /&gt;&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pwm_5F00_2.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I added an unused 3rd dummy duty (line 91).&lt;br /&gt;It seems to be working well.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pwm_5F00_3.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;However, increasing the playback count to 2 introduces a delay between the outputs.&lt;br /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pwm_5F00_4.png" /&gt;&lt;br /&gt;&lt;br /&gt;What should I do to get the waveform I want?&lt;br /&gt;Give me advice .&lt;br /&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>