This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How does the Watchdog work?

Hi, i need to use a watchdog in my application. I read that i can use the build in one, but i thing my configuration or the usage of the watchdog is wrong. here is my config:


void WatchDogInit															(void)
{
	NRF_WDT->CONFIG =  	(WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos); 
								  
	NRF_WDT->CRV = (32768 * 1); 	 
	NRF_WDT->RREN = WDT_RREN_RR0_Msk; 									
	
                    
    NRF_WDT->INTENSET=WDT_INTENSET_TIMEOUT_Msk;									
	                 
                                sd_nvic_ClearPendingIRQ(WDT_IRQn);													
	sd_nvic_SetPriority				(WDT_IRQn, APP_IRQ_PRIORITY_HIGH);		
	sd_nvic_EnableIRQ	 (WDT_IRQn);													
	NRF_WDT->TASKS_START = 1; // Watchdog start
}

when do i have to call this init method? Is tehre anything to lookfor, do i have to run it befor enabling the SD or something like that?

here is my example loop for testing it


					while (true)
					{
						NRF_WDT->RR[0] = WDT_RR_RR_Reload; ;//WDT_RR_RR_Reload;
						switch_stat_g(1);
						nrf_delay_ms(2000);
						switch_stat_g(0);
						nrf_delay_ms(2000);
					}

Do i use it in a wrong way?

Thank you for help and best regards, Nils :)

Parents
  • Hi Hakon, Thank you for your answer and your example. I tried out what you told me and i think it doesn't work. If I run your example, the LED flashes up after init but nothing more the is no reset of the WD the LED only blinks one Time, doesn't matter if i do Relaod or not.

    Here is my example i don#t understand why the is no reset. The WD Counter set to 32768 that means a reset after 1 Second, is that right? And i do not reload RR[0] but after One Second is no reset.

    It should be Start->LED on 1 Sek->Reset and don't start while loop. But it starts the while loop.

    Here is my Code:

    
    #include "nrf51.h"
    #include "nrf_gpio.h"
    #include "nrf_delay.h"
    #include <stdint.h>
    #include <string.h>
    #include <stdbool.h>
    
    // Counter is in 32kHz ticks. (NRF_WDT->CRV + 1)/32768 seconds
    #define WATCHDOG_COUNTER        32768
    #define MY_LED                  19
    
    
    void init_watchdog(void)
    {
        NRF_WDT->CONFIG = (WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);
        NRF_WDT->CRV = WATCHDOG_COUNTER;    
        NRF_WDT->RREN = WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos;
        NRF_WDT->TASKS_START = 1;
    }
    
    int main(void)
    {		
    			nrf_gpio_cfg_output(MY_LED);
    			nrf_gpio_pin_set(MY_LED);
    			nrf_delay_ms(1000);
    						
    			init_watchdog ( );
    	
    			nrf_gpio_pin_clear(MY_LED);
    				
    			while (true)
    			{
    				//NRF_WDT->RR[0] = WDT_RR_RR_Reload;  //Reload watchdog register 0
    				nrf_gpio_pin_set(MY_LED);
    				nrf_delay_ms(600);
    				nrf_gpio_pin_clear(MY_LED),
    				nrf_delay_ms(500); 
    			}
    }
    /**
     *@}
     **/
    
    

    I realy don't understand why there is no reset. I think i do a mistake but where?

    Thank you and best regards Nils.

Reply
  • Hi Hakon, Thank you for your answer and your example. I tried out what you told me and i think it doesn't work. If I run your example, the LED flashes up after init but nothing more the is no reset of the WD the LED only blinks one Time, doesn't matter if i do Relaod or not.

    Here is my example i don#t understand why the is no reset. The WD Counter set to 32768 that means a reset after 1 Second, is that right? And i do not reload RR[0] but after One Second is no reset.

    It should be Start->LED on 1 Sek->Reset and don't start while loop. But it starts the while loop.

    Here is my Code:

    
    #include "nrf51.h"
    #include "nrf_gpio.h"
    #include "nrf_delay.h"
    #include <stdint.h>
    #include <string.h>
    #include <stdbool.h>
    
    // Counter is in 32kHz ticks. (NRF_WDT->CRV + 1)/32768 seconds
    #define WATCHDOG_COUNTER        32768
    #define MY_LED                  19
    
    
    void init_watchdog(void)
    {
        NRF_WDT->CONFIG = (WDT_CONFIG_SLEEP_Run << WDT_CONFIG_SLEEP_Pos);
        NRF_WDT->CRV = WATCHDOG_COUNTER;    
        NRF_WDT->RREN = WDT_RREN_RR0_Enabled << WDT_RREN_RR0_Pos;
        NRF_WDT->TASKS_START = 1;
    }
    
    int main(void)
    {		
    			nrf_gpio_cfg_output(MY_LED);
    			nrf_gpio_pin_set(MY_LED);
    			nrf_delay_ms(1000);
    						
    			init_watchdog ( );
    	
    			nrf_gpio_pin_clear(MY_LED);
    				
    			while (true)
    			{
    				//NRF_WDT->RR[0] = WDT_RR_RR_Reload;  //Reload watchdog register 0
    				nrf_gpio_pin_set(MY_LED);
    				nrf_delay_ms(600);
    				nrf_gpio_pin_clear(MY_LED),
    				nrf_delay_ms(500); 
    			}
    }
    /**
     *@}
     **/
    
    

    I realy don't understand why there is no reset. I think i do a mistake but where?

    Thank you and best regards Nils.

Children
Related