본문 바로가기

[STM32F746G-DISCO] 칩 내부 온도센서 사용하기

by rudals.kim 2024. 7. 14. 댓글 개
반응형
아래 테스트는 STM32CubeIDE 1.6.1/STM32Cube_FW_F7_V1.16.1를 사용하여 테스트 되었습니다.


STM32F746NG 내부에는 디바이스 주변의 온도를 측정할 수 있는 온도센서가 내장되어 있습니다.
이 온도 센서는 ADC1_18에 연결되어 있는데 내부 온도센서 또는 배터리 측정에 사용됩니다.
-40 ℃ ~ 125 ℃ 까지 측정 가능하며 정확도는 ±1.5 ℃ 입니다.

데이터시트를 살펴보면 아래와 같이 내부 온도센서를 읽는 방법이 나와 있습니다.

1. Select ADC1_IN18 input channel.
2. Select a sampling time greater than the minimum sampling time specified in the datasheet.
3. Set the TSVREFE bit in the ADC_CCR register to wake up the temperature sensor from power down mode
4. Start the ADC conversion by setting the SWSTART bit (or by external trigger)
5. Read the resulting VSENSE data in the ADC data register
6. Calculate the temperature using the following formula:
Temperature (in ℃) = {(VSENSE – V25 ) / Avg_Slope} + 25

Where:
– V25 = VSENSE value for 25 ℃
– Avg_Slope = average slope of the temperature vs. VSENSE curve (given in mV/°C or µV/°C)

V25 and Avg_Slope 값은 아래 데이터시트에서 주어지는 전압 및 온도 특성 값을 참고하시면 됩니다.

아래와 같이 adc에서 읽어 들인 값을 위 데이터 시트에 나와있는 수식에 적용하여 온도를 계산합니다.

MX_ADC1_Init();
 
/* USER CODE BEGIN 2 */
printf("ADC1_IN18 TEST\r\n");
 
HAL_ADC_Start(&hadc1);
/* USER CODE END 2 */
 
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
  if (HAL_ADC_PollForConversion(&hadc1, 1000000) == HAL_OK)
    {
        adc_value = HAL_ADC_GetValue(&hadc1);
        temperature = adc_value * 3.3 / 0xfff;
        temperature = (temperature-0.76)/0.0025 + 25.0;
        printf("Temperature : %5.1f\r\n", temperature);
    }
      HAL_Delay(500);
/* USER CODE END WHILE */
 
/* USER CODE BEGIN 3 */
 
}
/* USER CODE END 3 */


실행해 보면 아래와 같이 내부 온도 센서의 값을 읽어 오고 있습니다.
처음 다운로드시는 33도 정도에서 시작되었으나 시간이 지나감에 따라 조금씩 온도가 올라가 40도 근처까지 올라가네요.

ADC1_IN18 TEST
Temperature : 33.4
Temperature : 33.4
Temperature : 33.7
Temperature : 34.0
Temperature : 34.3
Temperature : 34.3
Temperature : 34.6
Temperature : 36.3
Temperature : 35.3
Temperature : 35.6
Temperature : 35.3

반응형

댓글