AnsweredAssumed Answered

ADC_GetConversionValue(ADC) == 0 ??

Question asked by su.sam.001 on Feb 6, 2014
Latest reply on Feb 7, 2014 by baird.hal.001
Hi I'm getting sometimes 0 from my ADC conversation but this can't be possible.

Pls correct me pls if I say something wrong.

I'm working with the STM3210E-Eval board it has an STM32F103GT processor.

This is my configuration for my adc1 , I have 3 ADC's because it is the same I'm just posting one.

01.void Config_ADC(GPIO_InitTypeDef *GPIO_InitStructure)
02.{
03.    RCC_ADCCLKConfig(RCC_PCLK2_Div6);                                                                                    //clock for ADC  ADCCLK = PCLK2/6 = 72/6 = 12MHz*/
04. 
05.    // enable ADC system clock
06.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3, ENABLE);
07.  
08.     /* Configure PC.01, PC.02 and PC.03 (ADC Channel 11, ADC Channel 12, ADC Channel 13) as analog input */
09.    GPIO_InitStructure->GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 ;                    // PC.01, PC.02 and PC.03
10.    GPIO_InitStructure->GPIO_Mode = GPIO_Mode_AIN;                                                               // Input-Mode
11.    GPIO_InitStructure->GPIO_Speed = GPIO_Speed_50MHz;                                                     // Speed of port
12.    GPIO_Init(GPIOC, GPIO_InitStructure);                                                                                // apply configuration on PortC
13.  
14.}

01.  ADC_InitStructure->ADC_ContinuousConvMode = ENABLE;                                                      //ster next convert automatically
02.  ADC_InitStructure->ADC_DataAlign = ADC_DataAlign_Right;                                              //put left/right adjusted in register
03.  ADC_InitStructure->ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;                     //choose which extern signal should start convert
04.  ADC_InitStructure->ADC_Mode = ADC_Mode_Independent;
05.  ADC_InitStructure->ADC_NbrOfChannel = 1;
06.  ADC_InitStructure->ADC_ScanConvMode = DISABLE;
07.   
08.  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_28Cycles5);  
09.ADC_Init(ADC1, ADC_InitStructure);                                                                                      //set config of ADC1
10.   
11.  ADC_Cmd(ADC1, ENABLE); 

1.//start-callibration
2.ADC_ResetCalibration(ADC1);                                                  /* Enable ADC1 reset calibration register */
3.while(ADC_GetResetCalibrationStatus(ADC1));                  /* Check the end of ADC1 reset calibration register (Reset previous calibration)*/
4.ADC_StartCalibration(ADC1);                                                  /* Start ADC1 calibration */
5.while(ADC_GetCalibrationStatus(ADC1));                           /* Check the end of ADC1 calibration */
6.//End-callibration
7. 
8.ADC_SoftwareStartConvCmd(ADC1, ENABLE);

    
So that means one AD conversion takes 3,41 us.

I have an Timer that is active every 30us active.


01.void Config_Timer_TIM2(TIM_TimeBaseInitTypeDef *TIM_TimeBaseStructure, NVIC_InitTypeDef *NVIC_InitStructure)
02.{
03.    // enable TIMER TIM2 system clock
04.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
05.     
06.     
07. /* Enable the Timer2 Interrupt */
08.    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
09.     
10.  NVIC_InitStructure->NVIC_IRQChannel = TIM2_IRQn;                       //  configure the Timer2 interrupts
11.  NVIC_InitStructure->NVIC_IRQChannelPreemptionPriority = 3;   //  sets the priority group of the TIMER2 interrupts
12.  NVIC_InitStructure->NVIC_IRQChannelSubPriority = 0;                    //  set the subpriority inside the group
13.  NVIC_InitStructure->NVIC_IRQChannelCmd = ENABLE;                       //  TIMER2 interrupts are globally enabled
14.  NVIC_Init(NVIC_InitStructure);       
15.     
16.    /* Configure Timer which is every 1 ms active*/
17.  TIM_DeInit(TIM2);
18.  TIM_TimeBaseStructInit(TIM_TimeBaseStructure);
19.  
20.  /* Time base configuration */
21.  TIM_TimeBaseStructure->TIM_Prescaler = 72 - 1; // 72 MHz / 72 = 1 Mhz
22.  TIM_TimeBaseStructure->TIM_Period = 30 - 1;    // (1/1Mhz) * 30 = 30 us;
23.  TIM_TimeBaseStructure->TIM_ClockDivision = TIM_CKD_DIV1;
24.  TIM_TimeBaseStructure->TIM_CounterMode = TIM_CounterMode_Up;
25.  TIM_TimeBaseInit(TIM2, TIM_TimeBaseStructure);
26.     
27.     
28.  /* Enable TIM2 Update Interrupt */
29.  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
30.  
31.  /* Enable TIM2 */
32.  TIM_Cmd(TIM2,ENABLE);        
33.}

In my Interrupt:

01.void TIM2_IRQHandler(void)
02.{
03. if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
04. {        
05.   if(calibration < calibration_counter)
06.  {             
07.   array1 =ADC_GetConversionValue(ADC1);        
08.   array2 =ADC_GetConversionValue(ADC2);          
09.   array3 =ADC_GetConversionValue(ADC3);          
10.   TIM_ClearITPendingBit(TIM2, TIM_IT_Update);              //Update Interrupt
11.  }
12. }
13.}



When I'm getting 512 times an value with ADC_GetConversionValue(ADC)  , about 200 values from ADC 3 are 0 , from ADC2 are 139 zero and ADC1 are 56 zero.

What is the problem ?

Outcomes