<?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>PWM Dutychange with a custom variable array</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66844/pwm-dutychange-with-a-custom-variable-array</link><description>Hi , i am using the nRF52DK and i have a small problem with the pwm driver. 
 i basically would like that the frequency increases if i press a button or decreases if I press another button while keeping the same 50% duty cycle. 
 The way i attempted it</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 08 Oct 2020 22:59:04 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66844/pwm-dutychange-with-a-custom-variable-array" /><item><title>RE: PWM Dutychange with a custom variable array</title><link>https://devzone.nordicsemi.com/thread/273885?ContentTypeID=1</link><pubDate>Thu, 08 Oct 2020 22:59:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fbfa6288-0bbf-47f5-9549-eee0a0a752cb</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Without writing an example, I think I would disagree, if I may. This would be the trick:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Structure holding duty cycle 0, 1 and 2 and top value which is max pwm pulse width
// The 15-bit wave counter is responsible for generating the pulses at a duty cycle that depends on the compare
// values, and at a frequency that depends on COUNTERTOP. MS bit is the sign, &amp;#39;1&amp;#39; active high starting pulse
//
//  DECODER.LOAD = Repeat
//  =====================
//  PWM with Nordic library code
//
//   +----------------------------------&amp;gt; COMP0 OUT[0] Compare 0 - PIN_PWM_1
//   |         +------------------------&amp;gt; COMP1 OUT[1] Compare 1 - PIN_PWM_2
//   |         |         +--------------&amp;gt; COMP2 OUT[2] Compare 2 - PIN_OTHER
//   |         |         |               (COMP3 OUT[3] Compare 3 not used)
//   |         |         |         
// +---------+---------+---------+---------+
// | Compare | Compare | Compare | Top     | Cycle N
// +---------+---------+---------+---------+
// | Compare | Compare | Compare | Top     | Cycle N+1
// +---------+---------+---------+---------+
//                                 |
//                                 +----&amp;gt; COUNTERTOP Cycle Period 4 steps, 1MHz clocks. Range 3-32767&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The table is in RAM, and the PWM can be set up to LOOP or toggle between two tables. Since the data is in RAM and is read every PWM cycle it can be synchronously changed on-the-fly without stopping. The ratio Top:Compare=50%must be maintained of course.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PWM Dutychange with a custom variable array</title><link>https://devzone.nordicsemi.com/thread/273781?ContentTypeID=1</link><pubDate>Thu, 08 Oct 2020 13:40:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7de6d90b-dcf7-4fc0-bfeb-b574c248d520</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]&lt;p&gt;i am using the nRF52DK and i have a small problem with the pwm driver.&lt;/p&gt;
&lt;p&gt;i basically would like that the frequency increases if i press a button or decreases if I press another button while keeping the same 50% duty cycle.&lt;/p&gt;
&lt;p&gt;The way i attempted it is that i have an array with different top values that correspond to different frequencies. but I&amp;#39;m struggling to put it in seq_vallues and get the 50%. my code can be seen below.&lt;/p&gt;[/quote]
&lt;p&gt;Unfortunately, the only way to change the pwm frequency is by disabling + uninitializing the pwm instance, before configuring the new frequency, init&amp;#39;ing and enabling it again.&lt;br /&gt;However, this is done pretty fast - much faster than the time it takes for you to finish pressing a button - so this should not be an issue for this application.&lt;br /&gt;There are multiple threads on the forums discussing this already. Please take a look at &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/31035/how-to-change-pwm-frequency"&gt;this thread, for a more in-depth discussion on the issue&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>