502360026 发表于 2014-10-22 16:36 
楼主能否把程序贴出来参考下?
void adc_init(void)
{
ADC1->TDRL = 0x00;
ADC1->TDRH = 0x00;//(uart需要,如果为0XFF串口只能发送接受不了)
ADC1->CR1 = 0x00; // 16mhz/2
ADC1->CR2 = (uint8_t)~ADC1_CR2_ALIGN; //数据左对齐
ADC1->CR1 |= ADC1_CR1_ADON; //从低功耗唤醒AD
}
uint16_t adc_scan(uint8_t channel)
{
uint16_t temp = 0;
int i =0;
ADC1->CSR &= (uint8_t)~ADC1_CSR_EOC;
ADC1->DRH = 0;
ADC1->DRL =0;
ADC1->CSR = adc_channel[channel];
ADC1->CR1 |= ADC1_CR1_ADON;
// for(i=3;i>0;i--)
// nop();
/* select channel */
while (!(ADC1->CSR & ADC1_CSR_EOC));
temp = ADC1->DRH;
temp = temp<<2;
temp += ADC1->DRL;
ADC1->CSR &= (uint8_t)~ADC1_CSR_EOC;
// temp = (uint16_t)(((float)temp*5000)/1023)*2;
return temp;
}
cur_channel = 0;下面是调用函数,是一个IO上升沿中断触发采样,一个上升沿采样1次或者连续10次,结果都不准,哎愁死了,急死了,我的电压一直是4020V,采集到的数据乱七八糟的,什么结果都有,急死了~~~
void extic_interrupt(void)
{
int i = 0;
int count = 0;
// GPIO_WriteLow(GPIOB, GPIO_PIN_5);
// for(i=0;i<4200;i++)
// nop(); //延时280us 4200/16mhz
for (count = 0; count < SCAN_COUNT;count++)
{
ADScanVol[cur_channel][count] = adc_scan(cur_channel);
}
// BatADVol[cur_channel] = adc_scan(cur_channel);
if (cur_channel >= ADC_CHANNEL_BAT13)
{
cur_channel = ADC_CHANNEL_IDEL;
}
else
{
cur_channel+=1;
}
}
|