安全微控制器系列(DS5000FP、DS5001FP、DS5002FP和相關(guān)模塊)集成了內(nèi)部看門狗定時器,以防止代碼執(zhí)行錯誤。看門狗定時器使用微控制器也使用的高精度晶體振蕩器。這消除了對RC振蕩器的需求,同時提供了更高的精度。
概述
微控制器通常用于電源瞬變、電磁干擾 (EMI) 和靜電放電 (ESD) 豐富的惡劣環(huán)境中。總線損壞和電磁放電引起的程序損壞可能導(dǎo)致微處理器執(zhí)行錯誤的指令。在這些環(huán)境中,看門狗定時器是一種有用的外設(shè),可以幫助捕獲和重置已“失控”的微控制器。
看門狗定時器是一個簡單的倒數(shù)定時器,用于在特定時間間隔后重置微處理器。在正常運行的系統(tǒng)中,軟件將定期“寵愛”或重新啟動看門狗定時器。重新啟動后,看門狗將開始計時另一個預(yù)定間隔。當(dāng)軟件或設(shè)備無法正常運行時,軟件不會在超時之前重新啟動看門狗計時器。當(dāng)看門狗定時器超時時,將導(dǎo)致微控制器復(fù)位。如果系統(tǒng)軟件設(shè)計正確且沒有硬件故障,則重置將導(dǎo)致系統(tǒng)再次正常運行。重置條件必須是“安全”狀態(tài)。例如,讓磁條讀卡器的復(fù)位狀態(tài)啟用寫入磁頭是不明智的。
許多系統(tǒng)都是使用外部看門狗定時器設(shè)計的。安全微控制器系列通過集成內(nèi)部看門狗定時器,無需外部元件。通過在微控制器內(nèi)移動看門狗定時器,可以減少系統(tǒng)中的器件數(shù)量,從而提高整體系統(tǒng)可靠性。看門狗定時器可以利用微控制器使用的高精度晶體振蕩器,而不是大多數(shù)獨立看門狗定時器使用的不精確的RC振蕩器。看門狗定時器的操作與微控制器無關(guān),除非通過定時訪問程序?qū)iT解決。失控的微控制器意外禁用看門狗定時器的可能性小于 1/7.2 ×1016.本應(yīng)用筆記介紹了安全微控制器看門狗定時器的特性和用途。
看門狗定時器的一般用途
看門狗定時器的主要應(yīng)用是作為系統(tǒng)監(jiān)視器來檢測和復(fù)位“失控”微處理器。當(dāng)程序執(zhí)行出錯時,它將無法正確執(zhí)行重新啟動看門狗的代碼。在這種情況下,看門狗定時器將超時并導(dǎo)致微控制器復(fù)位。在正確設(shè)計的系統(tǒng)中,復(fù)位將糾正錯誤。
無論看門狗定時器的功能如何,都存在無法通過復(fù)位來糾正的某些故障。例如,看門狗定時器無法防止或檢測數(shù)據(jù)存儲器的損壞。除非數(shù)據(jù)損壞影響程序流,或者采取了一些額外的措施,否則數(shù)據(jù)損壞不會導(dǎo)致監(jiān)視器超時。當(dāng)然,自診斷軟件可以編寫成這樣一種方式,即重新啟動看門狗取決于數(shù)據(jù)存儲器的驗證。雖然許多應(yīng)用程序?qū)崿F(xiàn)了此類數(shù)據(jù)驗證方案,但它超出了本文檔的范圍。
應(yīng)該記住,看門狗定時器無法立即檢測到故障。根據(jù)定義,監(jiān)視程序計時器必須達到其超時間隔的末尾,然后才能重置處理器。系統(tǒng)設(shè)計人員應(yīng)注意執(zhí)行錯誤指令和看門狗定時器復(fù)位之間可能發(fā)生的最大時間間隔。
放置重新啟動說明
在安全微控制器系列中,看門狗定時器由主系統(tǒng)時鐘驅(qū)動。超時間隔固定為 122,800 個計算機周期(1,473,600 個外部時鐘周期)。當(dāng)達到超時時,將進行重置。表1顯示了與不同晶體頻率相關(guān)的復(fù)位時間間隔。
時鐘頻率 | 超時間隔 |
16.0000兆赫 | 92 毫秒 |
14.7456兆赫 | 100 毫秒 |
11.0592兆赫 | 133 毫秒 |
7.73280兆赫 | 191 毫秒 |
5.52960兆赫 | 266 毫秒 |
1.84320兆赫 | 800 毫秒 |
主要問題是看門狗定時器復(fù)位命令(設(shè)置 RWT 位)在軟件中的位置。最理想的方法是在系統(tǒng)軟件的主回路中有一個位置,定期重新啟動看門狗計時器。通過主程序循環(huán)所需的時間必須小于超時間隔,否則設(shè)備將在正常運行期間自行復(fù)位。然而,在某些系統(tǒng)中,程序流不夠線性,無法放置單個看門狗定時器復(fù)位功能。代碼中應(yīng)放置多個復(fù)位功能,對應(yīng)于最長的軟件路徑。
通常,系統(tǒng)需要知道是否發(fā)生了看門狗定時器復(fù)位。WTR 位 (PCON.4) 將在發(fā)生這種情況時進行設(shè)置,如果發(fā)生系統(tǒng)故障,軟件可以在復(fù)位序列的早期對此進行測試。如果是這樣,系統(tǒng)可能會決定進入“安全”模式并提醒用戶注意錯誤情況。
看門狗復(fù)位示例
下面顯示了一個簡短的程序,說明了看門狗定時器的初始化和基本功能。它說明了定時訪問功能,該功能可防止意外修改看門狗控制位。定時訪問操作是必須按順序一起執(zhí)行的一系列步驟;否則,訪問將失敗。示例程序顯示了用于重新啟動監(jiān)視器并啟用其重置的定時訪問。有關(guān)定時訪問操作的更多詳細信息,請參閱安全微控制器用戶指南。受定時訪問過程保護的看門狗定時器位是使能看門狗定時器復(fù)位 (EWT;PCON.2) 并重新啟動看門狗定時器 (RWT;IP.7) 位。
; WD_RST.ASM Program ; ; This program demonstrates the use of the watchdog timer. ; When running, the program counts on port 1 to indicate the device is ; running and periodically resetting the watchdog timer. After counting ; to 16, it stops resetting the watchdog timer, simulating a system fault. ; ; The program begins by checking to see if the WTR bit is set. If so, the ; reset was caused by the watchdog timer, and the program will execute ; the FAULT subroutine. Port 1 is set to F0h to indicate this condition. ; If the WTR bit is not set, the reset was caused by another source and ; execution should continue normally. ;************************************ RWT EQU 0BFh ;Reset Watchdog Timer bit TA EQU 0C7h ;Timed Access Register PCON EQU 87h ;Power Control Register ACC EQU 0E0h ;Accumulator P1 EQU 090h ;Port 1 ORG 00h ;Reset Vector SJMP START ;************************************ ORG 080h ;Program starts at 80h in this example. START: MOV A, PCON ;If reset was caused by watchdog timeout, JB ACC.4, FAULT ; (WTR bit =1) execute fault subroutine. ;********************************** ;A normal power-on reset has occurred. Start initialization sequence. MOV P1, #00h ;Clear P1 to signal start of program. ;Watchdog timer initialization sequence MOV TA, #0AAh ;First restart the Watchdog timer MOV TA, #055h ; using timed SETB RWT ; access. MOV TA, #0AAh ;Next enable the Watchdog timer reset MOV TA, #055h ; function using timed ORL PCON, #04h ; access. ;********************************** ;Main program loop. This simulates a program that is operating ; correctly and then goes awry. After the program has counted to 16 ; on Port 1 it will skip over the watchdog timer reset function. This ; will simulate a fault and allow the watchdog timer reset to be asserted. ;********************************** MAIN: MOV R1, #0FFh ;Create a delay loop. This simulates LOOP1: MOV R2, #0FFh ; a device actually "doing something." LOOP2: JB P1.4, SKIP_WD_RST ;Have we been through loop 16 times? MOV TA, #0AAh ;Watchdog timer reset. In a user application it MOV TA, #055h ; should be placed at strategic locations SETB RWT ; where it will be executed periodically. SKIP_WD_RST: DJNZ R2, LOOP2 JNZ R1, LOOP1 INC P1 ;Increment counter. SJMP MAIN ;Go back to main program loop. ;************************************ ;Watchdog timeout fault. This subroutine would normally have special ; routines to be executed in the event of a system fault. In this example, ; it disables the watchdog reset and sets Port 1 to F0h to indicate a fault. ; In a real application, this routine could either clear the fault and ; restart the software, or signal a fault and halt further operation. ;************************************ FAULT: MOV P1, #0F0h ;Signal a fault MOV TA, #0AAh ;Disable watchdog timer reset MOV TA, #55h ; using timed ANL PCON, #0FBh ; access. SJMP $ ;Halt further operation.
總結(jié)
任何使用看門狗作為監(jiān)視器的設(shè)計都必須考慮許多因素。確定超時期限后,必須分析系統(tǒng)軟件以確定看門狗重新啟動指令的位置。為了進行有效的設(shè)計,應(yīng)將監(jiān)視程序重新啟動的次數(shù)保持在最低限度,并應(yīng)考慮錯誤執(zhí)行重新啟動的可能性。如前所述,某些系統(tǒng)軟件過于復(fù)雜或依賴于數(shù)據(jù),無法確保看門狗重新啟動涵蓋所有軟件流路徑。這可能要求可能需要自診斷軟件方法。如果存在預(yù)期的故障機制,例如周期性EMI突發(fā)或電源毛刺,則看門狗超時應(yīng)考慮此時間段。
審核編輯:郭婷
-
微控制器
+關(guān)注
關(guān)注
48文章
7724瀏覽量
152675 -
ESD
+關(guān)注
關(guān)注
49文章
2179瀏覽量
173923 -
電磁干擾
+關(guān)注
關(guān)注
36文章
2350瀏覽量
105850
發(fā)布評論請先 登錄
相關(guān)推薦
看門狗定時器硬件外設(shè)參考設(shè)計
看門狗定時器WDT是什么
內(nèi)部與外部看門狗定時器的比較
看門狗定時器的設(shè)計、工作原理及看門狗定時器的操作

看門狗定時器的作用
TB3123 - PIC?單片機的窗口看門狗定時器

什么是看門狗定時器?為何看門狗定時器如此重要?

PCB設(shè)計技巧:您是否應(yīng)在電路板設(shè)計中包含外部看門狗定時器?
LPC2294看門狗定時器

MSP430學(xué)習(xí)筆記(三)--起步看門狗

看門狗定時器電路的功能和操作及局限性解決方案

評論