{
EALLOW;
AdcaRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdcaRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iu;
AdcaRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iu;
AdcaRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iu;
}
else
{
AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iu);
AdcaRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iu);
AdcaRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iu);
}
//============================================================
AdccRegs.ADCPPB1CONFIG.bit.CONFIG = 0x0000;
AdccRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdccRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iv;
AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iv;
AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iv;
}
else
{
AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iv);
AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iv);
AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iv);
}
//============================================================
AdcdRegs.ADCPPB1CONFIG.bit.CONFIG = 0x0000;
AdcdRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdcdRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdcdRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iw;
AdcdRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iw;
AdcdRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iw;
}
else
{
AdcdRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iw);
AdcdRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iw);
AdcdRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iw);
}
}
user5233622:
EALLOW;
AdccRegs.ADCPPB1CONFIG.bit.CONFIG = 0; AdccRegs.ADCPPB2CONFIG.bit.CONFIG = 1; AdccRegs.ADCPPB3CONFIG.bit.CONFIG = 2; AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0; AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0; AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0; AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = offcal_Iv; AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = offcal_Iv; AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = offcal_Iv;
EDIS;
上述为PPB设置程序,无论将哪一个PPB分配给SOC0,也就是CONFIG = 0,SOC0得出结果都没有进行偏移校正,其他两个PPB工作正常,实在搞不懂,希望得到解答
{
EALLOW;
AdcaRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdcaRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iu;
AdcaRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iu;
AdcaRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iu;
}
else
{
AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iu);
AdcaRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iu);
AdcaRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iu);
}
//============================================================
AdccRegs.ADCPPB1CONFIG.bit.CONFIG = 0x0000;
AdccRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdccRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iv;
AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iv;
AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iv;
}
else
{
AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iv);
AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iv);
AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iv);
}
//============================================================
AdcdRegs.ADCPPB1CONFIG.bit.CONFIG = 0x0000;
AdcdRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdcdRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdcdRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iw;
AdcdRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iw;
AdcdRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iw;
}
else
{
AdcdRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iw);
AdcdRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iw);
AdcdRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iw);
}
}
user5233622:
回复 Green Deng:
还有个问题想请教一下,我程序内将2048当作零,得出差值将差值输入OFFCAL。当差值大于五百左右时PPB的计算结果就错误了。
比如:此时ADC实际采样值为2570,差值为2570-2048 = 522,将结果输入OFFCAL,TWOSCOMPEN选0,最终运算结果却为3074。而如果差值小一些就能正常工作,结果归为2048附近。麻烦帮忙分析一下,谢谢
{
EALLOW;
AdcaRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdcaRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdcaRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iu;
AdcaRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iu;
AdcaRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iu;
}
else
{
AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdcaRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iu);
AdcaRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iu);
AdcaRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iu);
}
//============================================================
AdccRegs.ADCPPB1CONFIG.bit.CONFIG = 0x0000;
AdccRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdccRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iv;
AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iv;
AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iv;
}
else
{
AdccRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdccRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iv);
AdccRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iv);
AdccRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iv);
}
//============================================================
AdcdRegs.ADCPPB1CONFIG.bit.CONFIG = 0x0000;
AdcdRegs.ADCPPB2CONFIG.bit.CONFIG = 0x0001;
AdcdRegs.ADCPPB3CONFIG.bit.CONFIG = 0x0010;
if(offset_Iu >= 0)
{
AdcdRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 0;
AdcdRegs.ADCPPB1OFFCAL.bit.OFFCAL = offset_Iw;
AdcdRegs.ADCPPB2OFFCAL.bit.OFFCAL = offset_Iw;
AdcdRegs.ADCPPB3OFFCAL.bit.OFFCAL = offset_Iw;
}
else
{
AdcdRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB3CONFIG.bit.TWOSCOMPEN = 1;
AdcdRegs.ADCPPB1OFFCAL.bit.OFFCAL = -(offset_Iw);
AdcdRegs.ADCPPB2OFFCAL.bit.OFFCAL = -(offset_Iw);
AdcdRegs.ADCPPB3OFFCAL.bit.OFFCAL = -(offset_Iw);
}
}
user5233622:
回复 Green Deng:
做了一下特殊实验差值不由计算决定,实际AD值为2645,OFFCAL写入400时ADCRESULT结果可运算为2245,OFFCAL写入600时ADCRESULT结果运算为3074