watchdog timer in MKV46F256VLL16

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

watchdog timer in MKV46F256VLL16

Jump to solution
1,807 Views
soaring_sun
Contributor III

Hi,

 I have been working on the usage of watch dog timer in my application. For this, I have referred the example project. I needed a few clarifications regarding the example project to help me understand better.

Capture.PNG

Here, there is an infinite while loop that runs after a few instructions are executed. But in the console, I see that the compiler does not get stuck at this point, but continues to run further lines. How is that possible? If I un-comment the line within the while loop, then the compiler gets stuck in the infinite loop. Why is that?

Capture.PNG

The same applies to the next set of instructions. Here the wdog_reset_counter is getting updated from WDOGResetCount(); How is this changed every time? Which function is causing this change?

0 Kudos
1 Solution
1,729 Views
soaring_sun
Contributor III

Hi,

I had to add the watchdog driver to make sure that it was activated in the peripheral driver section to program it. Once it was done, I was able to program it.

My bad.

View solution in original post

0 Kudos
5 Replies
1,739 Views
soaring_sun
Contributor III

Hi Omar,

I am using PWM interrupt timer of 15KHz to generate 20ms. I saw that in the BOARD_InitBootPins(); function, watchdog was already initialized due to which it was getting a double command. Once that init function was made okay, the watchdog seemed to work properly as I expected.

Now that I have initialized my own watchdog with my own instructions, I went ahead to do the same with the config tools. In the clock section, I have selected the watchdog timer to be active and have selected LPO frequency for operation. Once this is set, I go the peripheral section to generate the code. But unfortunately, I find that there is no provision for me to generate.

Why does that happen? Have I missed any configuration? Should the MCG mode be different? Shouldn't watchdog be operational at all modes? Or should I be manually be writing the code for it?

Screenshot (20).pngScreenshot (21).png

Please send a manual which describes which mode to be used during these operations as it is not clear in the TRM.

Thank you

0 Kudos
1,730 Views
soaring_sun
Contributor III

Hi,

I had to add the watchdog driver to make sure that it was activated in the peripheral driver section to program it. Once it was done, I was able to program it.

My bad.

0 Kudos
1,785 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello soaring_sun

 

I will gladly answer your questions.
In the "while" cycle the watchdog timer is running without being fed, since the watchdog is not refreshing the MCU will be restarted by the module and increase the reset count.

Let me know if this is helpful, if you have more questions do not hesitate to ask me.
Best regards,
Omar

0 Kudos
1,770 Views
soaring_sun
Contributor III

Oh, that explains a lot. Thank you.

I went ahead to use the same logic in my program. So, I now want to use a watchdog timer, give a timer value and refresh it before the watchdog expires so that my program will continue to work without resetting the MCU.

The following is the program that I am using. I am using an interrupt to generate a 20ms flag. Every 20ms I refresh the watchdog so as to not to reset MCU. Timeout value is 0x28 in hex for 40ms considering LPO = 1KHz. (Is that the right way to calculate??)

To make sure that my program is running smoothly, I have a running pwm pulse and I'm monitoring it. But on the oscilloscope, I notice that there is a glitch every 20ms which halts the pulsing.

	WDOG_GetDefaultConfig(&config);
	config.timeoutValue = 0x28U;
	WDOG_Init(wdog_base, &config);
	while (1)
	{
		if(flag_20ms == 1)
		{
			flag_20ms = 0;
			GPIO_PortToggle(GPIOD, 1u << 1u);
			WDOG_Refresh(wdog_base);
		}
	}

Where am I going wrong? For my application, is there a need for interrupt to be used? Is this the right way to initialize WDOG?

 

If I remove the interrupts and only run the program with watchdog, then ate every 20ms, the console gets refreshed and the MCU is reset. How can I avoid this?

	WDOG_GetDefaultConfig(&config);
	config.timeoutValue = 0x28U;
	WDOG_Init(wdog_base, &config);

	for(int i = 0; i < 10; i ++)
	{
		PRINTF("--- Refresh wdog %d time ---\r\n", i + 1);
	}

	while (1)
	{
//		if(flag_20ms == 1)
		{
//			flag_20ms = 0;
//			GPIO_PortToggle(GPIOD, 1u << 1u);
			WDOG_Refresh(wdog_base);
		}
	}

the console reading is as follows

Capture.PNG

 

 Help me figure this out.

thank you in advance

0 Kudos
1,747 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

The time-out value is defined in terms of cycles of the watchdog clock so the value you set is correct.
You can use the interruption when you want to execute other tasks in your program and only refresh the watchdog when it is necessary, the interruption will allow you concurrency.
Which timer are you using to generate the 20ms interruption? It would be helpful if you attach a picture of the glitch on the PWM.
I suggest before starting an update or refresh sequence, disable global interrupts, after the sequence finishes, restore global interrupts.

I look forward to your reply, if you have more questions do not hesitate to ask me.
Best regards,
Omar

0 Kudos