This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F636 SD24B 采集电压

请问,怎么把寄存器MEMH和MEML中的数据转换成真实电压?以下是我的代码:

//*****************************************************************************
#include <msp430.h>
#include <math.h>

/* Array to store SD24 conversion results */
int results[4];
double v0,tempCH0,VoltageCH0;
#define sampleCount0 4096
#define sampleCount1 4096
float Kv0=1413.92;

void main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT

SD24BCTL0 = SD24REFS | SD24SSEL_1; // Select internal REF
// Select SMCLK as SD24_B clock source

SD24BCCTL0 = SD24SNGL | SD24SCS_4; // Single conversion, group 0
SD24BCCTL1 = SD24SNGL | SD24SCS_4; // Single conversion, group 0

SD24BIE = SD24IE1; // Enable channel 1 interrupt

__delay_cycles(0x3600); // Delay for 1.5V REF startup

while (1)
{
SD24BCTL1 |= SD24GRP0SC; // Set bit to start conversion
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0 w/ interrupts
SD24BCTL1 &= ~SD24GRP0SC; // Clear bit for next conversion
__no_operation(); // SET BREAKPOINT HERE
}
}

#pragma vector=SD24B_VECTOR
__interrupt void SD24BISR(void)
{
static int countCH0=0;
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
results[0] = SD24BMEMH0; // Save CH0 results (clears IFG)
results[1] = SD24BMEML0; // Save CH0 results (clears IFG)
results[2] = SD24BMEMH1; // Save CH1 results (clears IFG)
results[3] = SD24BMEML1; // Save CH0 results (clears IFG)
v0=(results[0]<<16+results[1])*1.153/0x1000000;
tempCH0+=pow(v0,2);
//tempCH0+=v0;
countCH0++;
if(countCH0==sampleCount0)
//{VoltageCH0=Kv0*tempCH0/sampleCount0;tempCH0=0;countCH0=0;}
{VoltageCH0=Kv0*(sqrt(tempCH0/sampleCount0)-0.000463363714);tempCH0=0;countCH0=0;}
break;
case SD24BIV_SD24IFG2: // SD24MEM2 IFG
break;
}

__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}

存在的问题:以0.4V 50Hz的交流电设置Kv0值来校准,改变输入幅值,电压测得值不准

  • 寄存器MEMH和MEML中的数据转换成真实电压,和你的电路有关系的

  • 我是参照TI给的一个文档里的原理图,直接将输入电压接到SD0P0、SD0N0,参考电压是内部参考电压1.2V,请问这种情况下是怎么计算实际电压?谢啦!

x 出现错误。请重试或与管理员联系。