主要逻辑:取8次平均值,然后存入数组,求和然后取平均值。
阅读后如果有帮助,给我点赞吧
void AdcAverageInit(void)
{
u16 ADCInit_SPVal = 0;
u8 n;
for(n=0; n<8;n++)
{
ENABLE_ADC_AIN7; //使能
ADCInit_SPVal = AdcGetVal(); //单次取值
SpeedAverage[n] = ADCInit_SPVal; //取8次ADC值,并存入数组
Speed_Sum += SpeedAverage[n]; //求和
}
SpeedInitialValue = Speed_Sum; //复位后速度ADC初始值
Speed_Init = Speed_Sum >> 3; //除以8取平均值
}
主要逻辑:取8次平均值,然后存入数组,求和然后取平均值。
阅读后如果有帮助,给我点赞吧
void AdcAverageInit(void)
{
u16 ADCInit_SPVal = 0;
u8 n;
for(n=0; n<8;n++)
{
ENABLE_ADC_AIN7; //使能
ADCInit_SPVal = AdcGetVal(); //单次取值
SpeedAverage[n] = ADCInit_SPVal; //取8次ADC值,并存入数组
Speed_Sum += SpeedAverage[n]; //求和
}
SpeedInitialValue = Speed_Sum; //复位后速度ADC初始值
Speed_Init = Speed_Sum >> 3; //除以8取平均值
}
举报