WATCHDOGS in STM32 || IWDG and WWDG || CubeIDE
55 views
Jul 19, 2020
Purchase the Products shown in this video from :: https://controllerstech.store ________________________________________________________________________________________ 00:28 IWDG (Independent WatchDog) 08:06 WWDG (Window WatchDog) STM32 Playlist :::: https://www.youtube.com/playlist?list=PLfIJKC1ud8gga7xeUUJ-bRUbeChfTOOBd DOWNLOAD THIS PROJECT FROM :::: https://controllerstech.com/iwdg-and-wwdg-in-stm32/ ________________________________________________________________________________________ ******* SUPPORT US BY DONATING****** https://paypal.me/controllertech *******Join the Membership******* https://www.youtube.com/channel/UCkdqtSMnhYuMsJkyHOxiPZQ/join Join the Discord Server https://discord.gg/D32JE5wKyD
View Video Transcript
0:00
hello everyone welcome to controllers
0:03
tech today in this video we will see how
0:07
to use independent watchdog and window
0:10
watchdog in stm32 watchdogs are
0:14
basically used to detect Fault in the
0:16
system we need to refresh the watchdogs
0:19
at a particular time interval or else
0:22
the system will reset the first of this
0:25
video will cover the independent
0:27
watchdog let's take a look at the
0:30
document provided by st i wdg have a
0:35
timeout range from 125 microseconds to
0:38
30 2.8 seconds it is clocked from a
0:42
separate internal low speed oscillator
0:45
this is an advantage even if the main
0:48
clock fails it will keep running here is
0:52
the block diagram you can refer it let's
0:56
start with cube ID create a project
1:00
first
1:05
I am using stm32f4 for 6r II give some
1:11
name to the project and click finish
1:23
first of all I am selecting the external
1:26
crystal for the clock now go to iw DG
1:30
and activate it we have prescaler here
1:40
and the down counter we will come back
1:43
to it let's first set the clock I have
1:47
eight megahertz crystal and I want the
1:49
system to run at 168 megahertz
1:53
note here that the LSI is 32 kilohertz
1:56
and it is consistent throughout all the
1:59
MCU s now let's go back to the document
2:07
there is a formula provided to calculate
2:10
the time based on prescaler and the
2:12
reload value I have modified this
2:15
formula to calculate the reload value
2:18
let's say we want the time out to be 20
2:22
milliseconds multiply it with 32,000
2:26
divided by 4 times to power the
2:30
prescaler we need to see the pre scalars
2:33
first
2:40
the prescaler numbers are zero one two
2:43
three four five six I will select number
2:49
one here you can select any other to
2:52
make sure you select lower prescaler for
2:55
lower timeout values to power one will
2:59
be two and write the rest of the
3:02
calculation so we got the reload counter
3:11
value as 79
3:20
click Save to generate the project
3:33
this is our main dot C file I am adding
3:37
a delay of 500 milliseconds and then
3:40
turning on the LED this will help us
3:43
identify if the system was reset and the
3:46
code executed from beginning
3:58
[Music]
4:02
i wdg we'll start with the IW d g init
4:12
function we should refresh the i w DG
4:16
within 20 milliseconds that's what we
4:20
input in the calculation I am giving a
4:23
delay of 18 milliseconds here we have a
4:30
function to reset the iw DG
4:38
[Music]
4:44
let's build and debug the program let me
4:49
just tell you what I am expecting here
4:51
if we are able to refresh the watchdog
4:54
before the timeout then the LED will
4:57
keep on but if we fail to do so the
5:00
system will keep resetting and the LED
5:03
will keep blinking you can see the LED
5:13
was turned on this is because we were
5:16
able to refresh the watchdog in 18
5:19
milliseconds and its timeout was set to
5:21
20 milliseconds that's why the while
5:25
loop kept executing let's increase the
5:28
delay before refresh now I am setting
5:32
the delay higher than the Refresh
5:33
timeout after the watchdog starts we
5:37
won't be able to refresh it before the
5:39
timeout and that's why the program
5:42
resets and start executing from the
5:45
beginning and we can see the LED
5:47
blinking
5:54
one more important thing about iw DG we
5:59
need to refresh the counter within the
6:01
predefined time though the interval is
6:05
set for 20 milliseconds even if i
6:07
refresh it every two milliseconds it
6:09
will continue working properly
6:19
now let's say we want to use higher
6:22
timeout like one second
6:40
for hire timeout we need to use hire
6:43
prescaler also I will use 60 for its
6:52
position is 4 and 2 power 4 will be 16
6:56
remember guys the count for the
6:59
prescaler starts from 0 the reload value
7:07
will be 499 let's put that here let's
7:12
try with 900 milliseconds first no let's
7:21
try with 950 as you can see the LED is
7:28
constantly on that means the watchdog is
7:31
getting refresh within time limit now I
7:34
will change the delay to 1,100
7:38
milliseconds
7:47
this time the LED is blinking means the
7:51
program is resetting as we are not able
7:53
to reset the watchdog in required time
7:56
limit the next part of this video will
7:59
cover window watchdog you can stop here
8:02
if you were just looking for eye wdg
8:06
unlike independent watchdog in WWD gee
8:10
we can't refresh the counter before a
8:12
minimum time and after a maximum time
8:15
here we get a small window to do the
8:18
refresh and that's why the named window
8:21
watchdog as mentioned in the document it
8:24
must be refreshed within a time window
8:26
otherwise it will generate a system
8:29
reset
8:36
this is the formula provided to
8:38
calculate the counter values of course
8:42
this doesn't give much idea so I have
8:45
modified it again to ease the
8:47
calculation
8:57
let's go back to Cuba next
9:08
I am going to copy this part cuz I want
9:12
to keep it same I am deactivating the AI
9:22
wdg activate the window watchdog we have
9:36
four sets of prescaler here first we
9:40
will see how to calculate reload counter
9:43
value this is the formula to calculate
9:46
counter value WWD GS connected to a PB 1
9:51
o'clock and it's frequency goes here
9:54
let's see the clock setup
9:58
[Music]
10:04
[Music]
10:10
my APB 1 o'clock is at forty five
10:13
megahertz this time here is the maximum
10:21
time within which we can refresh the
10:23
counter let's say we want it to be
10:26
twenty milliseconds APB clock is forty
10:35
five megahertz divided by required
10:39
values I am choosing the prescaler to
10:43
before and its position is two in the
10:45
line to power two will be for remember
10:50
guys the count for prescaler will start
10:53
with zero
10:59
we got the value around 119 the maximum
11:04
value here can be 127 and if I try to
11:08
enter 128
11:10
well I can't enter 119 here now the
11:17
formula to calculate window value here
11:21
will be the counter value that we just
11:23
found and the time here will be the
11:25
minimum time for the refresh let's say I
11:29
want the minimum time to be 13
11:31
milliseconds the prescaler should be
11:34
same as before
11:42
we got 83 as the window value so
11:46
basically we have to refresh the
11:48
watchdog within 13 to 20 milliseconds
11:51
this is our window for the Refresh if we
11:56
refresh outside it the system will reset
12:01
the LED will turn on here before the
12:05
watchdog initialize so if the system
12:08
resets we can see the LED blinking
12:11
otherwise the LED will be always on here
12:25
is the function to refresh the watchdog
12:28
I will use the delay of 15 milliseconds
12:37
first keeping in mind the requirement is
12:39
between 13 to 20 milliseconds let's
12:43
flash this on our board you can see the
12:50
LED is continuously on let's change the
12:54
delay I am using 18 milliseconds now we
13:06
got the same result again because the
13:09
delay was between the required time now
13:13
if I try with 10 milliseconds delay the
13:16
LED should blink because this delay lies
13:19
outside our window of 13 and 20 let's
13:24
try with another set of time limits
13:43
I will set the maximum time as 40
13:46
milliseconds if I keep the prescaler at
13:53
for the value for reload counties 173
13:58
this is higher than 127 and we can't use
14:02
it to handle this I will increase the
14:06
prescaler also I will use this prescaler
14:10
8 then to power 3 will be 8 and we got
14:21
the reload value within the limit
14:24
remember that both the values must be
14:26
between 64 and 127 now the calculation
14:38
for the window value I will keep the
14:41
minimum time as 30 milliseconds using
14:45
the prescaler of 8 we got the value for
14:51
the window
14:52
let's first test with the delay of 25
14:56
milliseconds
15:02
this is outside our window so the LED
15:05
must toggle due to system reset you can
15:15
observe that let's change it to 35 which
15:19
is within the time window and LED must
15:22
remain on and yes we got the expected
15:31
result one last thing about WWD G we can
15:37
also make it work like independent
15:39
watchdog and by that I mean that the WWD
15:43
G can also work without the minimum time
15:46
requirement you simply have to worry
15:49
about only the maximum time if we input
15:54
the window value same as the counter
15:56
value the minimum time for the window in
15:58
that case will have to be 0 let's check
16:06
if the LED can be kept on with the delay
16:08
of 2 milliseconds you can see the LED is
16:16
on but if you want to use it like
16:19
independent watchdog better use the
16:22
independent watchdog instead WWD G have
16:27
its own advantages but we can't use it
16:29
for the higher timings you can choose
16:32
either of them based on your requirement
16:34
this is it for the video guys I hope you
16:39
understood the video you can download
16:42
the code from the link in the
16:44
description be safe keep watching and
16:47
have a nice day
#Engineering & Technology
#Programming
#Software