cancel
Showing results for 
Search instead for 
Did you mean: 

Curious problem when trying to read differential ADC values on Nucleo F303ZE

JMarc.5
Associate II

Hello, first time posting so I'm sorry if this is not the right place.

I just got a Nucleo F303ZE board and I'm trying to learn how to use it. The thing is, I have a board with several capacitos connected in series, and I'd like to use the MC to measure their individual voltages.

For this, I have to use several ADCs from the chip in differential mode, but I'm having trouble just measuring one. I can't use single-end mode, as the sum of volages of the supercaps can get up to 48V (18 caps of 2.7V each), but I've tried when they were dischaged and it worked just fine after messing with the sampling time and adding calibration.

The thing is, after setting ADC1 for differential mode, the value I get after measuring one capacitor is of 2155 (1.74V), which is way higher than it's actual charge (0.17V, measured manually).

I thought that maybe I had missplaced the pins, so I swaped them and I got 1937 this time. Funny enough, 2155 - 1937 = 218, which is exactly the 0.17V that I'm expecting when converted, so I know that I can't be too far from the solution.

And here is what i receive through terminal:0693W000008zfzJQAQ.pngAnd after switching the pins:

0693W000008zfziQAA.png 

Here is an screenshot of my configuration and I also include the main.c code, but the only things that I've included after auto generating are:

int main(void)
{
  /* USER CODE BEGIN 1 */
	uint16_t raw;
		  char msg[10];
  /* USER CODE END 1 */
 
 if(HAL_ADCEx_Calibration_Start(&hadc1, ADC_DIFFERENTIAL_ENDED)){
	  Error_Handler();
  }
/* USER CODE BEGIN 2 */
  if (HAL_ADC_Start(&hadc1) != HAL_OK)
    {
      /* Start Conversation Error */
      Error_Handler();
    }
  /* USER CODE END 2 */
while (1)
  {
//Some LEDs tryouts and serial connection
	  	      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET);
	  	      HAL_GPIO_WritePin(LD3_GPIO_Port,LD3_Pin,GPIO_PIN_SET);
	  	      HAL_GPIO_WritePin(LD3_GPIO_Port,LD3_Pin,GPIO_PIN_RESET);
	  	      
raw = HAL_ADC_GetValue(&hadc1);
	  	      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
	  	      sprintf(msg, "%hu\r\n", raw);
	  	      HAL_UART_Transmit(&huart3, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}

0693W000008zftkQAA.png 

So I've been trying several configurations on CubeIDE but to no avail, any one can help me with where could be the problem? I'm pretty new to all of this stuff so I'm sorry if I'm not explaining well.

Right now I'm only trying to measure 1 as I'm just starting, but in the future I'll have to measure all 18 caps at the same time, do you think I'll be able with this board?

Thank you very much.

5 REPLIES 5
Uwe Bonnes
Principal III

What is common mode voltage? Differential mode has only a small window around VREF/2., see table 79 CMIR.

JMarc.5
Associate II

Hello, than you for your response, but I'm not quite getting it, english is not my first language and I'm not too tech-savvy.

What do you mean "common mode voltage".

Also, if I understand correctly, you mean table 79 of the user manual of the STM32F303, right? This one: https://www.st.com/resource/en/reference_manual/dm00043574-stm32f303xb-c-d-e-stm32f303x6-8-stm32f328x8-stm32f358xc-stm32f398xe-advanced-arm-based-mcus-stmicroelectronics.pdf ?

Uwe Bonnes
Principal III

Common mode voltage is ( V(ADCIN+, referenced to ground) - V(ADCIN-, referenced to ground)). It seems your setup has no ground connection between Nucleo and "CAP" board, so common mode voltage is floating and perhaps strange things happen. Try to measure single-ended: Connect to lower vltage of the CAP board to MCU GND and the higher voltage to ADCIN. Read about common-mode, single ended etc also in the Internet.

JMarc.5
Associate II

Ok, I've tried single-end ADC before, using pins to AGND and to PA0, and it works fine. I've measure the voltage of each pin used at the differential measure and their difference is the voltage that I'm looking for, but I'm trying to get said value with just one measure.

Also, could this MC be able to measure a diffential voltage when one of the pins is at, say, 48 and the other at 46? Or would voltages that high affect the board /MC?

(I'll add tomorrow and squematic view of the circuit)

Uwe Bonnes
Principal III

No. ADC absolute voltage needs to be between VSSA and VDDA or you will fry the chip.