This commit is contained in:
cfif 2025-12-04 10:51:44 +03:00
parent 5850efbe00
commit 26f1bf2f1e
1 changed files with 2 additions and 2 deletions

View File

@ -204,7 +204,7 @@ static adc_temp_lookup fast_lookup[TABLE_SIZE_LOOKUP]; // Таблица на TA
void init_fast_lookup_table(eAlg use_alg) {
// Создаем таблицу для быстрого преобразования АЦП->температура
for (uint16_t i = 0; i < TABLE_SIZE_LOOKUP; i++) {
uint16_t adc = i * (uint8_t)roundf(4095.0f / (TABLE_SIZE_LOOKUP - 1)); // Для 12-битного АЦП (0-4095)
uint16_t adc = i * (uint8_t)roundf(ADC_MAX / (TABLE_SIZE_LOOKUP - 1)); // Для 12-битного АЦП (0-4095)
float temp = get_temperature_from_adc_KST45(adc, use_alg);
fast_lookup[i].adc_value = adc;
fast_lookup[i].temp_c = (int16_t) (temp * 10.0f); // Храним с точностью 0.1°C
@ -213,7 +213,7 @@ void init_fast_lookup_table(eAlg use_alg) {
int16_t get_temperature_fast_KST45(uint16_t adc_value) {
// Простой поиск в таблице с линейной интерполяцией
uint16_t index = adc_value / (uint8_t)roundf(4095.0f / (TABLE_SIZE_LOOKUP - 1)); // Делим на 16 для TABLE_SIZE_LOOKUP = 256
uint16_t index = adc_value / (uint8_t)roundf(ADC_MAX / (TABLE_SIZE_LOOKUP - 1)); // Делим на 16 для TABLE_SIZE_LOOKUP = 256
if (index >= (TABLE_SIZE_LOOKUP - 1)) return fast_lookup[TABLE_SIZE_LOOKUP - 1].temp_c;
uint16_t adc1 = fast_lookup[index].adc_value;