Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBartek Paczkowski <bpaczkowski@users.noreply.github.com>2017-11-01 01:00:57 +0300
committerdc42 <dcrocker@eschertech.com>2017-11-01 01:00:57 +0300
commit2423233e4b5d16694c84f3a9c00c5e62d910a737 (patch)
treefb1ab84c6e2e4ac2358d660608e7d0a5ec83cb0e /src
parent871c22c0c5b1c5479488014f7d428efe423c38c7 (diff)
Added support for custom MAX31865 reference resistors (#135)
* added support for custom MAX31865 reference resistors based on: https://github.com/adafruit/pt100rtd * fixed rounding error * simplified temperature calculation * reverted a change to bottom tempTable value condition it wasn't needed * increased step size of the max31865 tempTable * fixed the R parameter of max31865 gcode setup * added current ref resistor to max31865 info output
Diffstat (limited to 'src')
-rw-r--r--src/Heating/Sensors/RtdSensor31865.cpp99
1 files changed, 42 insertions, 57 deletions
diff --git a/src/Heating/Sensors/RtdSensor31865.cpp b/src/Heating/Sensors/RtdSensor31865.cpp
index 79349d5c..07ca0474 100644
--- a/src/Heating/Sensors/RtdSensor31865.cpp
+++ b/src/Heating/Sensors/RtdSensor31865.cpp
@@ -10,6 +10,9 @@
#include "Platform.h"
#include "GCodes/GCodeBuffer.h"
+short RRef = 400; // default value of the reference resistor
+const short CelsiusMin = -200; // minimum temperature of the temp table below
+
const uint32_t MAX31865_Frequency = 4000000; // maximum for MAX31865 is also 5MHz
// SPI modes:
@@ -33,53 +36,28 @@ const uint32_t MinimumReadInterval = 100; // minimum interval between reads, in
const uint8_t DefaultCr0 = 0b11000011;
const uint8_t Cr0ReadMask = 0b11011101; // bits 1 and 5 auto clear, so ignore the value read
-// Table of temperature vs. MAX31865 result for PT100 thermistor, from the MAX31865 datasheet
-struct TempTableEntry
+// pt100rtd list of resistances v temperature
+//
+// DIN 43760 / IEC 751 resistance values (ohms) were multiplied by 100 and
+// converted to 16 bit unsigned integers with no loss of accuracy.
+//
+// Examples:
+// 1852 represents 18.52 ohms and corresponds to a temperature of -200C.
+// 10000 ==> 100.00 ohms @ 0C
+// 13851 ==> 138.51 ohms @ 100C
+static const uint16_t tempTable[] =
{
- int16_t temperature;
- uint16_t adcReading;
-};
-
-static const TempTableEntry tempTable[] =
-{
- {-30, 7227},
- {-20, 7550},
- {-10, 7871},
- {0, 8192},
- {10, 8512},
- {20, 8830},
- {30, 9148},
- {40, 9465},
- {50, 9781},
- {60, 10096},
- {70, 10410},
- {80, 10723},
- {90, 11035},
- {100, 11346},
- {110, 11657},
- {120, 11966},
- {130, 12274},
- {140, 12582},
- {150, 12888},
- {160, 13194},
- {170, 13498},
- {180, 13802},
- {190, 14104},
- {200, 14406},
- {225, 15156},
- {250, 15901},
- {275, 16639},
- {300, 17371},
- {325, 18098},
- {350, 18818},
- {375, 19533},
- {400, 20242},
- {425, 20945},
- {450, 21642},
- {475, 22333},
- {500, 23018},
- {525, 23697},
- {550, 24370}
+ 1852, 2283, 2710, 3134, 3554, 3972, 4388, 4800, 5211, 5619,
+ 6026, 6430, 6833, 7233, 7633, 8031, 8427, 8822, 9216, 9609,
+ 10000, 10390, 10779, 11167, 11554, 11940, 12324, 12708, 13090, 13471,
+ 13851, 14229, 14607, 14983, 15358, 15733, 16105, 16477, 16848, 17217,
+ 17586, 17953, 18319, 18684, 19047, 19410, 19771, 20131, 20490, 20848,
+ 21205, 21561, 21915, 22268, 22621, 22972, 23321, 23670, 24018, 24364,
+ 24709, 25053, 25396, 25738, 26078, 26418, 26756, 27093, 27429, 27764,
+ 28098, 28430, 28762, 29092, 29421, 29749, 30075, 30401, 30725, 31048,
+ 31371, 31692, 32012, 32330, 32648, 32964, 33279, 33593, 33906, 34218,
+ 34528, 34838, 35146, 35453, 35759, 36064, 36367, 36670, 36971, 37271,
+ 37570, 37868, 38165, 38460, 38755, 39048
};
const size_t NumTempTableEntries = sizeof(tempTable)/sizeof(tempTable[0]);
@@ -110,10 +88,16 @@ bool RtdSensor31865::Configure(unsigned int mCode, unsigned int heater, GCodeBuf
}
}
+ if (gb.Seen('R'))
+ {
+ seen = true;
+ RRef = (short)gb.GetIValue();
+ }
+
if (!seen && !gb.Seen('X'))
{
CopyBasicHeaterDetails(heater, reply);
- reply.catf(", reject %dHz", (cr0 & 0x01) ? 50 : 60);
+ reply.catf(", reject %dHz, reference resistor: %d ohms", (cr0 & 0x01) ? 50 : 60, RRef);
}
}
return false;
@@ -206,18 +190,18 @@ TemperatureError RtdSensor31865::GetTemperature(float& t)
}
else
{
- const uint16_t adcVal = (rawVal >> 1) & 0x7FFF;
+ const float ohmsx100 = ((rawVal >> 1) & 0x7FFF) * RRef / 32768.0 * 100;
// Formally-verified binary search routine, adapted from one of the eCv examples
size_t low = 0u, high = NumTempTableEntries;
while (high > low)
keep(low <= high; high <= NumTempTableEntries)
- keep(low == 0u || tempTable[low - 1u].adcReading < adcVal)
- keep(high == NumTempTableEntries || adcVal <= tempTable[high].adcReading)
+ keep(low == 0u || tempTable[low - 1u] < ohmsx100)
+ keep(high == NumTempTableEntries || ohmsx100 <= tempTable[high])
decrease(high - low)
{
size_t mid = (high - low)/2u + low; // get the mid point, avoiding arithmetic overflow
- if (adcVal <= tempTable[mid].adcReading)
+ if (ohmsx100 <= tempTable[mid])
{
high = mid;
}
@@ -227,8 +211,8 @@ TemperatureError RtdSensor31865::GetTemperature(float& t)
}
}
assert(low <= NumTempTableEntries);
- assert(low == 0 || tempTable[low - 1] < adcVal);
- assert(low == NumTempTableEntries || adcVal <= tempTable[low]);
+ assert(low == 0 || tempTable[low - 1] < ohmsx100);
+ assert(low == NumTempTableEntries || ohmsx100 <= tempTable[low]);
if (low == 0) // if off the bottom of the table
{
@@ -240,10 +224,11 @@ TemperatureError RtdSensor31865::GetTemperature(float& t)
}
else
{
- const float interpolationFraction = (float)(adcVal - tempTable[low - 1].adcReading)/(float)(tempTable[low].adcReading - tempTable[low - 1].adcReading);
- t = lastTemperature = ((float)(tempTable[low].temperature - tempTable[low - 1].temperature) * interpolationFraction)
- + (float)tempTable[low - 1].temperature;
- //debugPrintf("raw %u low %u interp %f temp %f\n", adcVal, low, interpolationFraction, *t);
+ const float temperatureFraction = (float)(ohmsx100 - tempTable[low - 1])/(float)(tempTable[low] - tempTable[low - 1]);
+
+ t = lastTemperature = 10 * (low - 1) + CelsiusMin + 10 * temperatureFraction;
+
+ //debugPrintf("raw %f low %u temp %f\n", ohmsx100, low, t);
lastResult = TemperatureError::success;
}
}