void Init_SD24_B(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
SD24BCTL0 = SD24REFS | SD24SSEL_1; // Select internal REF
// Select SMCLK as SD24_B clock source —-8M
SD24BCCTL0 = SD24SNGL | SD24SCS_4; // Single conversion, group 0
SD24BCCTL1 = SD24SNGL | SD24SCS_4; // Left-aligned, group 0
SD24BIE = SD24IE1; // Enable channel 1 interrupt
__delay_cycles(0x3600);
SD24BCTL1 |= SD24GRP0SC; // Set bit to start conversion
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=SD24B_VECTOR
__interrupt void SD24BISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(SD24B_VECTOR))) SD24BISR (void)
#else
#error Compiler not supported!
#endif
{
switch (SD24BIV)
{
case SD24BIV_SD24OVIFG: // SD24MEM Overflow
break;
case SD24BIV_SD24TRGIFG: // SD24 Trigger IFG
break;
case SD24BIV_SD24IFG0: // SD24MEM0 IFG
break;
case SD24BIV_SD24IFG1: // SD24MEM1 IFG
results1 = SD24BMEMH0; // Save CH0 results (clears IFG)
results1 = results1<<16; // Save CH0 results (clears IFG)
results1 |= SD24BMEML0; // Save CH0 results (clears IFG)
valt1 = ((results1-8388608)*75)>>19;
printf("a %d ",valt1);
results2 = SD24BMEMH1; // Save CH1 results (clears IFG)
results2 = results2<<16; // Save CH1 results (clears IFG)
results2 |= SD24BMEML1; // Save CH1 results (clears IFG)
valt2 = ((results2-8388608)*75)>>19; // printf("b %d\n ",valt2);
SD24BCTL1 &= ~SD24GRP0SC; // Clear bit for next conversion
break;
default:break; }
}
请教一下,MSP430F6726的SD24_B的电压值转换公式是不是 ((SD24BMEMH1<<16)|SD24BMEML1)*1.2/2^24?但
我算出的值和测量值差很多,而用上面别的公式就很准,但是我没看懂他的公式是怎么来的
灰小子:
没仔细翻手册。看公式,1.2应该是基准电压,括号内是采样值,公式就是采样值/2^24*基准电压,很容易理解了吧?
TONG PANG:
回复 灰小子:
dirtwillfly
没仔细翻手册。看公式,1.2应该是基准电压,括号内是采样值,公式就是采样值/2^24*基准电压,很容易理解了吧?