cancel
Showing results for 
Search instead for 
Did you mean: 

WatchDog Implementation on STM32F0 Discovery

wbarkley
Associate II
Posted on November 12, 2012 at 20:58

The following is my watchdog code.  The watchdog is triggering and I am constantly find myself in the startup routine.  Why?  Here is my watchdog related code:

//After Periph Clock set and before GPIO and NVIC setup

//RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);

    //WWDG_SetPrescaler(WWDG_Prescaler_1);

    //WWDG_SetWindowValue(0x7F);

    //WWDG_Enable(0x7F);

//in main's while loop

//1 tick = 10ms

        if (timeDiff >= 10){

            //WWDG_SetCounter(0x7F);

            for (loop = 0; loop < TIMERSIZE; loop++){

                if (tmrOn[loop] > 0){

                    on = 1;

                }

                else{

                    on = 0;

                }

                if (tmrTicks[loop] > 65530u){

                    tmrTicks[loop] = 65530u;

                }

                tmrTicks[loop] = on * (tmrTicks[loop] + 1);

            }

            lastTime = time;

            timeDiff = 0;

        }
4 REPLIES 4
Posted on November 12, 2012 at 21:21

Wouldn't you want to pick a Window Value that you have some chance of meeting? ie greater than 64, but LOWER than your starting point. If the window shuts as soon as it starts you're never going to be able to kick it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
wbarkley
Associate II
Posted on November 13, 2012 at 15:02

So WWDG_SetWindowValue(0x7F) function sets the value at which the watchdog downcounter will activate and reset micro?  Which is why it should be set greater than 0x40?  Can you get below 0x40 and is that a different type of watchdog timer reset?  Why did you suggest 0x64?

Posted on November 13, 2012 at 17:53

Have you looked at the example, or considered the IWDG?

STM32F0xx_StdPeriph_Lib_V1.0.0\Project\STM32F0xx_StdPeriph_Examples\WWDG\WWDG_Example\main.c

/* WWDG configuration */
/* Enable WWDG clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
/* WWDG clock counter = (PCLK1 (48MHz)/4096)/8 = 1464Hz (~683 us) */
WWDG_SetPrescaler(WWDG_Prescaler_8);
/* Set Window value to 80; WWDG counter should be refreshed only when the counter
is below 80 (and greater than 64) otherwise a reset will be generated */
WWDG_SetWindowValue(80);
/* Enable WWDG and set counter value to 127, WWDG timeout = ~683 us * 64 = 7 ms
In this case the refresh window is: ~683 * (127-80)= 1ms < refresh window < ~683 * 64 = 7ms
*/
WWDG_Enable(127);
while (1)
{
/* Toggle LED2 */
STM_EVAL_LEDToggle(LED2);
/* Insert 33 ms delay */
Delay(33);
/* Update WWDG counter */
WWDG_SetCounter(127);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
wbarkley
Associate II
Posted on November 13, 2012 at 21:42

Exactly my problem, I dont want to have to worry about setting the counter before I hit my window value and generating a reset because I hit the SetCounter statement too soon.  All I want is to refresh the counter periodically without worrying if I am going to get there too soon.  This is the watchdog implementation I am used, this getting there too soon is foreign to me.  How do I work around it? 

Basically, I want to SetCounter of my watchDog every 10 msec.  If it gets past 1 sec, then reset.  How do I do this?