cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Channel Conversion Difference

MSilv.1
Associate III

Guys, I need help with ADC on STM32F407ZGTx. I have a project where I read 2 channels, ADC3_IN4 and ADC3_IN15. Since I need a function that has pin ADC3_IN15, I changed it to ADC3_IN8.

The problem is that I don't know what it is about STM32F407ZGTx, at least mine, that makes a difference in the reading.

On IN15, I had ranges from 54 to 920 in the final read value (this is the correct range).

However, on IN8, reading the same voltage levels, it is reading from 64 to 706. In addition to giving me incorrect ranges (for example, in the middle of the reading, it should give me 313, but it is giving me 460, which is the value that I read with IN15 and which is correct).

Are there any differences in the inputs? I've looked in several places, the STM32F407ZGTx manual, AN's, etc., and nothing, no one says anything. I tried DMA, nothing either. If I go back to IN15, the reading becomes constant and correct again.

Attached is an image of the configuration on the STM32CUBEIDE

.

PS: I checked the values ​​read by debug in each channel(IN15 and IN8), and they are really like that, analyzing the same voltage levels, but returning different values.


Below is the code that I read from the channels ADC

 

int analogRead(uint16_t GPIO_Pin)
{
	int vAnalogData;

	ADC_ChannelConfTypeDef sConfig = {0};

	switch (GPIO_Pin)
	{
		case 10:
			sConfig.Channel = ADC_CHANNEL_8;
			break;
		case 6:
			sConfig.Channel = ADC_CHANNEL_4;
			break;
	}

	sConfig.Rank = 1;
	sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	HAL_ADC_ConfigChannel(&hadc3, &sConfig);

	HAL_ADC_Start(&hadc3);
	HAL_ADC_PollForConversion(&hadc3, 1000);
	vAnalogData = HAL_ADC_GetValue(&hadc3);
	HAL_ADC_Stop(&hadc3);

	sConfig.Rank = 0;
	sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
	HAL_ADC_ConfigChannel(&hadc3, &sConfig);

	return vAnalogData;
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

> sConfig.Rank = 1;

If you're doing a single conversion, it should be rank 0.

Your code here is weird. It sets rank 1, then converts (rank 0), then sets rank 0 (but doesn't convert it).

 

To the larger question: The ADC acts like a multiplexer. Downstream of the multiplexer, the same circuits convert each channel, so there should be no difference. Short sampling times can affect things for fast vs slow channels but at 84 cycles/sample this should not have an effect.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

> sConfig.Rank = 1;

If you're doing a single conversion, it should be rank 0.

Your code here is weird. It sets rank 1, then converts (rank 0), then sets rank 0 (but doesn't convert it).

 

To the larger question: The ADC acts like a multiplexer. Downstream of the multiplexer, the same circuits convert each channel, so there should be no difference. Short sampling times can affect things for fast vs slow channels but at 84 cycles/sample this should not have an effect.

If you feel a post has answered your question, please click "Accept as Solution".
MSilv.1
Associate III

That is it.. I removed this rank form code, and worked like a charm.

Thank you very much...