<?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>nRF52832 PWM sequence endlessly by easyDMA</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22572/nrf52832-pwm-sequence-endlessly-by-easydma</link><description>Hi, I&amp;#39;m developping endless PWM sequence. 
 That is ...
Only one output pin and the signal from it is repeated with the same period of pulse but with two different duty setting contiguous and repeats back again. 
 3 cycles of Duty-A followed by 259</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 Jun 2017 13:02:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22572/nrf52832-pwm-sequence-endlessly-by-easydma" /><item><title>RE: nRF52832 PWM sequence endlessly by easyDMA</title><link>https://devzone.nordicsemi.com/thread/88803?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2017 13:02:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a5dfa6b-5fd1-420d-9d53-370d0ee3533d</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;The reason why I used SEQ[1].CNT = 7, and SEQ[1].REFRESH = 36 in order to make it 259 cycles, is that the REFRESH value is ignored when CNT =1 for SEQ[1].  So you cannot have  SEQ[1].CNT =1 and  SEQ[1].REFRESH = 258 for SEQ[1]. This is explained in the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pwm.html?cp=2_2_0_46#concept_pzc_1pw_nr"&gt;PWM Product Specification&lt;/a&gt;, quote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;SEQ[n].REFRESH and SEQ[n].ENDDELAY are
ignored at the end of a complex
sequence, indicated by a LOOPSDONE
event. The reason for this is that the
last value loaded from RAM is
maintained until further action from
software (restarting a new sequence,
or stopping PWM generation).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So you need  SEQ[1].CNT &amp;gt; 1. The solution with SEQ[1].CNT = 7, and SEQ[1].REFRESH = 36 is fully reasonable and appliable in order to get 269 cycles.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 PWM sequence endlessly by easyDMA</title><link>https://devzone.nordicsemi.com/thread/88802?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2017 12:17:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9594368e-126e-4c53-9bc2-f955cb32daf8</guid><dc:creator>kojima</dc:creator><description>&lt;p&gt;Dear sigurdon,&lt;/p&gt;
&lt;p&gt;Thank you very much for showing me a good code sippet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Have you considered using the PWM driver in the SDK?
No. not yet.
Because I did NOT learn enough about the basic philothopy of Nordic&amp;#39;s SDK coding structure and style to write MY OWN code along that.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Here is some code that will give you 3 cycles of DUTY A, and 259 cycles of DUTY B, and will loop &amp;gt;forever. This is with EasyDMA, and with no CPU usage.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is very similar to MY experimental code just done last night!.
I fould LOAD_COMMON would be the reasonable choice.
But, I&amp;#39;m not sure this is the reasonable and universally-appliable solution or not...
Because, this code includes very puzzly magic number combination for Duty-B cycles.
I&amp;#39;d also found that (7)*(36+1) can make up 259 and employing REFRESH.&lt;/p&gt;
&lt;p&gt;How do you think ?&lt;/p&gt;
&lt;p&gt;P.S.
Regarding three cycles for Duty-A, I did employing REFRESH=(3-1), CNT=1 to save RAM space.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 PWM sequence endlessly by easyDMA</title><link>https://devzone.nordicsemi.com/thread/88804?ContentTypeID=1</link><pubDate>Thu, 08 Jun 2017 11:38:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37c49280-f982-43a7-9e34-ec9bcaae2e9f</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you considered using the PWM driver in the SDK?&lt;/p&gt;
&lt;p&gt;Here is some code that will give you 3 cycles of DUTY A, and 259 cycles of DUTY B, and will loop forever. This is with EasyDMA, and with no CPU usage.&lt;/p&gt;
&lt;p&gt;Code snippet:&lt;/p&gt;
&lt;pre&gt;&lt;code&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;nrf_drv_clock.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;


#define OUTPUT_PIN 4

#define DUTY_A 50
#define DUTY_B 80

static nrf_drv_pwm_t m_pwm0 = NRF_DRV_PWM_INSTANCE(0);


static nrf_pwm_values_common_t /*const*/ seq0_values[] =
{
         DUTY_A,DUTY_A,DUTY_A
};

nrf_pwm_sequence_t const seq0 =
{
    .values.p_common = seq0_values,
    .length          = NRF_PWM_VALUES_LENGTH(seq0_values),
    .repeats         = 0,
    .end_delay       = 0
};


static nrf_pwm_values_common_t /*const*/ seq1_values[] =
{
         DUTY_B,DUTY_B,DUTY_B,DUTY_B,DUTY_B,DUTY_B,DUTY_B
};

nrf_pwm_sequence_t const seq1 =
{
    .values.p_common = seq1_values,
    .length          = NRF_PWM_VALUES_LENGTH(seq1_values),
    .repeats         = 36,
    .end_delay       = 0
};


static void pwm_init(void)
{
    nrf_drv_pwm_config_t const config0 =
    {
        .output_pins =
        {
            OUTPUT_PIN, // channel 0
            NRF_DRV_PWM_PIN_NOT_USED,             // channel 1
            NRF_DRV_PWM_PIN_NOT_USED,             // channel 2
            NRF_DRV_PWM_PIN_NOT_USED,             // channel 3
        },
        .irq_priority = APP_IRQ_PRIORITY_LOWEST,
        .base_clock   = NRF_PWM_CLK_1MHz,
        .count_mode   = NRF_PWM_MODE_UP,
        .top_value    = 100,
        .load_mode    = NRF_PWM_LOAD_COMMON,
        .step_mode    = NRF_PWM_STEP_AUTO
    };
    // Init PWM without error handler
    APP_ERROR_CHECK(nrf_drv_pwm_init(&amp;amp;m_pwm0, &amp;amp;config0, NULL));
    
}


int main(void)
{

    // Start clock for accurate frequencies
    NRF_CLOCK-&amp;gt;TASKS_HFCLKSTART = 1; 
    // Wait for clock to start   
    while(NRF_CLOCK-&amp;gt;EVENTS_HFCLKSTARTED == 0);   
    
    pwm_init();

   APP_ERROR_CHECK(nrf_drv_pwm_complex_playback(&amp;amp;m_pwm0, &amp;amp;seq0, &amp;amp;seq1, 1,
                                       NRF_DRV_PWM_FLAG_LOOP ));

    while(true)
    {
    __WFE();
    __SEV();
    __WFE();

    }
}


/** @} */
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>