cancel
Showing results for 
Search instead for 
Did you mean: 

How to read 3 channel ADC with DMA

ferhatyol-23
Senior
Posted on January 13, 2016 at 16:16

Hi

I'm using STM32f7 Discovery board.I want to read 3 channel adc with DMA.I currently run a single channel.But I could not run three channels. I want to use ADC3 Channel 6, Channel 7 and Channel 8 This is ADC config code

/**
* @brief ADC configuration
* @param htim : ADC handle
* @retval None
*/
static void ADC_Config(void)
{
ADC_ChannelConfTypeDef sConfig;
/*##-1- Configure the ADC peripheral #######################################*/
AdcHandle.Instance = ADC3;
AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle.Init.NbrOfConversion = 3;
AdcHandle.Init.ScanConvMode = ENABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
AdcHandle.Init.NbrOfDiscConversion = 0;
AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; /* Conversion start trigged at each external event */
AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIG2_T2_TRGO;
AdcHandle.Init.DMAContinuousRequests = ENABLE;
AdcHandle.Init.EOCSelection = DISABLE;
if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
{
/* ADC initialization Error */
}
/*##-2- Configure ADC regular channel ######################################*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
{
/* Channel Configuration Error */
}
/*##-3- Start the conversion process #######################################*/
if(HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&uhADCxConvertedValue[0], 3) != HAL_OK)
{
/* Start Conversation Error */
}
}

How do I make ADC channel settings in HAL libraries? Thank you
12 REPLIES 12
ferhatyol-23
Senior
Posted on January 15, 2016 at 21:19

No, I'm using potentiometer with CH6.  I don't use CH7 and CH8. 

CH7 and CH8 are iddle.(float)

nikitaterm
Associate
Posted on February 14, 2016 at 16:33

I have the same issue. And I also have no ideas what's going on. Have you solved it for yourself?

nikitaterm
Associate
Posted on February 14, 2016 at 17:13

Hello again!

I solved the issue for me!

The problem is that the ADC has the input capacitor and when it is switching to the next channel the capacitor still is charged by the value from the previous one. It requires some time to re-charge the capacitor with the voltage from the current channel .

In my case the second channel is the temperature sensor and it's connected with some resistance which creates an RC-circuit with the capacitor. That's why we need to wait some time (RC-time constant) before reading the value from the second channel . Just change the channel sampling time with the appropriate value (corresponding  your RC-time constant) to do that. Also you can change the resistance of your channel's input, but it isn't possible in my case, because the temperature sensor is internally connected.