how to configure the multiple ADC' s using polling method(not as DMA or Interrupt method)
Hi,
I AM using a stm32f070c6 . it has 8 channel with 12 bit resolution ADC, I need to configure the multiple ADC's using polling method, not to use DMA or Interrupt method , I develop a code for it if any one sensor connected with adc pin of my MCU , that channel should be enabled and gives the output(for that i made minimum constant value for all the channels) all the channels are enabled and gives the adc values but the adc values are not correct(because I checked with 3.3v pin connected with one of my channel but it is giving some 113 value actually for 3.3 it gives 4095 ( this is my formula to convert the adc get value into mv ,adc_value=adc_value*3300/4095))
I need some clarifications
- is it possible to enable the all channels at a time in stm32 using polling method(if it is possible how we can configure)
- is that sampling time effects my adc values
- actaully I gave rank 1 to all the channels AND sConfig.Channel = ADC_CHANNEL_NO.;
- I need an example code to configure the multiple adc's using polling method(not as an DMA or Interrupt method)
this is my code
before main function
void ADC_Select_CH0 (void)
{
ADC_ChannelConfTypeDef sConfig = {0};
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
// ADC_SAMPLETIME_28CYCLES_5
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
void ADC_Select_CH1 (void)
{
ADC_ChannelConfTypeDef sConfig = {0};
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
as follows all the channels
In my while(1)
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 100);
for(int count =0;count<=min;count++)
{
ADC_VAL [0]= HAL_ADC_GetValue(&hadc);
sprintf((char*)data,"ADC value[0]:%4d\r\n",(int)adc_value[0]);
ADC_VAL [0]= ADC_VAL[0]*3300/4095;
if(count<=min)
{
VAR+= ADC_VAL[0];
}
}
adc_value = VAR/min;
//HAL_ADC_Stop(&hadc);
//adc_value = ADC_VAL[0]*3300/(int)4095;
HAL_ADC_Stop(&hadc);
if(adc_value>=min)
{
sprintf((char*)data,"ADC value[0]:%4d\r\n",(int)adc_value);
CDC_Transmit_FS(data, sizeof(data));
HAL_Delay(100);
as follows for all channels
where min =100, i just average the ADC value.
if any one have idea about of it please give a reply.
Thanks in advance
