芯片:MSP430FR6972
问题描述:
通过运放电路处理罗氏线圈出来的正弦信号,然后通过单片机自带的ADC采集出来,然后将采集到的信号先计算平均值(为了计算参考电压分量),然后采样值减参考分量后计算均方根值。
计算时发现计算的均方根值总是出现波动,导致精度一直难以满足。因此想请教一下,问题出在哪部分?
看波形挺好的呀!是不是参考不准导致的呀,因为测量发现1.25V参考(芯片REF3312),有时是1.24,1.26,1.25。
相关程序;
void Sample_Calculate(void)
{
uint8_t i = 0;
int16_t actual_val = 0; //实际采样电压编码值(有符号)
uint32_t result_temp = 0; //缓存乘法器计算值
uint16_t current_avg = 0; //电流平均值
uint32_t current_sum = 0; //存放电流和
uint16_t c_act_rms; //电流裸数值
/* 求平均 */
for(i=0; i<20; i++)
{
current_sum += Indicator_Status.Sample_Current[Indicator_Status.Calculate_Node][i];
}
current_avg = current_sum / 20;
current_sum=0;
/* 开方 */
for(i=0; i<20; i++)
{
actual_val = Indicator_Status.Sample_Current[Indicator_Status.Calculate_Node][i] - current_avg;
MPYS = actual_val;
OP2 = actual_val;
//_NOP();_NOP();_NOP();
result_temp = RESHI;
result_temp <<= 16;
result_temp |= RESLO;
current_sum += result_temp;
}
c_act_rms = sqrt2(current_sum); //未校正电流裸数值
Indicator_Status.Current_RMS=RMS_Correction(c_act_rms); //电流校正
}
相关电路图:
相关波形: