multilinear sensor / sensor table for M308
-
The linear-analog sensor type M308 offers is very helpful when dealing with custom temperature sensors or temperature sensors with preamplifiers.
But it is not precise enough if you happen to upgrade a printer that was previously running Marlin (Marlin allows the user to define a complete sensor table which makes it possible to use any sensor, regardless how weird its curve might be).
My sugfestion would be therefore to enhance the current "linear-analog" sensor option to accept more than two reference values, for example by replacing the current B and C parameter with two new parameters that allow value pairs to be defined, with some useful upper limit for these values that the Duet can accept.
Here is an example:
Current notation for a perfectly linear sensor:M308 Y"linear-analog" F1 B-20 C380
for a linear sensor where ADC=0 at -20°C and ADC=full scale at 380°C
Suggested new notation with a new parameter "X" = list of temperature or other value and "Y" = list of ADC factor between 0 and 1:
- if it is the linear sensor from above:
M308 "linear-analog" F1 X-20:380 Y0:1
- if the sensor from above would happen to have one linear curve above 100°C and another linear curve below 100°C (i.e. it is a bilinear sensor), reading accuracy could be enhanced by adding a third value pair, where one linear section ranges from -20°C = ADC 0 to 100°C = 0.27 times ADC full scale, and the second linear section ranges from 100°C = 0.27 times ADC full scale to 380 °C = 1 times ADC full scale:
M308 "linear-analog" F1 X-20:100:380 Y0:0.27:1
- if you require more value pairs, you simply add them by choosing suitable value pairs from the sensor curve in your data sheet (your favourite spreadsheet calculation program might help you choosing the most suitable ones), e.g.
M308 "linear-analog" F1 X-20:100:280:380 Y0:0.27:0.73:1
From my experience, you are able to cover almost all sensors and amplifiers with a reasonable accuracy already when using up to eight value pairs = seven sections, since sensors and analogue amplifiers always have a "largely linear" amplification curve which is either slightly curved or has a slight "S" shape. Therefore, very long lists should not be needed.
Here are some picture from the Snapmaker J1 that I am currently working on which uses PT100 temperature sensors on the swappable hotend modules followed by a preamplifier in the hotend. The curve is based on the Marlin temperature sensor table of that printer that I simply imported into Excel. A linear interpolation causes significant errors of more than 10°C in the lower temperature range if you wantr it to work reasonably correct in the "printing-critical" temperature range. The option to define a bilinear curve would suffice to improve this - with a trilinear curve I could recreate the curve almost completely exact:
(edit: corrected swapped X and Y values in the examples, clarified the text and added example pictures)
-
-
Update: in case someone might need it, this request is partially solved thanks to the new M308 U and V parameters - at least if the required switching speed between the areas can be slow enough to be handled by daemon.g.