我在AD采样中断中把采样结果放到一个数组中,数组长度为4 然后在100us的定时器中把这4个采样结果求平均值,再*3 /4096,算成真实值。 对9路AD采样进行同样的操作。我直接计算的话需要是78us,用IQmath去计算为什么时间还要跟就呢 大概80us ,求教大神这是为什么呢?因为我是想测试IQmath所以没有用CLA
直接计算程序:
void claculat_adc(void)
{
Sum1=((float)(ADbuffVaca[0]+ADbuffVaca[1]+ADbuffVaca[2]+ADbuffVaca[3]))/4;
Sum2=((float)(ADbuffVacb[0]+ADbuffVacb[1]+ADbuffVacb[2]+ADbuffVacb[3]))/4;
Sum3=((float)(ADbuffVacc[0]+ADbuffVacc[1]+ADbuffVacc[2]+ADbuffVacc[3]))/4;
Sum4=((float)(ADbuffIaca[0]+ADbuffIaca[1]+ADbuffIaca[2]+ADbuffIaca[3]))/4;
Sum5=((float)(ADbuffIacb[0]+ADbuffIacb[1]+ADbuffIacb[2]+ADbuffIacb[3]))/4;
Sum6=((float)(ADbuffIacc[0]+ADbuffIacc[1]+ADbuffIacc[2]+ADbuffIacc[3]))/4;
Sum7=((float)(ADbuffVdc1[0]+ADbuffVdc1[1]+ADbuffVdc1[2]+ADbuffVdc1[3]))/4;
Sum8=((float)(ADbuffVdc2[0]+ADbuffVdc2[1]+ADbuffVdc2[2]+ADbuffVdc2[3]))/4;
Sum9=((float)(ADbuffTemp[0]+ADbuffTemp[1]+ADbuffTemp[2]+ADbuffTemp[3]))/4;
buff=Sum1*3/4096; // *3/4096
Val_adc_test[0]=(buff-ADC_OFFSET_UAC)*ADC_GAIN_UAC;
buff=Sum2*3/4096; // *3/4096
Val_adc_test[1]=(buff-ADC_OFFSET_UAC)*ADC_GAIN_UAC;
buff=Sum3*3/4096; // *3/4096
Val_adc_test[2]=(buff-ADC_OFFSET_UAC)*ADC_GAIN_UAC;
buff=Sum4*3/4096; // *3/4096
Val_adc_test[3]=(buff-ADC_OFFSET_IAC)*ADC_GAIN_IAC;
buff=Sum5*3/4096; // *3/4096
Val_adc_test[4]=(buff-ADC_OFFSET_IAC)*ADC_GAIN_IAC;
buff=Sum6*3/4096; // *3/4096
Val_adc_test[5]=(buff-ADC_OFFSET_IAC)*ADC_GAIN_IAC;
buff=Sum7*3/4096; // *3/4096
Val_adc_test[6]=buff*ADC_GAIN_UDC;
buff=Sum8*3/4096; // *3/4096
Val_adc_test[7]=buff*ADC_GAIN_UDC;
buff=Sum9*3/4096; // *3/4096
Val_adc_test[8]=((buff-0.5)*100);
}
采样IQmath的方法
void claculat_adc(void)
{
Sum1=(float)(ADbuffVaca[0]+ADbuffVaca[1]+ADbuffVaca[2]+ADbuffVaca[3]);
AdValue_avr=_IQdiv(_IQ(Sum1),_IQ(4.0)); //平均值
buff= _IQdiv(_IQmpy(_IQ(Sum1),_IQ(3.0)),_IQ(4096.0)); // *3/4096 AD_value.Ua=_IQmpy((buff-_IQ(ADC_OFFSET_UAC)),_IQ(ADC_GAIN_UAC));
Sum2=((float)(ADbuffVacb[0]+ADbuffVacb[1]+ADbuffVacb[2]+ADbuffVacb[3]));
AdValue_avr=_IQdiv(_IQ(Sum2),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ub=_IQmpy((buff-_IQ(ADC_OFFSET_UAC)),_IQ(ADC_GAIN_UAC));
Sum3=((float)(ADbuffVacc[0]+ADbuffVacc[1]+ADbuffVacc[2]+ADbuffVacc[3]));
AdValue_avr=_IQdiv(_IQ(Sum3),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Uc=_IQmpy((buff-_IQ(ADC_OFFSET_UAC)),_IQ(ADC_GAIN_UAC));
Sum4=((float)(ADbuffIaca[0]+ADbuffIaca[1]+ADbuffIaca[2]+ADbuffIaca[3]));
AdValue_avr=_IQdiv(_IQ(Sum4),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ia=_IQmpy((buff-_IQ(ADC_OFFSET_IAC)),_IQ(ADC_GAIN_IAC));
Sum5=((float)(ADbuffIacb[0]+ADbuffIacb[1]+ADbuffIacb[2]+ADbuffIacb[3]));
AdValue_avr=_IQdiv(_IQ(Sum5),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ib=_IQmpy((buff-_IQ(ADC_OFFSET_IAC)),_IQ(ADC_GAIN_IAC));
Sum6=((float)(ADbuffIacc[0]+ADbuffIacc[1]+ADbuffIacc[2]+ADbuffIacc[3]));
AdValue_avr=_IQdiv(_IQ(Sum6),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ic=_IQmpy((buff-_IQ(ADC_OFFSET_IAC)),_IQ(ADC_GAIN_IAC));
Sum7=((float)(ADbuffVdc1[0]+ADbuffVdc1[1]+ADbuffVdc1[2]+ADbuffVdc1[3])); AdValue_avr=_IQdiv(_IQ(Sum7),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Udc1=_IQmpy((buff),_IQ(ADC_GAIN_UDC));
Sum8=((float)(ADbuffVdc2[0]+ADbuffVdc2[1]+ADbuffVdc2[2]+ADbuffVdc2[3]));
AdValue_avr=_IQdiv(_IQ(Sum8),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Udc2=_IQmpy((buff),_IQ(ADC_GAIN_UDC));
Sum9=((float)(ADbuffTemp[0]+ADbuffTemp[1]+ADbuffTemp[2]+ADbuffTemp[3]));
AdValue_avr=_IQdiv(_IQ(Sum9),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Temp=_IQmpy((buff-_IQ(0.5)),_IQ(100.0)); AD_value.Udc=AD_value.Udc1+AD_value.Udc2;
Val_adc_test[0]=_IQtoF(AD_value.Ua);
Val_adc_test[1]=_IQtoF(AD_value.Ub);
Val_adc_test[2]=_IQtoF(AD_value.Uc);
Val_adc_test[3]=_IQtoF(AD_value.Ia);
Val_adc_test[4]=_IQtoF(AD_value.Ib);
Val_adc_test[5]=_IQtoF(AD_value.Ic);
Val_adc_test[6]=_IQtoF(AD_value.Udc1);
Val_adc_test[7]=_IQtoF(AD_value.Udc2);
Val_adc_test[8]=_IQtoF(AD_value.Temp);
}
Seven Han:
Hi,你测试条件一样吗?都是在RAM或者flash跑的?
我在AD采样中断中把采样结果放到一个数组中,数组长度为4 然后在100us的定时器中把这4个采样结果求平均值,再*3 /4096,算成真实值。 对9路AD采样进行同样的操作。我直接计算的话需要是78us,用IQmath去计算为什么时间还要跟就呢 大概80us ,求教大神这是为什么呢?因为我是想测试IQmath所以没有用CLA
直接计算程序:
void claculat_adc(void)
{
Sum1=((float)(ADbuffVaca[0]+ADbuffVaca[1]+ADbuffVaca[2]+ADbuffVaca[3]))/4;
Sum2=((float)(ADbuffVacb[0]+ADbuffVacb[1]+ADbuffVacb[2]+ADbuffVacb[3]))/4;
Sum3=((float)(ADbuffVacc[0]+ADbuffVacc[1]+ADbuffVacc[2]+ADbuffVacc[3]))/4;
Sum4=((float)(ADbuffIaca[0]+ADbuffIaca[1]+ADbuffIaca[2]+ADbuffIaca[3]))/4;
Sum5=((float)(ADbuffIacb[0]+ADbuffIacb[1]+ADbuffIacb[2]+ADbuffIacb[3]))/4;
Sum6=((float)(ADbuffIacc[0]+ADbuffIacc[1]+ADbuffIacc[2]+ADbuffIacc[3]))/4;
Sum7=((float)(ADbuffVdc1[0]+ADbuffVdc1[1]+ADbuffVdc1[2]+ADbuffVdc1[3]))/4;
Sum8=((float)(ADbuffVdc2[0]+ADbuffVdc2[1]+ADbuffVdc2[2]+ADbuffVdc2[3]))/4;
Sum9=((float)(ADbuffTemp[0]+ADbuffTemp[1]+ADbuffTemp[2]+ADbuffTemp[3]))/4;
buff=Sum1*3/4096; // *3/4096
Val_adc_test[0]=(buff-ADC_OFFSET_UAC)*ADC_GAIN_UAC;
buff=Sum2*3/4096; // *3/4096
Val_adc_test[1]=(buff-ADC_OFFSET_UAC)*ADC_GAIN_UAC;
buff=Sum3*3/4096; // *3/4096
Val_adc_test[2]=(buff-ADC_OFFSET_UAC)*ADC_GAIN_UAC;
buff=Sum4*3/4096; // *3/4096
Val_adc_test[3]=(buff-ADC_OFFSET_IAC)*ADC_GAIN_IAC;
buff=Sum5*3/4096; // *3/4096
Val_adc_test[4]=(buff-ADC_OFFSET_IAC)*ADC_GAIN_IAC;
buff=Sum6*3/4096; // *3/4096
Val_adc_test[5]=(buff-ADC_OFFSET_IAC)*ADC_GAIN_IAC;
buff=Sum7*3/4096; // *3/4096
Val_adc_test[6]=buff*ADC_GAIN_UDC;
buff=Sum8*3/4096; // *3/4096
Val_adc_test[7]=buff*ADC_GAIN_UDC;
buff=Sum9*3/4096; // *3/4096
Val_adc_test[8]=((buff-0.5)*100);
}
采样IQmath的方法
void claculat_adc(void)
{
Sum1=(float)(ADbuffVaca[0]+ADbuffVaca[1]+ADbuffVaca[2]+ADbuffVaca[3]);
AdValue_avr=_IQdiv(_IQ(Sum1),_IQ(4.0)); //平均值
buff= _IQdiv(_IQmpy(_IQ(Sum1),_IQ(3.0)),_IQ(4096.0)); // *3/4096 AD_value.Ua=_IQmpy((buff-_IQ(ADC_OFFSET_UAC)),_IQ(ADC_GAIN_UAC));
Sum2=((float)(ADbuffVacb[0]+ADbuffVacb[1]+ADbuffVacb[2]+ADbuffVacb[3]));
AdValue_avr=_IQdiv(_IQ(Sum2),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ub=_IQmpy((buff-_IQ(ADC_OFFSET_UAC)),_IQ(ADC_GAIN_UAC));
Sum3=((float)(ADbuffVacc[0]+ADbuffVacc[1]+ADbuffVacc[2]+ADbuffVacc[3]));
AdValue_avr=_IQdiv(_IQ(Sum3),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Uc=_IQmpy((buff-_IQ(ADC_OFFSET_UAC)),_IQ(ADC_GAIN_UAC));
Sum4=((float)(ADbuffIaca[0]+ADbuffIaca[1]+ADbuffIaca[2]+ADbuffIaca[3]));
AdValue_avr=_IQdiv(_IQ(Sum4),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ia=_IQmpy((buff-_IQ(ADC_OFFSET_IAC)),_IQ(ADC_GAIN_IAC));
Sum5=((float)(ADbuffIacb[0]+ADbuffIacb[1]+ADbuffIacb[2]+ADbuffIacb[3]));
AdValue_avr=_IQdiv(_IQ(Sum5),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ib=_IQmpy((buff-_IQ(ADC_OFFSET_IAC)),_IQ(ADC_GAIN_IAC));
Sum6=((float)(ADbuffIacc[0]+ADbuffIacc[1]+ADbuffIacc[2]+ADbuffIacc[3]));
AdValue_avr=_IQdiv(_IQ(Sum6),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Ic=_IQmpy((buff-_IQ(ADC_OFFSET_IAC)),_IQ(ADC_GAIN_IAC));
Sum7=((float)(ADbuffVdc1[0]+ADbuffVdc1[1]+ADbuffVdc1[2]+ADbuffVdc1[3])); AdValue_avr=_IQdiv(_IQ(Sum7),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Udc1=_IQmpy((buff),_IQ(ADC_GAIN_UDC));
Sum8=((float)(ADbuffVdc2[0]+ADbuffVdc2[1]+ADbuffVdc2[2]+ADbuffVdc2[3]));
AdValue_avr=_IQdiv(_IQ(Sum8),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Udc2=_IQmpy((buff),_IQ(ADC_GAIN_UDC));
Sum9=((float)(ADbuffTemp[0]+ADbuffTemp[1]+ADbuffTemp[2]+ADbuffTemp[3]));
AdValue_avr=_IQdiv(_IQ(Sum9),_IQ(4.0)); buff= _IQdiv(_IQmpy(AdValue_avr,_IQ(3.0)),_IQ(4096.0)); // *3/4096
AD_value.Temp=_IQmpy((buff-_IQ(0.5)),_IQ(100.0)); AD_value.Udc=AD_value.Udc1+AD_value.Udc2;
Val_adc_test[0]=_IQtoF(AD_value.Ua);
Val_adc_test[1]=_IQtoF(AD_value.Ub);
Val_adc_test[2]=_IQtoF(AD_value.Uc);
Val_adc_test[3]=_IQtoF(AD_value.Ia);
Val_adc_test[4]=_IQtoF(AD_value.Ib);
Val_adc_test[5]=_IQtoF(AD_value.Ic);
Val_adc_test[6]=_IQtoF(AD_value.Udc1);
Val_adc_test[7]=_IQtoF(AD_value.Udc2);
Val_adc_test[8]=_IQtoF(AD_value.Temp);
}
LEI BO:
回复 Seven Han:
是一样的,都是定义在ram中运行。。。还有怎么判断程序是不是成功的被复制到ram中了呢?我感觉我程序的运行速度比较慢