cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE Voltage Sensor with STM32F103C8T6

i_am_sandy
Associate II

The is voltage sensing in live expression I'm using STM32F103C8T6 board popularly known as blue pill im using a voltage divider the supply is given from the power supply and the ADC pin i use is B1 from the power supply when i give less than 2V the output in the live expression is accurate but when i give more than 2V and less than 3.3V it is not correct and for example if i give 3.3V in the live expression the output shows is 5.1345V how to resolve this problem any ideas gentlemen's 

3 REPLIES 3

Note that the chances of a Blue Pill containing a genuine STM32 are vanishingly small.

It's quite possible that a fake STM32 could have weird ADC behaviour.

The first thing to determine is whether the issue is just with the IDE and its live expression display, or in your code.

So what happens if you send your result out through a UART to a terminal?

If you see the same error doing that, then the problem is in your code.

 

Have you looked at the raw values from the ADC?

i_am_sandy
Associate II

Yes i have gone through the raw value of the ADC it correct

here is my program is there any correction

while (1)
  {
  HAL_ADC_PollForConversion(&hadc1,1000);
     readValue = HAL_ADC_GetValue(&hadc1);
     voltage =(float)readValue/4095*8.56;
     HAL_Delay(100);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
Karl Yamashita
Lead III

Are you sure the 8.56 is the correct factor? What is your voltage divider R1 and R2? What is the max input voltage to the divider?

 

try 

voltage =(float)readValue * (3.3/4096) * 8.56; // assuming Vref = 3.3V

 

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.