1
\$\begingroup\$

I have a custom PCB with an STM32F303K8T6 microcontroller onboard. Three values need to be measured with the ADC, but the values from the ADC do not match with the voltages measured at the ADC pins.

The voltages for the ADC2 are both 1.64 V and the measured values are 364 and 2001. ADC1 seems to have an offset (around 0-600) that changes over the applied voltage, like it is temperature dependent. I had such a problem on a STM32F4 Discovery, where the diode was the problem, but here I don't use any diode that could cause that problem.

The reference voltage at the VDDA/VREF+ is exactly 3.3 V (measured). The schematic and the setup in the CubeMX is attached in the images at the bottom. The code to achieve the ADC measurements is the following:

Code:

HAL_ADC_Start(&hadc1);
while(HAL_ADC_PollForConversion(&hadc1, 0) != HAL_OK)
    ;
measurement1 = HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);

HAL_ADC_Start(&hadc2); // Start regular conversion of regular group (channel 4 and 5)
while(HAL_ADC_PollForConversion(&hadc2, 0) != HAL_OK)
    ;
measurement2 = HAL_ADC_GetValue(&hadc2);
measurement3 = HAL_ADC_GetValue(&hadc2);
HAL_ADC_Stop(&hadc2);

Schematic:

Schematic Schematic 2

CubeMX:

Enter image description here Enter image description here

\$\endgroup\$
  • \$\begingroup\$ What are the ADC inputs? \$\endgroup\$ – Bence Kaulics Feb 26 '17 at 17:17
  • \$\begingroup\$ ADC1, channel 4 measures the input voltage via a voltage divider (1/11), which varies. ADC2, channel 1 and channel 2 have both 1.64V as input, where channel 1 with the measured value 364 is totally wrong and channel 2 with 2000 is nearly right. \$\endgroup\$ – HansPeterLoft Feb 26 '17 at 17:46
  • 2
    \$\begingroup\$ I could solve the wrong measurement problem, it was actually a bad soldering at the adc channel 1 pin. The offset of the voltage measurement is still a problem, maybe the reason is the same. \$\endgroup\$ – HansPeterLoft Feb 26 '17 at 18:44
  • \$\begingroup\$ You need to include the source in your circuit or at least state its impedance. \$\endgroup\$ – Chris Stratton Feb 26 '17 at 18:47
  • \$\begingroup\$ I updated the schematic, its a LP2985 voltage regulator. ADC2 measures the current of two shunts. \$\endgroup\$ – HansPeterLoft Feb 27 '17 at 8:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.