cancel
Showing results for 
Search instead for 
Did you mean: 

I am new to micro-controller programming . I am using STM32F091RC Nucleo board. I am trying to read the temperature using NTC thermistor of 10 kOhm. I burned the code on micro-controller and tried to see the output on STM Studio.

Pinki
Associate

 But my adc_value is stuck at 59390 for some reason. I don't see any change in temperature and I am not sure if I am doing it right. Can anyone help me?

/* Private variables ---------------------------------------------------------*/

ADC_HandleTypeDef hadc;

UART_HandleTypeDef huart2;

uint16_t adc_val;

float R1, R2, R22, Tk, Tc, c1, c2, c3;

float sysTemperature, sysTemp_inmV, sysTemp_inCel;

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_ADC_Init(void);

static void MX_USART2_UART_Init(void);

/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

adc_val = HAL_ADC_GetValue(hadc);

R1 = 10000;

c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

R2 = R1 * ((4095/adc_val) - 1);

R22 = log(R2);

Tk = (1.0 / (c1 + c2*R22 + c3*R22*R22*R22));

Tc = Tk - 273.15;

HAL_ADC_Start_IT(hadc);

}

2 REPLIES 2

> 4095/adc_val

This is performed as an integer division, which is probably not what you intended. Cast adc_val to float, or use 4095.0f.

Btw., many of your calculations are going to be performed as double, suffix your constants with f and also use logf() if you want to stick to float.

JW

Ozone
Lead

I agree with Jan.

> c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

When using float, say farewell to this many decimals. Single precision is rather limited.

I suggest to observe the ADC value as raw integer first, before pondering about conversions and outputs.