Changed temperature calculation mechanism

This commit is contained in:
Yury Shuvakin
2024-08-06 17:11:59 +09:00
parent c355331033
commit 697aa42977
4 changed files with 85 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
/build /build
*.pro.user *.pro.user
TkrMonitor.pro.user

View File

@@ -123,7 +123,8 @@ void MainWindow::handlePackage(int index)
coolantTemperatureIndex = 0; coolantTemperatureIndex = 0;
} }
qint16 coolantTemperature = FlashTdegr[coolantTemperatureIndex << 2] - 55; coolantTemperatureIndex = coolantTemperatureIndex << 2;
qint16 coolantTemperature = adcToTemperature(coolantTemperatureIndex);
parameterModel_->setItem(5, 1, new QStandardItem(QString::number(coolantTemperature))); parameterModel_->setItem(5, 1, new QStandardItem(QString::number(coolantTemperature)));
quint16 outputPhaseCurrent = (message->getByte(3) << 2) + ((message->getByte(7) & 0x0C) >> 2); quint16 outputPhaseCurrent = (message->getByte(3) << 2) + ((message->getByte(7) & 0x0C) >> 2);
@@ -290,3 +291,80 @@ QString MainWindow::statusToDescription(quint8 status)
return description; return description;
} }
qint16 MainWindow::adcToTemperature(quint16 adc)
{
const double vref = 2.5; // Напряжение опорное
const double vin = 5.0; // Входное напряжение
const double r = 10000; // Сопротивление резистора в Омах (например, 10kΩ)
// Преобразуем значение АЦП в выходное напряжение
double vout = (adc / 4095.0) * vref;
// Проверяем, чтобы Vout не было равно Vin
if (vout >= vin)
{
return 0; // Ошибка: Vout не может быть больше или равно Vin
}
// Вычисляем сопротивление термистора
double r_ntc = r * (vout / (vin - vout));
QList<QPair<qint16, double>> temp_table =
{
{-55, 96.3},
{-50, 67.01},
{-45, 47.17},
{-40, 33.65},
{-35, 24.26},
{-30, 17.7},
{-25, 13.04},
{-20, 9.707},
{-15, 7.293},
{-10, 5.533},
{-5, 4.232},
{0, 3.265},
{5, 2.539},
{10, 1.99},
{15, 1.571},
{20, 1.249},
{25, 1.0},
{30, 0.8057},
{35, 0.6531},
{40, 0.5327},
{45, 0.4369},
{50, 0.3603},
{55, 0.2986},
{60, 0.2488},
{65, 0.2083},
{70, 0.1752},
{75, 0.1481},
{80, 0.1258},
{85, 0.1072},
{90, 0.09177},
{95, 0.07885},
{100, 0.068},
{105, 0.05886},
{110, 0.05112},
{115, 0.04454},
{120, 0.03893},
{125, 0.03417},
{130, 0.03009},
{135, 0.02654},
{140, 0.02348},
{145, 0.02083},
{150, 0.01853},
{155, 0.01653},
};
for (qsizetype i = 0; i < temp_table.size() - 1; i++)
{
if (r_ntc <= temp_table[i].second && r_ntc >= temp_table[i + 1].second)
{
return temp_table[i].first + (temp_table[i + 1].first - temp_table[i].first) *
(r_ntc - temp_table[i].second) / (temp_table[i + 1].second - temp_table[i].second);
}
}
return 0;
}

View File

@@ -35,6 +35,8 @@ private:
QString statusToString(quint8 status); QString statusToString(quint8 status);
QString statusToDescription(quint8 status); QString statusToDescription(quint8 status);
qint16 adcToTemperature(quint16 adc);
Ui::MainWindow* ui = nullptr; Ui::MainWindow* ui = nullptr;
QStandardItemModel* parameterModel_ = nullptr; QStandardItemModel* parameterModel_ = nullptr;
QStandardItemModel* statusModel_ = nullptr; QStandardItemModel* statusModel_ = nullptr;

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 13.0.2, 2024-07-06T23:05:55. --> <!-- Written by QtCreator 14.0.0, 2024-08-06T16:11:01. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@@ -69,7 +69,9 @@
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value> <value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
<value type="bool" key="AutoTest.Framework.QtTest">true</value> <value type="bool" key="AutoTest.Framework.QtTest">true</value>
</valuemap> </valuemap>
<value type="bool" key="AutoTest.ApplyFilter">false</value>
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/> <valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
<value type="int" key="AutoTest.RunAfterBuild">0</value> <value type="int" key="AutoTest.RunAfterBuild">0</value>
<value type="bool" key="AutoTest.UseGlobal">true</value> <value type="bool" key="AutoTest.UseGlobal">true</value>
<valuemap type="QVariantMap" key="ClangTools"> <valuemap type="QVariantMap" key="ClangTools">