PIC32MZ tutorial -- Watchdog Timer
Watchdog is a very necessary module for embedded system. Someone said that embedded system operates without watchdog enabled just like the car without air bag. You should always enabled watchdog as possible as you can.
The PIC32MZ Watchdog Timer (WDT), when enabled, operates from the internal Low-Power RC (LPRC) Oscillator clock source which is 32.768 KHz. The WDT can be used to detect system software malfunctions by resetting the device if the WDT is not cleared periodically in software. The WDT can be configured in Windowed mode or non-Windowed mode. Various WDT time-out periods can be selected using the WDT postscaler. The WDT can also be used to wake the device from Sleep or Idle mode.
At the moment, I implement the primary function of the WDT is to reset the processor in the event of a software malfunction. I enable WDT with Non-Windowed mode, and the WDT will increment until it overflows or "times out". A WDT time-out will force a device Reset, except during Sleep or Idle modes. To prevent a WDT time-out Reset, my application always periodically clear the WDT by writing a key word 0x5743 to the WDTCLEKEY (WDTCON<31:16>) through a single 16-bit write (for some other devices, or by setting the WDTCLR (WDTCON<0>).
The WDT is enabled or disabled by the device configuration bits or controlled through software by writing to the WDTCON register. In my application I just set the device configuration bits like below.
#pragma config WDTPS = PS32 // Watchdog Timer Postscaler (1:32)
#pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)
#pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)
#pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)
#pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%)
The setting as above, the postscaler of Watchdog Timer is 32. It determines the period of Watchdog Timer overflow is 32ms. The FWDTEN Configuration bit is clear, so I need enable Watchdog Timer by software, and I also need a function to clear Watchdog and call this function periodically in the main loop. Below is my implementation of them.
void Wdt_Init(void)
{
WDTCONSET = 0x8000;
} void Wdt_Refresh(void)
{
unsigned short *pWdtClear = (unsigned short *)0xBF800800 + ;
*pWdtClear = 0x5743;
}
PIC32MZ tutorial -- Watchdog Timer的更多相关文章
- PIC32MZ tutorial -- 32-bit Timer
The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...
- PIC32MZ tutorial -- Core Timer
Core Timer is a very popular feature of PIC32 since it is a piece of the MIPS M4K core itself and is ...
- PIC32MZ tutorial -- OC Interrupt
In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...
- PIC32MZ tutorial -- External Interrupt
In my older blog "PIC32MZ tutorial -- Key Debounce", I shows how to acheive key debounce w ...
- PIC32MZ tutorial -- Output Compare
Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...
- PIC32MZ tutorial -- Hello World
Today I implement "Hello World" on PIC32MZ EC starter kit. The application of "Hello ...
- PIC32MZ tutorial -- Timer Interrupt
An interrupt is an internal or external event that requires quick attention from the controller. The ...
- PIC32MZ tutorial -- Input Capture
Today I accomplish a simple application for PIC32MZ EC Starter Kit. This application uses Input Capt ...
- PIC32MZ tutorial -- Change Notification
In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...
随机推荐
- SAP web 开发 (第二篇 bsp 开发 mvc模式 Part1 )
Model-View-Controller 简称MVC. 简单的说就是把数据处理,显示,页面事件及处理过程分离开来,企业应用多数都采用这种方式,多层架构的优缺点不再多言,google一下啥都知道. 在 ...
- Day9 summary
昨天又翻出收藏夹里一个叫“谷子粒”的bloghttp://1.guzili.sinaapp.com/?p=128#more-128,链接是博主整理的机器学习方面的热点微博,相当的干货.要说我是从知乎对 ...
- windows核心编程---第六章 线程的调度
每个线程都有一个CONTEXT结构,保存在线程内核对象中.大约每隔20ms windows就会查看所有当前存在的线程内核对象.并在可调度的线程内核对象中选择一个,将其保存在CONTEXT结构的值载入c ...
- git 添加ssh的方法 push免登陆
在github.com上 建立了一个小项目,可是在每次push 的时候,都要输入用户名和密码,很是麻烦 原因是使用了https方式 push 在termail里边 输入 git remote -v ...
- HDU1016 dfs
刷回溯的时候发现我对DFS思路很不清晰,总是做着做着就乱了,刷个水题找找思路. 题意:经典DFS,找出所有的能让1~n的数形成素数环的序列(相邻相加为素数): #include <iostrea ...
- HDU1005(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 #include<cstdio> using namespace std; int ...
- PCL安装使用
一. 下载安装 http://pointclouds.org/downloads/windows.html 1. QT安装在默认路径下(否则后续会出现问题),添加环境变量QTDIR(c:\Qt\4.8 ...
- Android关联源码support-v4,v7,v13源码(转)
在Android实际开发过程中往往会遇到使用v4,v7或v13兼容包中的一些类如ViewPager,Fragment等,但却无法关联源码. 在网上搜索之后,有很多办法,这里只向大家介绍一种,我用的觉得 ...
- html5本地存储的解决
1.解决了Cookie 4K存储大小的问题2.解决了请求头常带存储信息的问题3.解决了关系型存储的问题4.跨域问题,跨浏览器*在 HTML5 中,数据不是由每个服务器请求传递的,而是只有在请求时使用 ...
- HTML5实战与剖析之触摸事件(touchstart、touchmove和touchend)
HTML5中新添加了很多事件,但是由于他们的兼容问题不是很理想,应用实战性不是太强,所以在这里基本省略,咱们只分享应用广泛兼容不错的事件,日后随着兼容情况提升以后再陆续添加分享.今天为大家介绍的事件主 ...