<?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 stop PWM</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20107/how-to-stop-pwm</link><description>Hi,
i am working on PWM to operate vibration motor with different frequency levels. so that i integrated PWM Library example to my ble_app_uart example. in the PWM example i initialised PWM. i just want to run this for only 1 or 2 sec after that it should</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Mar 2017 12:54:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20107/how-to-stop-pwm" /><item><title>RE: how to stop PWM</title><link>https://devzone.nordicsemi.com/thread/78291?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 12:54:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:846d0bcd-57c0-48eb-97d9-7298310431d0</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Then you should looking into using a app_timer. Take a look at the &lt;a href="https://devzone.nordicsemi.com/tutorials/19/"&gt;Application Timer Tutorial&lt;/a&gt;. You should stop the PWM in the app_timer timeout handler. The ble_app_uart example already includes the app-timer. Here is some code snippets on how you can implement this.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP_TIMER_DEF(m_pwm_timer_id);

// Timeout handler for the timer
static void timer_handler(void * p_context)
{
    // ADD CODE TO TURN OFF PWM
}

static void create_timer()
{   
    uint32_t err_code;

    // Create timers
    err_code = app_timer_create(&amp;amp;m_pwm_timer_id,
                                APP_TIMER_MODE_SINGLE_SHOT,
                                timer_handler);
    APP_ERROR_CHECK(err_code);
}



static void start_pwm_timer()
{
    uint32_t err_code;

    //ADD CODE TO START THE PWM. (app_pwm_enable() + set duty cycle)

    // Start timer, call the timout handler afte 2 sec
    err_code = app_timer_start(m_pwm_timer_id,
                                APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER),
                                NULL);
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to stop PWM</title><link>https://devzone.nordicsemi.com/thread/78290?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 12:41:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b82657da-294e-4294-9363-0c6f5d14d6f1</guid><dc:creator>saiteja</dc:creator><description>&lt;p&gt;i want to run the PWM for 2 sec and then it should stop. how to do this with out using while(true)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to stop PWM</title><link>https://devzone.nordicsemi.com/thread/78292?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 11:48:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aebf7577-4a3a-4160-a78c-43aa8b5c57a6</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can disable the PWM instance using the function &lt;code&gt;app_pwm_disable()&lt;/code&gt;, and uninitialize the PWM instance using &lt;code&gt;app_pwm_uninit()&lt;/code&gt;. Note that your function &amp;quot;PWM_init&amp;quot; is will be stuck in the &lt;code&gt;while(true)&lt;/code&gt; loop, constantly changing the duty cycle.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>