//****读取中间值****// short GetMedianNum(short * bArray, short iFilterLen) { short i,j,bTemp;// 排序循环 for (j = 0; j < iFilterLen - 1; j ++) { for (i = 0; i < iFilterLen - j - 1; i ++) { if (bArray[i] > bArray[i + 1]) { // »¥»» bTemp = bArray[i]; bArray[i] = bArray[i + 1]; bArray[i + 1] = bTemp; } } } if ((iFilterLen & 1) > 0) { // 奇数计算中值 bTemp = bArray[(iFilterLen + 1) / 2]; } else { // 偶数个计算中值 bTemp = (bArray[iFilterLen / 2] + bArray[(iFilterLen / 2) - 1]) / 2; } return bTemp; } void get_ADC_CH(void) { nrfx_err_t err_code; static uint8_t ADC_CNT = 0; static short ADC_ch_data[AdcUseCHs][ADC_FILTER_CNT]; uint8_t tempi,tempj; err_code = fu_peripheral_saadc_sample_convert(0, (nrf_saadc_value_t*)&userADC_var.buff[0][ADC_CNT]); APP_ERROR_CHECK(err_code); err_code = fu_peripheral_saadc_sample_convert(1, (nrf_saadc_value_t*)&userADC_var.buff[1][ADC_CNT]); APP_ERROR_CHECK(err_code); err_code = fu_peripheral_saadc_sample_convert(2, (nrf_saadc_value_t*)&userADC_var.buff[2][ADC_CNT]); APP_ERROR_CHECK(err_code); err_code = fu_peripheral_saadc_sample_convert(3, (nrf_saadc_value_t*)&userADC_var.buff[3][ADC_CNT]); APP_ERROR_CHECK(err_code); err_code = fu_peripheral_saadc_sample_convert(4, (nrf_saadc_value_t*)&userADC_var.buff[4][ADC_CNT]); APP_ERROR_CHECK(err_code); ADC_CNT++; if(ADC_CNT>=ADC_FILTER_CNT) { ADC_CNT = 0; } for(tempi= 0;tempi<AdcUseCHs;tempi++) { for(tempj= 0;tempj<ADC_FILTER_CNT;tempj++) { ADC_ch_data[tempi][tempj] = userADC_var.buff[tempi][tempj]; } } for(tempi= 0;tempi<AdcUseCHs;tempi++) { userADC_var.ADCMeasureVals[tempi] = (uint16_t)GetMedianNum(ADC_ch_data[tempi],ADC_FILTER_CNT); }