2023-03-29 12:36 PM
2023-03-29 12:50 PM
sorry, press sent before post the questions.
I am using the STM32F429 chip. Try to use the internal sensor to measure temperature.
Using the HAL functions and setup
void ADC1_HandleInit(void)
{
ADC_HandleTypeDef *AdcHandle = &TemperatureADC.AdcHandle;
ADC_ChannelConfTypeDef *sConfig = &TemperatureADC.sConfig[0];
//
// Configure the ADC peripheral
//
AdcHandle->Instance = ADC1; // ADC1 (STM32 requirement)
AdcHandle->Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
AdcHandle->Init.Resolution = ADC_RESOLUTION_12B;
AdcHandle->Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */
AdcHandle->Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */
AdcHandle->Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */
AdcHandle->Init.NbrOfDiscConversion = 1;
AdcHandle->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
/* Conversion start trigger at each external event */
AdcHandle->Init.ExternalTrigConv = ADC_SOFTWARE_START;
AdcHandle->Init.DataAlign = ADC_DATAALIGN_RIGHT;
AdcHandle->Init.NbrOfConversion = 1;
AdcHandle->Init.DMAContinuousRequests = DISABLE;
AdcHandle->Init.EOCSelection = ADC_EOC_SINGLE_CONV;
//
sConfig->Channel = ADC_CHANNEL_TEMPSENSOR; // Temperature Sensor channel
sConfig->Rank = 1;
sConfig->SamplingTime = ADC_SAMPLETIME_480CYCLES;
sConfig->Offset = 0;
//
// Configure channel to ADC Handle
// Start ADC channel for measurement
//
if (HAL_ADC_ConfigChannel(AdcHandle, sConfig) != HAL_OK)
{
Error_Handler();
}
}
Able to get value from HAL_ADC_GetValue(&hadc1); function.
From RM0090-stm32f4xx-manual.pdf (Page 413)
Temperature (in °C) = {(VSENSE – V25) / Avg_Slope} + 25
Where:
– V25 = VSENSE value for 25° C
– Avg_Slope = average slope of the temperature vs. VSENSE curve (given in mV/°C
or μV/°C)
Refer to the datasheet’s electrical characteristics section for the actual values of V25
and Avg_Slope.
From stm32f427vg_Datasheet.pdf (Page 164)
However, when I search online, some people mention using the
My Question :
2023-03-29 02:11 PM
According to this, the two calibration points are 30 and 110 C°
2023-03-29 11:07 PM
> How does the TS_CAL fit into the equation ??
As Pavel A. said above, these are factory calibration values at two temperatures, you'll find the exact temperatures in the DS. These should give you a somewhat better result than using the generic V24/slope equation. I have a write up on this here (second part). Cube/HAL and/or Cube/LL may have a pre-chewed function using these, I don't use Cube.
> Also, I could not find the ADC_Calibration_EX function from the HAL library
Why do you think you need it? You cannot copy/paste things from the interwebs without understanding them. The ADC unit differs between the STM32 models significantly; the 'F4 ADC does not need/have explicit calibration.
JW
2023-03-30 08:47 AM
If I use the datasheet setting at 25c for calculation, to work out the ADC value I get from HAL_ADC_GetValue() where adcValue = 1056
The result of sensor_tmp ~61c
Which not making sense. Could it be the parameters in HAL_ADC_ConfigChannel() is wrong ??
#define SENSOR_ADC_MAX 4095.0
#define SENSOR_ADC_REFV 3.3
#define SENSOR_AVG_SLOPE 2.5
#define SENSOR_V25 0.76
float sensor_vol = (adcValue) * SENSOR_ADC_REFV / SENSOR_ADC_MAX;
float sensor_tmp = ((sensor_vol - SENSOR_V25) *1000 / SENSOR_AVG_SLOPE) + 25.0;
2023-03-31 03:18 AM
What hardware are you using? Is this a "known good" board like Nucleo or Disco?
What's the actual voltage on VREF+/VDDA pins?
JW
2023-04-02 12:50 AM
61°C is not unreasonable, it is internal temperature of the chip.
2023-04-30 11:38 AM
The issue was wrong reference value, it should be 3.0 on my board after checking.
2023-04-30 11:52 AM
There is one post weekly about internal Vtemp Vref and Vdd. I think it is time that the ST SW drivers or utility converts the calibrated/measured Vtemp and Vref into mV and DegC_x10.... that would indeed cut short development time and support...