2021-05-27 01:18 AM
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
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
2021-06-01 04:38 AM
Hello @VRajk.1 ,
You can get inspired from the working ADC example runs on STM32F0xx devices, which is available in the STM32CubeF0 MCU package and can help you on how to use the ADC in Polling mode to convert data:
\Repository\STM32Cube_FW_F0_V1.11.2\Projects\STM32072B_EVAL\Examples\ADC\ADC_RegularConversion_Polling
Hope this helps you :)
Please mark my answer as best by clicking on the "Select as Best" button if it helped.
Imen