Solved
Thermistor reading error with ADC1
Post edited by ST moderator to be inline with the community rules especially with the code sharing.
1- In next time please use </> button to paste your code. Please read this post: How to insert source code.
2- Post is not related to CubeIDE usage but more to the product so it needs to be moved to "STM32 MCUs Products" forum. So please don't post your question in CubeIDE only if it's related to CubeIDE usage or to raise a limitation in it.
I have a 110k resistor in series with a 110k thermistor as well, at the midpoint I connect PC0, the other leg of the thermistor to 3.3v, the sConfig.SamplingTime is 247.5. But the readings are 110 Celsius when it should read 22 Celsius, what am I doing wrong, this is my code, thanks
define R_SERIE 115000.0f // resistor fijo del divisor
#define BETA 3950.0f // coef. beta del NTC
#define T0 298.15f // 25 °C en Kelvin
#define R0 115000.0f // resistencia nominal NTC a 25°C
ADC_HandleTypeDef hadc1;
volatile uint16_t adc_val = 0;
volatile float temperature = 0.0f;
volatile int setpoint = 30;
float NTC_ReadTemperature(void)
{
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
uint32_t adc_val = HAL_ADC_GetValue(&hadc1);
float vref = 3.3f;
float v_adc = (vref * adc_val) / 65535.0f;
float r_ntc = (R_SERIE * v_adc) / (vref - v_adc);
float tempK = 1.0f / ((1.0f / T0) + (1.0f / BETA) * logf(r_ntc / R0));
return tempK - 273.15f;
}
