cancel
Showing results for 
Search instead for 
Did you mean: 

Different ADC Channels Reporting Values from other Channels when Polled (STM32G0)

jesse-TP
Associate

Hello,

I have seven ADC channels in my design. I have probed these channels and can confirm from an analog standpoint the signals are clean, and are stable when read from using the ADC. 

 

I have read from each channel and received expected values, however when I scan, I at times will have a channel reporting a value I would expect from a different channel. As if I am reading from channel 4, but it is reported as channel 5. Here is telemetry I receive when reading from the ADC channels:

 

 

... Beginning ADC Read ...
VIN Voltage [mv]: 6190 index: 1 
3V3 Voltage [mv]: 446 index: 2 // I would expect this value on a CC line
CC1 Voltage [mv]: 51 index: 3 
CC2 Voltage [mv]: 1236 index: 4 // I would expect this value to be VBAT
IBAT Current [mV]: 1236 index: 5 // same value again ??
VBAT Voltage [mv]: 2476 index: 6

 

 

 

My implementation for scanning and reading these ADC channels is below:

 

 

void getADC(uint32_t* data_buffer)
{
	uint8_t numChannels = 7;
	uint16_t vref = 3300;
	HAL_ADC_Start(&hadc1);
	for(uint8_t i = 0; i < numChannels; i++)
	{
		HAL_ADC_PollForConversion(&hadc1, 1000);
		data_buffer[i] = HAL_ADC_GetValue(&hadc1);
		if ((i + 1) == ADC_RANK_VBAT)
		{
			uartPrintf("VBAT Voltage [mv]: %i index: %i\r\n", data_buffer[i]*vref / 4095*2, i);
		}
		if ((i + 1) == ADC_RANK_VIN)
		{
			uartPrintf("VIN Voltage [mv]: %i index: %i\r\n", data_buffer[i]*vref / 4095*5, i);
		}
		if ((i + 1) == ADC_RANK_VAUX)
		{
			uartPrintf("3V3 Voltage [mv]: %i index: %i\r\n", data_buffer[i]*vref / 4095*2, i);
		}

		if ((i + 1) == ADC_RANK_CC1)
		{
			uartPrintf("CC1 Voltage [mv]: %i index: %i\r\n", data_buffer[i]*vref / 4095, i);
		}
		if ((i + 1) == ADC_RANK_CC2)
		{
			uartPrintf("CC2 Voltage [mv]: %i index: %i\r\n", data_buffer[i]*vref / 4095, i);
		}
		if ((i + 1) == ADC_RANK_IBAT)
		{
			uartPrintf("IBAT Current [mV]: %i index: %i\r\n", data_buffer[i]*vref / 4095, i);
		}
	}
	HAL_ADC_Stop(&hadc1);

}

 

 

The ADC init function is called from main() once at startup. This getADC function is called once ever second or so from the main while loop. 

GUI settings for the ADC are below:

jesseTP_0-1718376627975.pngjesseTP_1-1718376663997.pngjesseTP_2-1718376700530.pngjesseTP_3-1718376721357.png

 

I am not using the DMA in this instance for some minor power savings. Could this be the cause of my issue? Anything else stick out for what I am doing wrong?

 

Thanks

Jesse

 

 

 

1 REPLY 1
Lohi
Associate III

hi; without seeing a schematic, it's more difficult, but, in some cases, with multiplexing, if the resistance of the source is too high, the ADC S/H can pick up the previous channel voltage, which is 'sitting' on the ADC input capacitance...if the channel is changed, then enough settling time is allowed, this can be avoided, or, use a fast buffer to drive the ADC channels... can't be too sure without more hardware information, so just an "educated guess"