AnsweredAssumed Answered

ADC Bug

Question asked by serao.pietro on May 20, 2013
Latest reply on May 25, 2013 by an.yuping
Hi guys, i use am stm32f0 microcontroller.
I've a problem about the ADC channel 13 (PC3 pin) and PA3 pin.
when i connect something to PA3 pin seems that the ADC PC3 pin reads the PA3 pin value.

this is my ADC configuration code:

void ADC1_Config(void)
{
  ADC_InitTypeDef          ADC_InitStructure;
  GPIO_InitTypeDef         GPIO_InitStructure;
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef        TIM_OCInitStructure; 
  
  /* Abilita Periph clock GPIOC  */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
  
  /* Abilita ADC1 Periph clock  */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  
  /* Abilita TIM3 Periph clock  */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  
  /* Configura ADC Channel11 come ingresso analogico */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN  ;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  
  /* Configurazione TIM3  *******************************************************/
  TIM_DeInit(TIM3);
  
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
  
  TIM_OCStructInit(&TIM_OCInitStructure);
    
  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Period = 0xFF;
  TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
  
  /* Seleziona TIM3 TRGO  */
  TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);
  
  /* Configurazione ADC1  *******************************************************/
  /* Reset ADC  */  
  ADC_DeInit(ADC1);
  
  /* Configura l' ADC1 in continous mode con una risoluzione di 12 bit*/
  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;    
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
  ADC_Init(ADC1, &ADC_InitStructure); 
  
  /* Converte l'ADC1 Channel 11 con sampling time pari a 239.5 cicli */ 
  ADC_ChannelConfig(ADC1, ADC_Channel_11 , ADC_SampleTime_28_5Cycles );   
  ADC_ChannelConfig(ADC1, ADC_Channel_13 , ADC_SampleTime_28_5Cycles);


  /* Calibrazione ADC  */
  ADC_GetCalibrationFactor(ADC1);
    
  ADC_WaitModeCmd(ADC1, ENABLE); 
  ADC_AutoPowerOffCmd(ADC1, ENABLE); 
  
  /* Abilita l'ADC */
  ADC_Cmd(ADC1, ENABLE);     
  
  /* Attesa per il flag ADCEN  */
  while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN)); 
  
  /* Abilita counter TIM2  */
  TIM_Cmd(TIM3, ENABLE);
  
  /* Avvia conversione software regolare dell' ADC1 */ 
  ADC_StartOfConversion(ADC1);
}

every x seconds starts a timer routine that calls the adc reading function

these reading function is:

void LeggiADC(void)
{
  
  static short value=0;//indica quale variabile deve essere salvata dall'ADC
  /* Acquisizione dati convertiti dll'ADC1 */
    ADC1ConvertedValue = ADC_GetConversionValue(ADC1);
    value++;
    /* Calcolo della tensione del sensore di luminosità */
    if (value==1){
     mVLux = ((ADC1ConvertedValue * mV_VDDA_ref)/0xFFF);
  
    }else if (value==2){
      /* Calcolo della tensione del sensore di temperatura */
      mVTemp = ((ADC1ConvertedValue * mV_VDDA_ref)/0xFFF);
     value=0;
    }
    if(( GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6))==SET){
      NewSP=mVDAC;
      KTaratura= (float)(LUX)/2;
      EE_WriteVariable(0x6011, KTaratura);
    }
    
}


if i connect pin PA3 to 3V, the mVTemp value is 3V... why?

Outcomes