其實網路隨意google一下就很多資料
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
uint16_t readADC1(void) { uint16_t value; //ADC_RegularChannelConfig(ADC1, channel, 1, ADC_SampleTime_55Cycles5); // Start the conversion ADC_SoftwareStartConvCmd(ADC1, ENABLE); // Wait until conversion completion while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET); ADC_ClearFlag(ADC1, ADC_FLAG_EOC); // Get the conversion value value = ADC_GetConversionValue(ADC1); ADC_SoftwareStartConvCmd(ADC1, DISABLE); return value; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
void AdcPro(void) { static uint16_t buf[SAMP_COUNT]; static uint8_t write; uint32_t sum; uint8_t i; //buf[write] = ADC_GetConversionValue(ADC1); 原本直接讀取資料 buf[write] = readADC1(); if (++write >= SAMP_COUNT) { write = 0; } sum = 0; for (i = 0; i < SAMP_COUNT; i++) { sum += buf[i]; } g_usAdcValue = sum / SAMP_COUNT; /* 取平均 */ //ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* 原本先為下次使用而enable */ } |