<?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>NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17236/nrf52-dim-led-with-pwm-driver</link><description>I am migrating from nrf51 to nrf52. Using SDK12.1 
 On NRF51, I used the PWM Library to use 2 buttons on the DK to dim up or down onboard LED1 (called OUTPUT_LED).
It worked great (not sure if it did it properly or not).
The code was fairly simple</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 Sep 2017 08:41:41 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17236/nrf52-dim-led-with-pwm-driver" /><item><title>RE: NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/thread/66212?ContentTypeID=1</link><pubDate>Thu, 21 Sep 2017 08:41:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56cabd2d-484e-4d8f-b4a7-4fd556945aa7</guid><dc:creator>Nestor Matas</dc:creator><description>&lt;p&gt;Very useful, thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/thread/66213?ContentTypeID=1</link><pubDate>Sat, 20 May 2017 17:55:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:44c15680-93e1-4ed2-ade6-bd8dce4c3579</guid><dc:creator>Bndit</dc:creator><description>&lt;p&gt;Thank you for your kindness.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/thread/66211?ContentTypeID=1</link><pubDate>Thu, 18 May 2017 12:07:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea4e7c79-7853-4955-9487-26657b302820</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Bndit&lt;/p&gt;
&lt;p&gt;I just updated the answer with a new version of the example that compiles under SDK v13.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/thread/66214?ContentTypeID=1</link><pubDate>Tue, 16 May 2017 10:36:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ee7a03a3-cead-4bf2-8c02-c12c7640e015</guid><dc:creator>Bndit</dc:creator><description>&lt;p&gt;Not compiling, too many errors such as APP_TIMER_TICKS gets too many arguments&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/thread/66210?ContentTypeID=1</link><pubDate>Fri, 04 Nov 2016 16:07:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2b781b18-fed2-41a3-aee6-d47debdf7381</guid><dc:creator>Bryan H</dc:creator><description>&lt;p&gt;Thank you for your help!
This helped a lot.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52 Dim LED with PWM Driver</title><link>https://devzone.nordicsemi.com/thread/66209?ContentTypeID=1</link><pubDate>Mon, 24 Oct 2016 16:52:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:709a4336-3147-4fe8-bfa0-18f2f862ac62</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi Bryan&lt;/p&gt;
&lt;p&gt;Yeah, I must agree with you, the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v11.0.0%2Fexamples.html&amp;amp;cp=6_0_0_4"&gt;pwm_driver example in SDK 12.1.0&lt;/a&gt; has a lot of parameters. I figured out how things worked by looking at &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pwm.html?cp=2_2_0_46_0#concept_l3d_smw_nr"&gt;image 2 in the PS PWM chapter&lt;/a&gt; to realize that there is a counter that counts up to the specified top value, which is one pwm period, and then repeats the sequence.&lt;/p&gt;
&lt;p&gt;I have attached a simplified (hopefully) example which is more or less the code presented in the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.0.0/hardware_driver_pwm.html?cp=4_0_0_2_10_1#pwm_driver_using"&gt;pwm_driver documentation&lt;/a&gt;. Example output: Light intensity on LED_1 on the nRF52-DK is gradually increased and that sequence is repeated 4 times.&lt;/p&gt;
&lt;p&gt;How it works:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;base_clock runs at 1MHz and the top value is 1000. This means that the base clock ticks every 1 us and the top value is reached every 1us*1000=1ms&lt;/li&gt;
&lt;li&gt;The seq_values array includes 10 values. The first value in the array (value 0) is repeated 100 times (.repeats = 100), this means that the duty cycle is 0% for 1us* 1000* 100=100ms&lt;/li&gt;
&lt;li&gt;The next value is also repeated 100 times, i.e. for 100ms, namely the value 100, which gives 10% duty cycle&lt;/li&gt;
&lt;li&gt;After the last value has run for its 100ms, we delay it extra 500ms (end_delay = 500) before repeating the whole sequence&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can make this sequence repeat forever by setting&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 4, NRF_DRV_PWM_FLAG_LOOP);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or play the sequence only 4 times with&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_pwm_simple_playback(&amp;amp;m_pwm0, &amp;amp;seq, 4, NRF_DRV_PWM_FLAG_STOP);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is not much more to this example. The BSP is initialized and the bsp_evt_handler is defined so you can insert any code for desired button action into this handler.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/pwm_5F00_driver_5F00_simple.zip"&gt;pwm_driver_simple.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;An updated version of the example that compiles in SDK v13 can be found here:&lt;br /&gt;
&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/pwm_5F00_driver_5F00_simple_5F00_sdk13.zip"&gt;pwm_driver_simple_sdk13.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>