2014-02-06 12:35 PM
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.
void
Config_ADC(GPIO_InitTypeDef *GPIO_InitStructure)
{
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
//clock for ADC ADCCLK = PCLK2/6 = 72/6 = 12MHz*/
// enable ADC system clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO | RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3, ENABLE);
/* Configure PC.01, PC.02 and PC.03 (ADC Channel 11, ADC Channel 12, ADC Channel 13) as analog input */
GPIO_InitStructure->GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 ;
// PC.01, PC.02 and PC.03
GPIO_InitStructure->GPIO_Mode = GPIO_Mode_AIN;
// Input-Mode
GPIO_InitStructure->GPIO_Speed = GPIO_Speed_50MHz;
// Speed of port
GPIO_Init(GPIOC, GPIO_InitStructure);
// apply configuration on PortC
}
ADC_InitStructure->ADC_ContinuousConvMode = ENABLE;
//ster next convert automatically
ADC_InitStructure->ADC_DataAlign = ADC_DataAlign_Right;
//put left/right adjusted in register
ADC_InitStructure->ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
//choose which extern signal should start convert
ADC_InitStructure->ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure->ADC_NbrOfChannel = 1;
ADC_InitStructure->ADC_ScanConvMode = DISABLE;
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_28Cycles5);
ADC_Init(ADC1, ADC_InitStructure);
//set config of ADC1
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.
void
Config_Timer_TIM2(TIM_TimeBaseInitTypeDef *TIM_TimeBaseStructure, NVIC_InitTypeDef *NVIC_InitStructure)
{
// enable TIMER TIM2 system clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Enable the Timer2 Interrupt */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
NVIC_InitStructure->NVIC_IRQChannel = TIM2_IRQn;
// configure the Timer2 interrupts
NVIC_InitStructure->NVIC_IRQChannelPreemptionPriority = 3;
// sets the priority group of the TIMER2 interrupts
NVIC_InitStructure->NVIC_IRQChannelSubPriority = 0;
// set the subpriority inside the group
NVIC_InitStructure->NVIC_IRQChannelCmd = ENABLE;
// TIMER2 interrupts are globally enabled
NVIC_Init(NVIC_InitStructure);
/* Configure Timer which is every 1 ms active*/
TIM_DeInit(TIM2);
TIM_TimeBaseStructInit(TIM_TimeBaseStructure);
/* Time base configuration */
TIM_TimeBaseStructure->TIM_Prescaler = 72 - 1;
// 72 MHz / 72 = 1 Mhz
TIM_TimeBaseStructure->TIM_Period = 30 - 1;
// (1/1Mhz) * 30 = 30 us;
TIM_TimeBaseStructure->TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure->TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, TIM_TimeBaseStructure);
/* Enable TIM2 Update Interrupt */
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
/* Enable TIM2 */
TIM_Cmd(TIM2,ENABLE);
}
In my Interrupt:
void
TIM2_IRQHandler(
void
)
{
if
(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
if
(calibration < calibration_counter)
{
array1 =ADC_GetConversionValue(ADC1);
array2 =ADC_GetConversionValue(ADC2);
array3 =ADC_GetConversionValue(ADC3);
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
//Update Interrupt
}
}
}
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 ?
#adc
2014-02-06 12:49 PM
Yeah, well that's practically unreadable. Just cut-n-paste the source into the Format Code Block window, it doesn't recognize HTML
You don't seem to qualify the EOC status prior to reading the values. In understanding the cases where you read zero, you might want to check the status of the ADC. If you ground the pin you might expect to see a zero.Might make more sense to trigger the ADC with the timer.Clear the update interrupt prior to reading the ADC values.Post COMPLETE code.2014-02-06 03:37 PM
So the EOC is not a fixed period of time ? I thought a
ADC_SampleTime_28Cycles5
with 12 Mhz is one ADC about 3,41 us long... Even if I do to wait for EOC the result is the same...while
(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);// Get the conversion value
array1= ADC_GetConversionValue(ADC1); while (ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET); array2= ADC_GetConversionValue(ADC2); while (ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC) == RESET); array3= ADC_GetConversionValue(ADC3);2014-02-07 11:01 AM
The problem might be outside the posted information.
Is there more than ADC conversion happening in the code ? What are the three signal sources, and how are the grounds connected between the Eval board and the signal sources ? Are the signal sources monitored with a scope or meter ? Are any jumpers between BNC1-3 and PC1-3 different from the Eval board delivered configuration ? Cheers, Hal