<?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>How to change duty cycle when using HW driver library</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68125/how-to-change-duty-cycle-when-using-hw-driver-library</link><description>Hi 
 I am using the HW driver library for the PWM. 
 I looked at your example and in order to change the duty cycle of a channel, you directly change it in the m_demo1_seq_values. 
 The change is done in the handler, when NRF_DRV_PWM_EVT_FINISHED event</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 10 Nov 2020 10:37:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68125/how-to-change-duty-cycle-when-using-hw-driver-library" /><item><title>RE: How to change duty cycle when using HW driver library</title><link>https://devzone.nordicsemi.com/thread/279187?ContentTypeID=1</link><pubDate>Tue, 10 Nov 2020 10:37:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4627db9c-b6da-4528-8166-b0c8415f25bc</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;&lt;span&gt;&lt;span&gt;From nrfx_pwm.h line 142:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;NRFX_PWM_FLAG_LOOP&lt;br /&gt;&lt;br /&gt;When&amp;nbsp;the&amp;nbsp;requested&amp;nbsp;playback&amp;nbsp;is&amp;nbsp;finished,&amp;nbsp;&lt;/span&gt;&lt;span&gt;it&amp;nbsp;will&amp;nbsp;be&amp;nbsp;started&amp;nbsp;from&amp;nbsp;the&amp;nbsp;beginning. &lt;/span&gt;&lt;span&gt;This&amp;nbsp;flag&amp;nbsp;is&amp;nbsp;ignored&amp;nbsp;if&amp;nbsp;used&amp;nbsp;together&amp;nbsp;&lt;/span&gt;&lt;span&gt;with&amp;nbsp;@ref&amp;nbsp;NRFX_PWM_FLAG_STOP.&lt;/span&gt;&lt;span&gt;&amp;nbsp;@note&amp;nbsp;The&amp;nbsp;playback&amp;nbsp;restart&amp;nbsp;is&amp;nbsp;done&amp;nbsp;via&amp;nbsp;a&amp;nbsp;&lt;/span&gt;&lt;span&gt;shortcut&amp;nbsp;configured&amp;nbsp;in&amp;nbsp;the&amp;nbsp;PWM&amp;nbsp;peripheral. T&lt;/span&gt;&lt;span&gt;his&amp;nbsp;shortcut&amp;nbsp;triggers&amp;nbsp;the&amp;nbsp;proper&amp;nbsp;&lt;strong&gt;starting&amp;nbsp;t&lt;/strong&gt;&lt;/span&gt;&lt;span&gt;&lt;strong&gt;ask&lt;/strong&gt;&amp;nbsp;when&amp;nbsp;the&amp;nbsp;final&amp;nbsp;value&amp;nbsp;of the previous&amp;nbsp;&lt;/span&gt;&lt;span&gt;playback&amp;nbsp;is&amp;nbsp;read&amp;nbsp;from&amp;nbsp;RAM&amp;nbsp;and&amp;nbsp;applied&amp;nbsp;to &lt;/span&gt;&lt;span&gt;the&amp;nbsp;pulse&amp;nbsp;generator&amp;nbsp;counter. &lt;/span&gt;&lt;span&gt;When&amp;nbsp;this&amp;nbsp;mechanism&amp;nbsp;is&amp;nbsp;used&amp;nbsp;together&amp;nbsp;with&amp;nbsp;&lt;/span&gt;&lt;span&gt;the&amp;nbsp;@ref&amp;nbsp;NRF_PWM_STEP_TRIGGERED&amp;nbsp;mode,&lt;/span&gt;&lt;span&gt;&amp;nbsp;the&amp;nbsp;playback&amp;nbsp;restart&amp;nbsp;will&amp;nbsp;occur right&amp;nbsp;&lt;/span&gt;&lt;span&gt;after&amp;nbsp;switching&amp;nbsp;to&amp;nbsp;the&amp;nbsp;final&amp;nbsp;value&amp;nbsp;(this &lt;/span&gt;&lt;span&gt;final&amp;nbsp;value&amp;nbsp;will&amp;nbsp;be&amp;nbsp;played&amp;nbsp;only&amp;nbsp;once).&lt;br /&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
[quote user="arikramon"]According to nrfx_pwm.h, the function nrfx_pwm_sequence_update is updating the pointer to the duty cycle values&amp;nbsp; in the specified sequence during playback.[/quote]
&lt;p&gt;Acoording to the documentation you should only need to call this one function in order to update the sequence values when&amp;nbsp;&lt;span&gt;NRFX_PWM_FLAG_LOOP is set.&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change duty cycle when using HW driver library</title><link>https://devzone.nordicsemi.com/thread/279064?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 15:06:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6aeaf22b-d9bc-45e5-9cac-68fbb1419084</guid><dc:creator>arikramon</dc:creator><description>&lt;p&gt;If I am using flag=NRF_DRV_PWM_FLAG_LOOP, when the &lt;span&gt;TASKS_SEQSTART is triggered?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;is it triggered only once after nrfx_pwm_simple_playback is called?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;According to nrfx_pwm.h, the function nrfx_pwm_sequence_update is updating the pointer to the duty cycle values&amp;nbsp; in the specified sequence during playback.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Arik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change duty cycle when using HW driver library</title><link>https://devzone.nordicsemi.com/thread/279036?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 14:07:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3f628b8-1d10-465e-afad-cc7b5bad157d</guid><dc:creator>haakonsh</dc:creator><description>[quote user="arikramon"]&lt;ul&gt;&lt;li&gt;If I am using simple playback with two pins, with flag=NRF_DRV_PWM_FLAG_LOOP, when is the duty cycle is updated?&lt;/li&gt;
&lt;li&gt;There is a function call &amp;quot;nrfx_pwm_sequence_values_update&amp;quot; is it safe to use it at any time?&lt;/li&gt;&lt;/ul&gt;[/quote]
&lt;p&gt;&amp;nbsp;If you use&amp;nbsp;&lt;span&gt;nrfx_pwm_sequence_values_update it will update the next time a&amp;nbsp;TASKS_SEQSTART is triggered. By default, the driver triggers&amp;nbsp;TASKS_SEQSTART&amp;nbsp;when you call&amp;nbsp;&lt;/span&gt;nrfx_pwm_simple_playback. You can call&amp;nbsp;nrfx_pwm_simple_playback after the current loop is done or after you&amp;#39;ve called&amp;nbsp;nrfx_pwm_stop.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change duty cycle when using HW driver library</title><link>https://devzone.nordicsemi.com/thread/278971?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 11:08:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:652319d0-4645-48f5-b97f-eb2eeb035cf2</guid><dc:creator>arikramon</dc:creator><description>&lt;p&gt;Thank&amp;#39;s for the answer&lt;/p&gt;
&lt;p&gt;Two more questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If I am using simple playback with two pins, with flag=NRF_DRV_PWM_FLAG_LOOP, when is the duty cycle is updated?&lt;/li&gt;
&lt;li&gt;There is a function call &amp;quot;nrfx_pwm_sequence_values_update&amp;quot; is it safe to use it at any time?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Arik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change duty cycle when using HW driver library</title><link>https://devzone.nordicsemi.com/thread/278967?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 10:44:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d02204c5-b79a-41bb-843f-33ade5b9ec72</guid><dc:creator>haakonsh</dc:creator><description>[quote user=""]Can I change a duty cycle in m_demo1_seq_values not in the handler routine? the Duty cycle change occurs no so often, and I don&amp;#39;t want to enter the handler every time that NRF_DRV_PWM_EVT_FINISHED occur, as it &amp;quot;disturbs&amp;quot; the cpu[/quote]
&lt;p&gt;&amp;nbsp;Yes, there are two ways you can do it:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;You can wait until a&amp;nbsp;&lt;span&gt;EVENTS_SEQSTARTED[0] event has occured. This event signals that the PWM module has read the pointer address from &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pwm.html#register.SEQ-0.PTR"&gt;SEQ[0].PTR&lt;/a&gt;&amp;nbsp;and&amp;nbsp;stored it in an internal register. This is the address to your array of pwm duty-cycle samples (sequence).&lt;br /&gt;At this point in time it is safe to update the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/pwm.html#register.SEQ-0.PTR"&gt;SEQ[0].PTR&lt;/a&gt;&amp;nbsp;with the address to your new sequence of duty-cycles, but it must be done before the&amp;nbsp;next loop will start.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;You can modify the value of your sequence directly, though this is not safe unless you can guarantee there won&amp;#39;t be a race condition between you writing and the EasyDMA reading to/from the same address of memory at the same time. You can ensure this by either stopping the PWM, or use longer sequences and time your writing to the&amp;nbsp;EVENTS_SEQSTARTED[0] event, or any other suitable event.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]When changing the duty cycle, when the change actually take place?[/quote]
&lt;p&gt;&amp;nbsp;It depends on which method you used:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;When using multiple sequences, the PWM value is updated once the previous sequence is finished playing. If you are using loops, then all the loops must finish, unless you stop the PWM instance with a&amp;nbsp;&lt;span&gt;TASKS_STOP and then re-start it with a&amp;nbsp;TASKS_SEQSTART[0].&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;It will change as soon as the PWM module reads an updated sequence value.&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>