Changed temperature calculation mechanism
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
|
||||
/build
|
||||
*.pro.user
|
||||
TkrMonitor.pro.user
|
||||
|
||||
@@ -123,7 +123,8 @@ void MainWindow::handlePackage(int index)
|
||||
coolantTemperatureIndex = 0;
|
||||
}
|
||||
|
||||
qint16 coolantTemperature = FlashTdegr[coolantTemperatureIndex << 2] - 55;
|
||||
coolantTemperatureIndex = coolantTemperatureIndex << 2;
|
||||
qint16 coolantTemperature = adcToTemperature(coolantTemperatureIndex);
|
||||
parameterModel_->setItem(5, 1, new QStandardItem(QString::number(coolantTemperature)));
|
||||
|
||||
quint16 outputPhaseCurrent = (message->getByte(3) << 2) + ((message->getByte(7) & 0x0C) >> 2);
|
||||
@@ -290,3 +291,80 @@ QString MainWindow::statusToDescription(quint8 status)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ private:
|
||||
QString statusToString(quint8 status);
|
||||
QString statusToDescription(quint8 status);
|
||||
|
||||
qint16 adcToTemperature(quint16 adc);
|
||||
|
||||
Ui::MainWindow* ui = nullptr;
|
||||
QStandardItemModel* parameterModel_ = nullptr;
|
||||
QStandardItemModel* statusModel_ = nullptr;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!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>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -69,7 +69,9 @@
|
||||
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<value type="bool" key="AutoTest.ApplyFilter">false</value>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||
<valuelist type="QVariantList" key="AutoTest.PathFilters"/>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
|
||||
Reference in New Issue
Block a user