sappppp 发表于 2015-12-2 15:09:09

請問有關於兩個channel的ADC讀取問題

想要請問,我有兩個Channel的ADC,第一個Channel : ADC1IN11PC1 和另一個Channel: ADC1 IN12PC2,但是我在讀取的時後數值一直不對,所以想要請問我的程式是哪裡有問題呢?
謝謝
int main(void)
{
    /* System clocks configuration ---------------------------------------------*/
    RCC_Configuration();

    /* NVIC configuration ------------------------------------------------------*/
    NVIC_Configuration();

    /* GPIO configuration ------------------------------------------------------*/
    GPIO_Configuration();

    /* Configure the USART1 */
    USART_Configuration1();

    /* Configure the ADC */
    ADC_Configuration();

    /* Configure the DMA */
    DMA_Configuration();
      
    while(1)
    {
      ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_239Cycles5);
      AD_value = ADC_GetConversionValue(ADC1);

      ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 2, ADC_SampleTime_239Cycles5);
      AD_value2= ADC_GetConversionValue(ADC1);

       if (ticks++ >= 900000)
       {                  /* Set Clock1s to 1 every 1 second    */
      ticks   = 0;
      Clock1s = 1;
      }

      /* Printf message with AD value to serial port every 1 second             */
       if (Clock1s)
      {
          Clock1s = 0;

          printf("The current IA value = 0x%04X \r\n", AD_value );
          printf("The current IB value = 0x%04X \r\n", AD_value2);

       }
   }
}


void GPIO_Configuration(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC,ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
}


void ADC_Configuration(void)
{
    /* ADC1 configuration ------------------------------------------------------*/
    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;                                       
    ADC_InitStructure.ADC_ScanConvMode = ENABLE;                                                
    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;                                       
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;               
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                              
    ADC_InitStructure.ADC_NbrOfChannel = 2;                                                               
    ADC_Init(ADC1, &ADC_InitStructure);

    /* ADC1 regular channel14 configuration */
    ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_55Cycles5);          //通道11采样时间
    ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 2, ADC_SampleTime_55Cycles5);          //通道12采样时间

    /* Enable ADC1 */
    ADC_Cmd(ADC1, ENABLE);                                                                                                                  //使能ADC1

    /* Enable ADC1 reset calibaration register */   
    ADC_ResetCalibration(ADC1);                                                                                                          //允许ADC1复位校准寄存器
    /* Check the end of ADC1 reset calibration register */
    while(ADC_GetResetCalibrationStatus(ADC1));                                                                        //检测校准寄存器是否复位完成

   /* Start ADC1 calibaration */
    ADC_StartCalibration(ADC1);                                                                                                          //启动ADC1 校准
    /* Check the end of ADC1 calibration */
    while(ADC_GetCalibrationStatus(ADC1));                                                                              //检测校准是否完成

    /* Enable ADC1 DMA */                                                                                                                        
    ADC_DMACmd(ADC1, ENABLE);                                                                                          //允许ADC1进行DMA传送

      /* Start ADC1 Software Conversion */
    ADC_SoftwareStartConvCmd(ADC1, ENABLE);                                                                                  //软件触发启动ADC1转换
}



void DMA_Configuration(void)
{
    DMA_DeInit(DMA1_Channel1);
    DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;                  //DMA 外设 ADC 基地址
    DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC1_ConvertedValue;    // //DMA 内存基地址
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
    DMA_InitStructure.DMA_BufferSize = 1;
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
    DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
    DMA_Init(DMA1_Channel1, &DMA_InitStructure);

    /* Enable DMA channel1 */
    DMA_Cmd(DMA1_Channel1, ENABLE);

}

watershade 发表于 2015-12-3 13:15:53

是不是两个数据互相影响,就好像从一个口读取出来的数据
页: [1]
查看完整版本: 請問有關於兩個channel的ADC讀取問題