//*****************************************************************************
// MSP-FET430P410 Demo - SD16, Single Conversion on a Group of Channels
//
// Description: This program uses the SD16 module to perform a single
// conversion on a group of channels (0, 1, and 2). A SD16 interrupt occurs
// when the conversions have completed. Test by applying voltages to the
// three input channels and setting a breakpoint at the line indicated
// below. Run program until it reaches the breakpoint, then use the
// debugger's watch window to view the conversion results. Results for all
// three channels are stored in the array "results". NOTE: array won't
// contain values until after reaching breakpoint for the second time.
// ACLK = LFXT1 = 32768 Hz, MCLK = SMCLK = DCO = 32 x ACLK = 1048576 Hz
// //* An external watch crystal on XIN XOUT is required for ACLK *//
// //* Minimum Vcc is required for SD16 module - see datasheet *//
// //* 100nF cap btw Vref and AVss is recommended when using 1.2V ref *//
//
// MSP430F427
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|RST XOUT|-
// | |
// Vin1+ -->|A0.0+ |
// Vin1- -->|A0.0- |
// Vin2+ -->|A1.0+ |
// Vin2- -->|A1.0- |
// Vin3+ -->|A2.0+ |
// Vin3- -->|A2.0- |
// | |
// | VREF |---+
// | | |
// | | -+- 100nF
// | | -+-
// | | |
// | AVss |---+
// | |
//
// H. Grewal
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//*****************************************************************************
#include <msp430x42x.h>
/* Array to store SD16 conversion results */
/* NOTE: array needs to be global to */
/* prevent removal by compiler */
static unsigned int results[3];
float vt1,vt0,pr1,pr0,temperature1,temperature0;
static float pt1000[202]={1000,1001.954,1003.908,1005.861,1007.814,1009.767,1011.72,1013.672,1015.624,1017.576,
1019.527,1021.478,1023.429,1025.38,1027.33,1029.28,1031.229,1033.179,1035.128,1037.077,
1039.025,1040.973,1042.921,1044.869,1046.816,1048.764,1050.71,1052.657,1054.603,1056.549,
1058.495,1060.44,1062.385,1064.33,1066.274,1068.218,1070.162,1072.106,1074.049,1075.992,
1077.935,1079.877,1081.82,1083.762,1085.703,1087.644,1089.585,1091.526,1093.467,1095.407,
1097.347,1099.286,1101.225,1103.164,1105.103,1107.042,1108.98,1110.917,1112.855,1114.792,
1116.729,1118.666,1120.602,1122.538,1124.474,1126.41,1128.345,1130.28,1132.215,1134.149,
1136.083,1138.017,1139.95,1141.884,1143.817,1145.749,1147.681,1149.614,1151.545,1153.477,
1155.408,1157.339,1159.27,1161.2,1163.13,1165.06,1166.989,1168.918,1170.847,1172.776,
1174.704,1176.632,1178.56,1180.487,1182.414,1184.341,1186.268,1188.194,1190.12,1192.046,
1193.971,1195.896,1197.821,1199.746,1201.67,1203.594,1205.518,1207.441,1209.364,1211.287,
1213.21,1215.12,1217.054,1218.975,1220.897,1222.818,1224.739,1226.659,1228.579,1230.499,
1232.419,1234.338,1236.257,1238.176,1240.095,1242.03,1243.931,1245.848,1247.766,1249.683,
1251.6,1253.516,1255.432,1257.348,1259.264,1261.179,1263.094,1265.009,1266.923,1268.837,
1270.751,1272.665,1274.578,1275.141,1278.404,1280.316,1282.228,1284.14,1286.052,1287.963,
1289.874,1291.785,1293.695,1295.605,1297.515,1299.425,1301.334,1303.243,1305.152,1307.06,
1308.968,1310.876,1312.783,1314.691,1316.597,1318.504,1320.411,1322.316,1324.222,1326.128,
1328.033,1329.938,1331.843,1333.747,1335.651,1337.555,1339.458,1321.361,1343.264,1345.167,
1347.069,1348.971,1350.873,1352.774,1354.676,1356.577,1358.477,1360.377,1362.277,1364.177,
1366.077,1367.976,1369.875,1371.773,1373.671,1375.569,1377.467,1379.365,1381.262,1383.158,
1385.055,1386.951};
void main(void)
{
volatile unsigned int i; // Use volatile to prevent removal
// by compiler optimization
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FLL_CTL0 |= XCAP14PF; // Configure load caps
for (i = 0; i < 10000; i++); // Delay for 32 kHz crystal to
// stabilize
SD16CTL = SD16REFON+SD16SSEL0+SD16VMIDON; // 1.2V ref, SMCLK
SD16CCTL0 = SD16SNGL+SD16GRP; // Single conv, group with CH1
SD16CCTL1 = SD16SNGL+SD16GRP; // Single conv, group with CH2
SD16CCTL2 = SD16SNGL+SD16IE; // Single conv, enable interrupt
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup
_EINT(); // Enable general interrupts
while (1)
{
SD16CCTL2 |= SD16SC; // SET BREAKPOINT HERE
// Set bit to start conversion
/* //test
i=100;
pr0=pt1000[i];*/
_BIS_SR(LPM0_bits); // Enter LPM0
}
}
#pragma vector=SD16_VECTOR
__interrupt void SD16ISR(void)
{
float mid_num;
unsigned char i;
switch (SD16IV)
{
case 2: // SD16MEM Overflow
break;
case 4: // SD16MEM0 IFG
break;
case 6: // SD16MEM1 IFG
break;
case 8: // SD16MEM2 IFG
results[0] = SD16MEM0; // Save CH0 results (clears IFG)
results[1] = SD16MEM1; // Save CH1 results (clears IFG)
results[2] = SD16MEM2; // Save CH2 results (clears IFG)
//vt1=(float)(results[1]+40)/65536*1.2-0.6;
//vt0=(float)(results[0]+40)/65536*1.2-0.6;
//pr1=1508.1*vt1/(1.2-vt1);
//pr0=1495*vt0/(1.2-vt0);
pr1=(results[1]-32768)*1515.0/(98304-results[1]);
pr0=(results[0]-32768)*1501.8/(98304-results[0]);
if(pr1>1174.704){//高于45度时的处理
pr1=(results[1]-32768)*1511.6/(98304-results[1]);
}
if(pr0>1174.704){
pr0=(results[0]-32768)*1499.4/(98304-results[0]);
}
if(pr1<1039.025){//低于10度时的处理
pr1=(results[1]-32768)*1525.3/(98304-results[1]);
}
if(pr0<1039.025){
pr0=(results[0]-32768)*1513.8/(98304-results[0]);
}
if(1039.025<pr0<1077.935){
pr0=(results[0]-32768)*1504.6/(98304-results[0]);
}
if(1039.025<pr1<1077.935){
pr1=(results[1]-32768)*1516.9/(98304-results[1]);
}
break;
}
for(i=0;i<=201;i++){
if(pr1<pt1000[i]){
mid_num=(pt1000[i]+pt1000[i-1])/2;
if(pr1<mid_num)
temperature1=0.5*(i-1);
else
temperature1=0.5*i;
break;
}
}
for(i=0;i<=201;i++){
if(pr0<pt1000[i]){
mid_num=(pt1000[i]+pt1000[i-1])/2;
if(pr0<mid_num)
temperature0=0.5*(i-1);
else
temperature0=0.5*i;
break;
}
}
_BIC_SR_IRQ(LPM0_bits); // Exit LPM0
}
评论3
最新资源