2208 views|0 replies

3836

Posts

19

Resources
The OP
 

Common usage of MSP430 watchdog and writing method of interrupt function [Copy link]

I looked at the basic usage of the MSP430 watchdog

The watchdog is set to prevent the program from running away, but since the watchdog is similar to a timer, it can be used as a timer.

Example Code: Blink an LED with the Watchdog Timer


#include <msp430x14x.h>
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDT_MDLY_32; //macro definition
IE1 |= WDTIE; //allow watchdog timer interrupt
P2DIR |= BIT7;

_BIS_SR(LPM0_bits+GIE); //here puts the CPU into low power mode

}

#pragma vector = WDT_VECTOR
__interrupt void watchdag_timer(void)
{
P2OUT ^=BIT7; // XOR operation is basically the inversion operation
}

Note that there is a better macro definition here: WDTCTL = WDT_MDLY_32; enter the macro definition and you will find many similar macro definitions


/* WDT-interval times [1ms] coded with Bits 0-2 */
/* WDT is clocked by fSMCLK (assumed 1MHz) */
#define WDT_MDLY_32 (WDTPW+WDTTMSEL+WDTCNTCL) /* 32ms interval (default) */
# WDT_MDLY_8 (WDTPW+WDTTMSEL+WDTCNTCL+WDTIS0) /* 8ms " */
#define WDT_MDLY_0_5 (WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1) /* 0.5ms " */
#define WDT_MDLY_0_064 (WDTPW+WDTTMSEL+WDTCNTCL+WDTIS1+WDTIS0) define /* 0.064ms " */
/* WDT is clocked by fACLK (assumed 32KHz) */
#define WDT_ADLY_1000 (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL) /* 1000ms " */
#define WDT_ADLY_250 (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS0) /* 250ms " */
#define WDT_ADLY_16 (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1 ) /* 16ms " */
#define WDT_ADLY_1_9 (WDTPW+WDTTMSEL+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0) /* 1.9ms " */
/* Watchdog mode -> reset after expired time */
/* WDT is clocked by fSMCLK (assumed 1MHz) */
#define WDT_MRST_32 (WDTPW+WDTCNTCL) /* 32ms interval (default) */
#define WDT_MRST_8 (WDTPW+WDTCNTCL+WDTIS0) /* 8ms " */
#define WDT_MRST_0_5 (WDTPW+WDTCNTCL+WDTIS1) /* 0.5ms " */
#define WDT_MRST_0_064 (WDTPW+WDTCNTCL+WDTIS1+ WDTIS0) /* 0.064ms " */
/* WDT is clocked by fACLK (assumed 32KHz) */
#define WDT_ARST_1000 (WDTPW+WDTCNTCL+WDTSSEL) /* 1000ms " */
#define WDT_ARST_250 (WDTPW+WDTCNTCL+WDTSSEL+WDTIS0) /* 250ms " */
#define WDT_ARST_16 (WDTPW+WDTCNTCL+WDTSSEL+WDTIS1) /* 16ms " */
#define WDT_ARST_1_9 (WDTPW+WDTCNTCL+WDTSSEL+WDTIS1+WDTIS0) /* 1.9ms " */ Here we can choose

the appropriate timing time according to the usual needs.
When it comes to the timing time, we have to talk about the interrupt function. In the IAR compilation environment, the general interrupt function is written as

#pragma vector = interrupt vector__interrupt
void interrupt function name (void)
{
user program;
}

Note that the interrupt vector can be found in the header file of 430. The declaration of the interrupt function must be void interrupt function name (void). This is because the interrupt function has no return value and no formal parameters for the interrupt.

However, I saw another way of writing it on the website using switch, where one interrupt source corresponds to several interrupt vectors. I have not seen the source code for this method yet, so it is difficult to summarize.

This post is from Microcontroller MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list