130 likes | 258 Views
ECE 447 Fall 2009. Lecture 13: TI MSP430 Watchdog Timer and Real-Time Clock. ECE447: MSP430 Watchdog Timer Concept.
E N D
ECE 447 Fall 2009 Lecture 13: TI MSP430 Watchdog Timer and Real-Time Clock
ECE447: MSP430 Watchdog Timer Concept • A watchdog timer (or computer operating properly timer) is a hardware timing device that triggers a system reset if the main program, due to some fault condition, such as a hang, neglects to regularly service the watchdog.
ECE447: Use Cases for Watchdog Timer • Out of Control Software: • Trapped in infinite loop • Code/Memory overwrite • Peripheral Failure: • Polling a non responsive device • SW controlled reset: • The WDT register can be used to force a reset purposely
ECE 447: Enabling and Disabling the WDT • The WDT is always active after a reset • Default settings allow the software about 32ms to clear, stop, or reconfigure the WDT at startup. • Up until now we have always stopped the WDT by setting the WDT-HOLD bit.
ECE447: Petting the Watchdog • Petting is performed by writing to the WDT-CNTCL bit. • All writes to the WDT register are protected by a 8 bit password. • 0x5A must be the upper byte value of any write to the WDTCTL register • Any other value will cause an immediate reset.
ECE447: MSP430 Basic Timer1 • Basic Timer 1 provides two or three fucntions in the MSP430: • Clock for the LCD module • Periodic Interrupts • 1Hz clock signal to drive the Real-Time Clock • The RTC only exists in newer MSP430xFxx family devices.
ECE447: MSP430 Basic Timer1 • BTCNT1 and BTCNT2 count based on control bits in BTFRQx and BTIPx. • BTCNT2 causes the BTIFG flasg to be set at each rollover, with a rame from 16ms to 2s.
ECE447: MSP430 Real Timer Clock Concept • A Real-Time Clock (RTC) is a hardware device that counts time based on seconds, minutes, hours, days, months, and year. • Unlike most clocks in a microcontroller that do not convey useful data directly, the RTC is directly human understandable.
ECE447: MSP430 Real Timer Clock Concept • The current time and date are held in a set of registers that contain the following bytes: • Second (RTCSEC) • Minute (RTCMIN) • Hour (RTCHOUR), which runs from 0-23 (24-hour format) • Day of week (RTCDOW), which runs from 0-6 • Day of month (RTCDAY) • Month (RTCMON) • Year (RTCYEARL), assuming BCD format • Century (RTCYEARH), assuming BCD format.
ECE447: MSP430 Real Timer Clock Data Registers • The RTC is controlled by the RTCCTL • It is initially disabled at reset (RTCHOLD is set) • It can store its data registers in BCD or unsigned binary numbers (RTCBDC) • Care should be taken in reading the RTC, see Davies p286.
ECE447: MSP430 Real Timer Clock Data Registers • The Real-Time Clock has an interrupt flag RTCFG and corresponding enable bit RTCIE inRTCCTL. • The flag is set every minute, every hour, daily at midnight, or daily at noondepending on the RTCTEVx bits. • There is no alarm interrupt function, this must be implemented in software if desired.
ECE447: MSP430 Class Exercise Write a C program that sets up the RTC and sets the date to today, 18:00:00, and starts the time displaying on the Hitachi LCD module attached to P1 (4-bit mode) The time will be displayed in 24hr format with hours, minutes, and seconds. The output should be updated any time that the corresponding values are updated in the RTC registers.