<?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>WDT triggered too early</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50147/wdt-triggered-too-early</link><description>Hi everyone, 
 
 I&amp;#39;m using nrf52840 custom board (pca10056) 
 SDK version: 15.3 
 OS: Fedora 
 
 I work on a custom board and try to use WDT like so in the WTD project example: 
 
 When I set the reload value to 10 000ms my WDT is triggered every 10s</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 24 Jul 2019 10:52:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50147/wdt-triggered-too-early" /><item><title>RE: WDT triggered too early</title><link>https://devzone.nordicsemi.com/thread/200257?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2019 10:52:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4490418c-f58d-4de9-a17e-caf8e13b92ee</guid><dc:creator>awneil</dc:creator><description>[quote userid="80791" url="~/f/nordic-q-a/50147/wdt-triggered-too-early/200251"]why do I need to modify the SDK to fix this issue[/quote]
&lt;p&gt;Because, as &lt;a href="https://devzone.nordicsemi.com/members/ojousima"&gt;Otso Jousimaa&lt;/a&gt;&amp;nbsp;explained, the issue is due to a bug in the SDK!&lt;/p&gt;
&lt;p&gt;See also:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/49901/there-is-an-error-in-the-wdt-driver-sdk15-2/199583#199583"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/49901/there-is-an-error-in-the-wdt-driver-sdk15-2/199583#199583&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT triggered too early</title><link>https://devzone.nordicsemi.com/thread/200251?ContentTypeID=1</link><pubDate>Wed, 24 Jul 2019 10:27:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9074fed9-ac8f-4edf-890a-ddc480629ff7</guid><dc:creator>Louis Hatte</dc:creator><description>&lt;p&gt;Hi Otso,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now it works but why do I need to modify the SDK to fix this issue?&lt;/p&gt;
&lt;p&gt;Is there no better way to resolve this problem?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Louis&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: WDT triggered too early</title><link>https://devzone.nordicsemi.com/thread/200142?ContentTypeID=1</link><pubDate>Tue, 23 Jul 2019 15:37:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf216ee1-ef8e-4341-8e29-5ebd4f07fac0</guid><dc:creator>Otso Jousimaa</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You&amp;#39;re not doing anything wrong. The SDK15.3 watchdog init function is here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrfx_err_t nrfx_wdt_init(nrfx_wdt_config_t const * p_config,
                         nrfx_wdt_event_handler_t  wdt_event_handler)
{
    NRFX_ASSERT(p_config);
    nrfx_err_t err_code;

#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
    NRFX_ASSERT(wdt_event_handler != NULL);
    m_wdt_event_handler = wdt_event_handler;
#else
    NRFX_ASSERT(wdt_event_handler == NULL);
    (void)wdt_event_handler;
#endif
    if (m_state == NRFX_DRV_STATE_UNINITIALIZED)
    {
        m_state = NRFX_DRV_STATE_INITIALIZED;
    }
    else
    {
        err_code = NRFX_ERROR_INVALID_STATE;
        NRFX_LOG_WARNING(&amp;quot;Function: %s, error code: %s.&amp;quot;,
                         __func__,
                         NRFX_LOG_ERROR_STRING_GET(err_code));
        return err_code;
    }

    nrf_wdt_behaviour_set(p_config-&amp;gt;behaviour);

    nrf_wdt_reload_value_set((p_config-&amp;gt;reload_value * 32768) / 1000);

#if !NRFX_CHECK(NRFX_WDT_CONFIG_NO_IRQ)
    NRFX_IRQ_PRIORITY_SET(WDT_IRQn, p_config-&amp;gt;interrupt_priority);
    NRFX_IRQ_ENABLE(WDT_IRQn);
#endif

    err_code = NRFX_SUCCESS;
    NRFX_LOG_INFO(&amp;quot;Function: %s, error code: %s.&amp;quot;, __func__, NRFX_LOG_ERROR_STRING_GET(err_code));
    return err_code;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;the nrfx_wdt_config_t-&amp;gt;reload_value is uint32_t.&lt;/p&gt;
&lt;p&gt;When you set the reload to 360 000, it gets multiplied by 32768 which is&amp;nbsp;11 796 480 000 and the uint32_t overflows.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As a fix convert the reload_value to uint64_t before multiplication:&lt;/p&gt;
&lt;pre&gt;  if((((uint64_t) p_config-&amp;gt;reload_value * 32768) / 1000) &amp;gt;
      UINT32_MAX)  // Check for overflow
  {
    return NRF_ERROR_INVALID_PARAM;
  }&lt;/pre&gt;
&lt;pre&gt;  nrf_wdt_reload_value_set(((uint64_t) p_config-&amp;gt;reload_value * 32768) / 1000);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>