先贴下代码:
/* GPIO 初始化部分 */
/* GPIO的时钟已经使能 */
GPIO_InitTypeDef GPIO_InitStructure; /* MAC Pin */
GPIO_InitStructure.GPIO_Pin = MAC_GPIO_PIN; /* PA0 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(MAC_GPIO_PORT, &GPIO_InitStructure);
/* ADC 模拟看门狗初始化部分 */
ADC_InitTypeDef ADC_InitStructure;
/* Enable the HSI */
RCC_HSICmd(ENABLE);
/* Wait until HSI oscillator is ready */
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* ADC1 Configuration -----------------------------------------------------*/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_ClearITPendingBit(ADC1, ADC_IT_AWD);
/* ADC1 regular channel0 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_4Cycles);
/* Configure channel0 as the single analog watchdog guarded channel */
ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_4);
/* Configure high and low analog watchdog thresholds */
ADC_AnalogWatchdogThresholdsConfig(ADC1, MAC_HIGHER_THRESHOLD, MAC_LOWER_THRESHOLD);//0x16E
/* Enable analog watchdog on one regular channel: channel0 */
ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
/* Enable AWD interrupt */
ADC_ITConfig(ADC1, ADC_IT_AWD, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Wait until the ADC1 is ready */
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
{
}
/* Start ADC1 Software Conversion */
ADC_SoftwareStartConv(ADC1);
问题:1> 上面的代码是将对应的ADC通道用作模拟看门狗,该段程序用作通道0的时候能够正常实现对应的功能。但是换成通道4就不能实现模拟看门狗的功能?
2> 用作通道4的时候DR寄存器保存的AD值变动特别慢,有时候需要维持电压在一个值很长一段时间才能够采集到电压?
劳烦各位帮忙看看是什么问题?
|