📄 scan if main.c
字号:
//*****************************************************************************
//
// MSP-FET430P140 FET Board equipped with MSP430FW42x, with daughtercard
// equipped with two GMR sensors
//
// Description; Detect rotation of a disc using the Scan IF module of the 'FW.
// Rotation is indicated using four LEDs that cycle a binary
// count for each half-rotation.
//
// Note: When using the daughtercard with the MSP-FETP140 remove jumper J6.
//
//
// MSP430FW42x
// -----------------
// /|\| XIN|-
// | | | 32.768kHz
// --|RST XOUT|-
// | |
// | P6.4|-->LED 1
// GMR1-->|SIFCH0 |
// | P6.5|-->LED 2
// GMR2-->|SIFCH1 |
// | P6.6|-->LED 3
// | |
// | P6.7|-->LED 4
//
// K. Quiring
// Texas Instruments, Inc
// August 2006
//
// Based on code written for LC sensors, by C. Hernitscheck / Z. Albus
//*****************************************************************************
#include "msp430xw42x.h"
extern void InitScanIF(void);
extern void SIFCalib(void);
const unsigned char PSM[] = {
0x00, // No rotation
0x41, // Error
0x0A, // Next step counter-clockwise (+1)
0x49, // Error
0x00, // Next step counter-clockwise
0x01, // No rotation
0x48, // Error
0x49, // Error
0x10, // Next step counter-clockwise
0x41, // Error
0x08, // No rotation
0x49, // Error
0x40, // Error
0x41, // Error
0x48, // Error
0x49, // Error
0x10, // No rotation
0x01, // Next step counter-clockwise
0x48, // Error
0x49 // Error
};
volatile unsigned int i,j,k;
// Storage used in PSM state tracking function
char v=1,w=0,x=0,y=0,z=0;
char stateList[0x300];
int stateListIndex = 0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Disable Watchdog
FLL_CTL0 |= XCAP18PF; // Configure load caps
while(FLL_CTL0 & LFOF); // Wait until LF OSC stabilizes
P1DIR = 0xFF; // Configure unused outputs
P2DIR = 0xFF; // Configure unused outputs
P3DIR = 0xFF; // Configure unused outputs
P4DIR = 0xFF; // Configure unused outputs
P5DIR = 0xFC; // Configure unused outputs
P6OUT = 0x00; // P6.4-6.7 drive LEDs
P6DIR = 0xF0; // P6.4-6.7 drive LEDs
P6SEL |= 0x03; // Activate SIFCH0/1 (P6.0/1)
SIFCalib(); // Calibration of DAC thresholds
// Flash LEDs to signal end of calibration. When
// the lights go out, S2/S1 outputs need to read "00"
P6OUT = 0x00;
for(j=0x07;j>0;j--)
for(i=0x3FFF;i>0;i--);
for(k=0x04;k>0;k--)
{
P6OUT = 0xF0;
for(j=0x03;j>0;j--)
for(i=0x27FF;i>0;i--);
P6OUT = 0x00;
for(j=0x03;j>0;j--)
for(i=0x27FF;i>0;i--);
}
InitScanIF(); // Initialization of ScanIf module
_EINT();
// In normal operation, the code would be configured to enter LPM3. During
// debug, the PSM tracking function below can be used to track PSM state
// transitions. This can reveal problems in the PSM, as well as identify the
// specific S2/S1 transition that occurred before any error. If the LPM3
// line below is commented out, the tracking function will run continuously
// during SIF operation. If uncommented, the device will enter LPM3 and
// execution will not reach the tracking function.
_BIS_SR(LPM3_bits + GIE); // Leave uncommented if not
// tracking PSM
// Loop endlessly, capturing all PSM state transitions to array stateList[].
// Runs about every 12us.
SIFDEBUG = 0x0000;
while(1)
{
w = v;
v = (char) SIFDEBUG & 0x00FF;
if(!(v==w))
{
stateList[stateListIndex++] = v;
if (stateListIndex > 0x2FF) //In case stateList runs past 0x2FF
stateListIndex = 0;
}
}
} // End Main
#pragma vector=SCANIF_VECTOR
__interrupt void ISR_ScanIF(void)
{
if(SIFCTL1&SIFIFG3)
{
P6OUT = SIFCNT << 4; // Display LSBs with LEDs
SIFCTL1 &= ~0x0060;
}
if(SIFCTL1&SIFIFG5)
SIFCTL1 &= ~SIFIFG5; // Breakpoint here to catch errors
if((SIFCTL1&SIFIE1)&&(SIFCTL1&SIFIFG1))
{
SIFCTL1 &= ~SIFIFG1;
_BIC_SR_IRQ(LPM3_bits); // Exit LPM3 after reti
}
}
void InitScanIF(void)
{
// Use the same TSM that was defined in SIFCalib(), so no settings made here
SIFCTL4 = SIFCNT1ENP+SIFDIV3_14; // CNT1 incr enabled, no decr;
// SIFCLK = ACLK/14
SIFPSMV = (unsigned int) &PSM; // Initialize PSM for main operation
SIFCTL1 = SIFIE5+SIFIE3+SIFEN; // SIF_EN=1; int on cntr incr and on err
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -