반응형
STM32F4에서는 내부에 보정되어 어느정도 쓸만한 온도를 출력하는 ADC채널이 있다.
해당 값에 대한 정보는 Datasheet와 Reference Manual을 뒤져보면 알 수 있는데, 해당 채널을 이용하여 온도를 측정하는 코드는 대략 아래와 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | uint16_t adc_buffer[3] = {0,}; uint32_t adc_busy = 0; uint16_t *temperature_adc = &adc_buffer[0]; float temperature; uint16_t const *TS_CAL_30 = (uint16_t const *)0x1FFF7A2C; uint16_t const *TS_CAL_110 = (uint16_t const *)0x1FFF7A2E; float Map(float input, float base, float top, float mb, float mt){ float proportion = (input - base) / (top - base); float map_value = mb + (mt-mb) * proportion; return map_value; } float ADC2Volt(float adc_value){ const float normalize_in_V = 1 /4096.0f *3.3f; return adc_value * normalize_in_V; } void StartMonitorTask(void const * argument) { /* USER CODE BEGIN StartMonitorTask */ extern TIM_HandleTypeDef htim3; HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_1); HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_2); /* Infinite loop */ for(;;) { adc_busy = 1; HAL_ADC_Start_DMA(hadc, (uint32_t*)adc_buffer, 3); while(adc_busy){} /* Temperature - Celsius */ temperature = ADC2Volt(*temperature_adc); printf("Temp : %.3f\r\n", Map(*temperature_adc, *TS_CAL_30, *TS_CAL_110, 30, 110)); } } | cs |
반응형
'MCU' 카테고리의 다른 글
STM32 LwIP 구조 - 1 (0) | 2020.10.18 |
---|---|
STM32F7(Cortex-M7) 캐시 Invalidate (0) | 2020.10.17 |
원리부터 실무까지 쉽고 명확한 Arm 프로그래밍(Cortex-A9 중심으로) (0) | 2020.08.21 |
STM32 + FreeRTOS 이용시 printf를 수행하면 hardfault가 생기는 경우 (0) | 2020.02.15 |
USB ASP (0) | 2018.06.03 |
IAR EWARM에서 stm32 SWO로 printf 사용하기 (0) | 2018.03.20 |
Eclipse 기반의 AVR 개발 환경 구축하기 (0) | 2018.03.16 |