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的更多相关文章

  1. PIC32MZ tutorial -- 32-bit Timer

    The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...

  2. 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 ...

  3. PIC32MZ tutorial -- OC Interrupt

    In my previous blog "PIC32MZ tutorial -- Output Compare", I shows how to apply Output Comp ...

  4. PIC32MZ tutorial -- External Interrupt

    In my older blog "PIC32MZ tutorial -- Key Debounce", I shows how to acheive key debounce w ...

  5. PIC32MZ tutorial -- Output Compare

    Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...

  6. PIC32MZ tutorial -- Hello World

    Today I implement "Hello World" on PIC32MZ EC starter kit. The application of "Hello ...

  7. PIC32MZ tutorial -- Timer Interrupt

    An interrupt is an internal or external event that requires quick attention from the controller. The ...

  8. PIC32MZ tutorial -- Input Capture

    Today I accomplish a simple application for PIC32MZ EC Starter Kit. This application uses Input Capt ...

  9. PIC32MZ tutorial -- Change Notification

    In my last post I implement "Key Debounce" with port polling, port polling is not very eff ...

随机推荐

  1. 大量无线键盘存在KeySniffer漏洞-可嗅探用户输入的内容

    几美元的一根天线.一个无线发射器,还有几行Python代码,有了这些,黑客就可以在几十米开外主动地记录下你的用户名.密码.信用卡.你写的稿子,总之就是你用无线键盘输入的任何东西. 黑客所利用的是一种无 ...

  2. H.264 / MPEG-4 Part 10 White Paper-翻译

    1. Introduction Broadcast(广播) television and home entertainment(娱乐) have been revolutionised(彻底改变) b ...

  3. hibernate的数据库乱码问题

    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration ...

  4. “cv”: 具有该名称的命名空间不存在

    记得添加#include<highgui.h> 无法解析的外部符号 遇到这种问题一般都是由于缺少相应的库文件 右击项目,选择“属性”--“链接器”--“输入”--“附加依赖项” 根据错误中 ...

  5. iOS Xcodebuild

    简介 xcodebuild 是苹果发布自动构建的工具.它在一个Xcode项目下能构建一个或者多个targets ,也能在一个workspace或者Xcode项目上构建scheme,总的来说,用它没错就 ...

  6. GO RPC

    HTTP RPC SERVER CODE package main import ( "errors" "fmt" "net/http" & ...

  7. Node.js高级编程读书笔记 - 1 基本概念

    Outline 1 概述和安装 1.1 安装Node 1.2 Node简介 2 Node核心API基础 2.1 加载模块 2.2 应用缓冲区处理.编码和解码二进制数据 2.3 使用时间发射器模式简化事 ...

  8. jquery事件重复绑定的快速解决方法

    click等事件 解决:使用unbind("click")方法先解除绑定的事件再绑定新事件,即在给对象绑定事件之前先移除该对象上的原有事件 1 $("#test2&quo ...

  9. DHCP服务器安装及配置

    一.什么是DHCP? DHCP (Dynamic Host Configuration protocol)动态主机设置协议,基于UDP(发送很小的数据报文,且对时效性要求较高)协议通信. 它是C/S架 ...

  10. LeetCode 【235. Lowest Common Ancestor of a Binary Search Tree】

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...