<?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>Understanding demo1 in Nordic SDK PWM driver example code.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/46918/understanding-demo1-in-nordic-sdk-pwm-driver-example-code</link><description>Hello, 
 I am having trouble understanding how the following function in the PWM driver example under peripherals in the SDK. Below is demo1 from the code that creates and alternating LED display on the Development Kit: 
 static void demo1(void) { NRF_LOG_INFO</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 08 May 2019 09:30:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/46918/understanding-demo1-in-nordic-sdk-pwm-driver-example-code" /><item><title>RE: Understanding demo1 in Nordic SDK PWM driver example code.</title><link>https://devzone.nordicsemi.com/thread/185887?ContentTypeID=1</link><pubDate>Wed, 08 May 2019 09:30:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f1e5018-d196-4142-94da-990db2bf289f</guid><dc:creator>Edvin</dc:creator><description>[quote user="RyanA"]I want to set all 4 PWM channels to 4 different pins but don&amp;#39;t understand how it is done currently through this code.[/quote]
&lt;p&gt;&amp;nbsp;In the pwm_library example?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Each PWM instance has two channels which pins are set in:&lt;/p&gt;
&lt;p&gt;app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, BSP_LED_0, BSP_LED_1);&lt;/p&gt;
&lt;p&gt;BSP_LED_0 and BSP_LED_1 are the pins. If you want 4 channels, you must use two instances of PWM.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Then you have to actually initialize the PWM using app_pwm_init(), and then you can set the duty cycle using app_pwm_channel_duty_set(&amp;amp;PWM_instantce, channel_number, value);&lt;/p&gt;
&lt;p&gt;So if you have two instances, PWM1 and PWM2, and each have two channels, and you want to set all channels to 50% duty cycle, you would have to do:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;while(app_pwm_channel_duty_set(PWM1, 0, 50) == NRF_ERROR_BUSY);
while(app_pwm_channel_duty_set(PWM1, 1, 50) == NRF_ERROR_BUSY);
while(app_pwm_channel_duty_set(PWM2, 0, 50) == NRF_ERROR_BUSY);
while(app_pwm_channel_duty_set(PWM2, 1, 50) == NRF_ERROR_BUSY);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understanding demo1 in Nordic SDK PWM driver example code.</title><link>https://devzone.nordicsemi.com/thread/185794?ContentTypeID=1</link><pubDate>Tue, 07 May 2019 15:42:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76c490e5-2c97-4ffb-8f6f-e9dc0846e7f1</guid><dc:creator>RyanA</dc:creator><description>&lt;p&gt;Thanks, I will investigate this. I want to set all 4 PWM channels to 4 different pins but don&amp;#39;t understand how it is done currently through this code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understanding demo1 in Nordic SDK PWM driver example code.</title><link>https://devzone.nordicsemi.com/thread/185466?ContentTypeID=1</link><pubDate>Mon, 06 May 2019 11:50:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbfd19ba-9abe-4e91-b9f0-65b32b4663c7</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;So you &amp;quot;don&amp;#39;t want any patterns or oscillations, is that correct?&lt;/p&gt;
&lt;p&gt;So maybe something that could control a PWM motor, where you set one PWM duty cycle, which will stay until you set it again?&lt;/p&gt;
&lt;p&gt;If that is the case, I suggest that you check out the pwm_library example instead. Although the LEDs flash, this is all done by a counter in the main()-loop, which continuously updates the duty cycles. If you comment this out, you can set the PWM duty cycles as you like.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>