AD采样求平均STM32实现

 1 iADC_read(0, &u16NTC_1_Sample_Val_ARR[10]);
 2 
 3     if(0 == ui8FirstSampleFlag)
 4     {
 5         for(i=0; i<10; i++)
 6         {
 7             u16NTC_1_Sample_Val_ARR[i] = u16NTC_1_Sample_Val_ARR[10];
 8         }
 9         ui8FirstSampleFlag = 1;
10     }
11     
12     u16NTC_1_Sample_Val_ARR[10] = (uint16_t)
13 ((0.1f) * ((float)(u16NTC_1_Sample_Val_ARR[0] + u16NTC_1_Sample_Val_ARR[1]
14                 + u16NTC_1_Sample_Val_ARR[2] + u16NTC_1_Sample_Val_ARR[3]
15                 + u16NTC_1_Sample_Val_ARR[4] + u16NTC_1_Sample_Val_ARR[5]
16                 + u16NTC_1_Sample_Val_ARR[6] + u16NTC_1_Sample_Val_ARR[7]
17                 + u16NTC_1_Sample_Val_ARR[8] + u16NTC_1_Sample_Val_ARR[9])));
18 
19     
20     for(i=1; i<=10; i++)
21     {
22         u16NTC_1_Sample_Val_ARR[i-1] = u16NTC_1_Sample_Val_ARR[i];
23     }
1 uint8_t iADC_read( uint8_t ucAdcChn, uint16_t *u16AdcData)
2 {
3     *u16AdcData = (uint16_t)ADC_ConvertedValue[ucAdcChn] ;
4     return (1);
5 }
1 __IO uint16_t ADC_ConvertedValue[ADC_DMA_BUFFER_SIZE]= {0};

 

posted @ 2019-03-31 22:51  wdliming  阅读(1354)  评论(0编辑  收藏  举报