我的代码如下:
#define ADCBUFFERSIZE (20)
uint16_t milliVoltBuffer[ADCBUFFERSIZE];
int cmp(const void *a, const void *b )
{
return *(int *)a – *(int *)b;
}
void AdSampleFilter(void)
{
unsigned char i;
unsigned int sum;
qsort(milliVoltBuffer,ADCBUFFERSIZE,sizeof(milliVoltBuffer[0]),cmp);
for(i = 0; i < ADCBUFFERSIZE; i++)
{
if(i>=SAMPLE_OFFSET && i<(ADCBUFFERSIZE-SAMPLE_OFFSET))
{
sum += milliVoltBuffer[i];
}
}
powerValue = sum /(ADCBUFFERSIZE – SAMPLE_OFFSET*2);
}
Viki Shi:
好的,感谢提供反馈