<?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 configuration to stop it after x number of pulses</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74842/pwm-configuration-to-stop-it-after-x-number-of-pulses</link><description>We need to work with the PWM, the idea is to set one frequency, duty 50%, and put out these pulses to one pin, we understand how to do that but we need to stop these pulses after a number x of pulses, one option we think connects it with the event to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 May 2021 09:50:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74842/pwm-configuration-to-stop-it-after-x-number-of-pulses" /><item><title>RE: PWM configuration to stop it after x number of pulses</title><link>https://devzone.nordicsemi.com/thread/309172?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 09:50:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:521bab21-7264-4f2b-91b4-a2c150edb003</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;One option is to run the PWM from a function from main, a separate thread, or a&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/zephyr/reference/kernel/threads/workqueue.html"&gt;work queue&lt;/a&gt;&amp;nbsp;thread like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void run_pwm(struct k_work *work){
    pwm_pin_set_usec(pwm, PIN, PERIOD, PULSE , 0);
    k_sleep(DURATION);
    //STOP PWM
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You could also use the NRFX api and the function &lt;a href="https://github.com/nrfconnect/sdk-hal_nordic/blob/v1.5.1/nrfx/drivers/include/nrfx_pwm.h#L227-L259"&gt;nrfx_pwm_simple_playback()&lt;/a&gt;. Check out this case for more information about this function:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/73503/nrfx_pwm_simple_playback-on-nrf9160"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/73503/nrfx_pwm_simple_playback-on-nrf9160&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you change your mind about timers, this ticket may be useful:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/74591/timers-in-nrf5340"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/74591/timers-in-nrf5340&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>