MODEL_ADC_EX/APP/inc/ADC_Temp.h

61 lines
2.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Created by cfif on 04.12.2025.
//
#ifndef MDF_ADC_TEMP_KST45_14_2_H
#define MDF_ADC_TEMP_KST45_14_2_H
#include <stdint.h>
// Константы
#define ADC_MAX 4095.0f // 12-битный АЦП
// Параметры Steinhart-Hart для термистора
#define koef_A 0.001741624168166423
#define koef_B 0.00017003940268680147
#define koef_C 0.0000004890545443703666
#define TABLE_SIZE_LOOKUP 1024
// Типы таблиц NTC
typedef enum {
NTC_TYPE_KST45 = 0, // Таблица из документа KST45 (25°C = 3kΩ)
NTC_TYPE_INCAR = 1, // Таблица из документа Incar (25°C = 2795Ω)
NTC_TYPE_CUSTOM = 2 // Пользовательская таблица
} eNtcTableType;
// Структура для хранения табличных данных
typedef struct {
int16_t temp_c; // Температура (°C)
float r_nom; // Номинальное сопротивление (Ω)
} ntc_table_entry;
typedef enum {
ALG_STEINHART = 0,
ALG_STEINHART_FULL = 1,
ALG_LINEAR = 2
} eAlg;
// Предварительно вычисленная таблица для быстрого доступа
typedef struct {
uint16_t adc_value; // Значение АЦП
int16_t temp_c; // Температура в °C * 10 (для фиксированной точки)
float resistance; // Сопротивление термистора в Омах
} adc_temp_lookup;
// Функции инициализации и конфигурации
void init_fast_lookup_table(eAlg use_alg, eNtcTableType table_type, float custom_r1);
void set_custom_ntc_table(const ntc_table_entry* table, uint16_t size, float r1);
void select_ntc_table(eNtcTableType table_type, float custom_r1);
// Основные функции
float get_temperature_from_adc(uint16_t adc_value, eAlg alg);
int16_t get_temperature_fast(uint16_t adc_value);
float get_resistance_from_adc(uint16_t adc_value);
float get_resistance_fast(uint16_t adc_value);
// Функции для работы с текущей таблицей
eNtcTableType get_current_table_type(void);
float get_current_r1(void);
#endif //MDF_ADC_TEMP_KST45_14_2_H