MSP430 MCU Example 15 - Watchdog Timer Timing Application
[Copy link]
1. Task requirements
Use the watchdog timer of the MSP30F247 microcontroller to generate a set time interval interrupt, and switch the LED light on and off in the interrupt service program, turning it on for 1S and off for 1S.
2. Analysis and explanation
The watchdog timer has only two clock sources: ACLK and SMCLK, with 4 frequency division values, and can only implement a few simple timer interval interrupts.
3. Hardware Circuit
Select P4.1 of MSP430F247 microcontroller to connect an LED light, and use a virtual oscilloscope to observe the pin level change frequency. The low-frequency crystal oscillator uses a 32768Hz crystal oscillator to obtain a stable ACLK clock. XT2 is connected to an 8MHz crystal oscillator, and two 22pF matching capacitors are used to supply MCLK and SMCLK clocks. The tube voltage drop of a general light-emitting diode is about 1.8~2.2V, and the current is 5~10mA. In this example, the current limiting resistor is selected as 300 ohms. .
4. Programming
#include "msp430f247.h"
#include "stdlib.h"
#include "string.h"
/************************************************Software delay, main frequency 1M*******************/
#define CPU_F1 ((double)1000000)
#define delay_us1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000000.0))
#define delay_ms1M(x) __delay_cycles((long)(CPU_F1*(double)x/1000.0))
/****************************************************** ***************************/
/************************************************
Function name: main function
Function: Watchdog timer application
Entry parameters: None
Export parameters: None
************************************************/
main()
{
//WDTCTL = WDT_MDLY_32;
WDTCTL=WDT_ADLY_1000;;//Watchdog timing time interval 1S
_EINT();
IE1 |= WDTIE; //Enable WDT interrupt
P4DIR=0x01; //P4.0 output
while(1)
{
_BIS_SR(LPM3_bits); //Enter LPM3 low power mode, total interrupts are enabled
_NOP();
}
}
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer(void) //watchdog interrupt service routine
{
P4OUT ^= 0x01; //P4.0 output inverted
_NOP();
}
5. Program Description
The watchdog timer clock source selects ACLK, and the frequency division factor is 32768, so the timing time interval is 1S. P4.0 is set to output mode, and the main loop enters LPM3 low power mode.
Pay attention to setting the frequency of the ACLK clock in the properties of the microcontroller.
|