<?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>Best way to reload an app timer with a new value?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3015/best-way-to-reload-an-app-timer-with-a-new-value</link><description>Currently, I&amp;#39;m using the following: 
 if((err_code = app_timer_stop(m_timer_id)) == NRF_SUCCESS)
{
 err_code = app_timer_start(m_timer_id, APP_TIMER_TICKS(g_timer_val*1000, APP_TIMER_PRESCALER), NULL);
 APP_ERROR_CHECK(err_code);
}
else
{
 APP_ERROR_CHECK</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Jul 2014 06:07:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3015/best-way-to-reload-an-app-timer-with-a-new-value" /><item><title>RE: Best way to reload an app timer with a new value?</title><link>https://devzone.nordicsemi.com/thread/11368?ContentTypeID=1</link><pubDate>Mon, 21 Jul 2014 06:07:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d99d9681-9a4a-4e29-91e5-70b488fc9842</guid><dc:creator>Nick</dc:creator><description>&lt;p&gt;The solution to this is to use the &lt;strong&gt;event scheduler&lt;/strong&gt; so that the timer actually stops before it is re-started (as app_timer_stop and app_timer_start will now be executed from the main context).&lt;/p&gt;
&lt;p&gt;Event function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void reset_idle_timer_event(void * p_event_data, uint16_t event_size)
{
reset_idle_timer();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Scheduling event:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;// Reset idle timer
err_code = app_sched_event_put(NULL, NULL, reset_idle_timer_event);
APP_ERROR_CHECK(err_code);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Reset timer function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void reset_idle_timer(void)
{
    uint32_t err_code;
    
    // Stop timer
    err_code = app_timer_stop(m_idle_timer_id);
    APP_ERROR_CHECK(err_code);

    // Start timer
    err_code = app_timer_start(m_idle_timer_id, APP_TIMER_TICKS(idle_timer_val*1000, 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></channel></rss>