<?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>About several problems nrf51822 PWM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/26021/about-several-problems-nrf51822-pwm</link><description>How do you do
1.In the Nordic \ nRF5_SDK_12 _f012efa 2.0-3 d \ examples \ peripheral here, there are three PWM routines:
Low_power_pwm, pwm_driver, pwm_library but only low_power_pwm and pwm_library can be used for NRF51822 right? 
 2.Low_power_pwm</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 17 Oct 2017 10:51:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/26021/about-several-problems-nrf51822-pwm" /><item><title>RE: About several problems nrf51822 PWM</title><link>https://devzone.nordicsemi.com/thread/102538?ContentTypeID=1</link><pubDate>Tue, 17 Oct 2017 10:51:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:379b3d68-8c2e-4fba-afd3-dbefd9e65694</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In the Nordic \ nRF5_SDK_12 _f012efa
2.0-3 d \ examples \ peripheral here, there are three PWM routines:
Low_power_pwm, pwm_driver, pwm_library
but only low_power_pwm and pwm_library
can be used for NRF51822 right?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;That is correct. The nRF52-series have dedicated PWM hardware peripheral(used in the pwm_driver example), while in the nRF51-series the PWM libraries are implemented using GPIOTE, TIMERs and PPI hardware peripherals.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Low_power_pwm pwm_library and what is
the difference between the two
routines?Use under what circumstances?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The low-power PWM library is for applications where you don&amp;#39;t need high frequency or accuracy. The low power pwm example should be suitable for LEDs, as LEDs usually do not require that high PWM frequency. But for peripherals that need a high accuracy, you should use the PWM library instead.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;What PWM frequency do you need?&lt;/p&gt;
&lt;p&gt;Using the &lt;code&gt;APP_PWM_DEFAULT_CONFIG_2CH()&lt;/code&gt;, the first argument is the period in us, so with 5000 us, you get 200 Hz (&lt;code&gt;1 / 0.005 = 200&lt;/code&gt;). You set the duty cycle with the &lt;code&gt;app_pwm_channel_duty_set()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;With the PWM library you can try something like this.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;     ret_code_t err_code;

    /* 2-channel PWM, 200Hz, output on DK LED pins. */
    app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, 1, 2);

    /* Switch the polarity of the second channel. */
    pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH;

    /* Initialize and enable PWM. */
    err_code = app_pwm_init(&amp;amp;PWM1,&amp;amp;pwm1_cfg,pwm_ready_callback);
    APP_ERROR_CHECK(err_code);
    app_pwm_enable(&amp;amp;PWM1);
    
    //Set duty cycle to 50% for first waveform
    while (app_pwm_channel_duty_set(&amp;amp;PWM1, 0, 50) == NRF_ERROR_BUSY);
    
    
    //Set duty cycle to 50% for second waveform
    while (app_pwm_channel_duty_set(&amp;amp;PWM1, 1, 50) == NRF_ERROR_BUSY);
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>