I've done an implementation with
https://www.ti.com/product/LMT86
https://www.ti.com/lit/gpn/lmt86
using stm32duino
https://github.com/stm32duino/Arduino_Core_STM32
https://github.com/stm32duino/wiki/wiki
The sketch is like such.
This should work on a stm32f4xx e.g. stm32f411 Nucleo board or Adafruit STM32F405 Feather Express
The alternatives are like stm32f401/f411 blackpill board (these boards can be searched on AliExpress/eBay) etc.
STM32f4xx series is preferred for this due to the availability of an FPU in the SOC.
That 4 functions in the middle is the Newton–Raphson method to solve the quadratic equation as given in the specs.
It takes about a hundred newton iterations average in single precision floating point to converge to 0.001 C precision.
It is pretty fast on stm32f401 84 MHz, there is hardly any delay waiting for a converged figure.
But accordingly Newton's method may not converge at times, for now it seems stable and converges for a last half hour of run.
The FPU in stm32f401 is perfect for such, it saves encoding a big table. This kind of iterative stuff used to be done on bigger computers, it is cool that microcontrollers are fast enough for all these and close to real time.
I'd refrain from publishing this as a library, and I'd like to put in a note of caution as Newton's method is susceptible to numerical issues, some related to the functions, others related to degenerate floating point issues and may not converge. It has been working for me tested for days running on it, but there is no assurance that it'd always converge for all values. Hence, you'd need to test it yourself if you want to use it. i.e. this is possibly not safe to use in a safety related context. e.g. if you use it as input to a feedback loop, if it stalls in the loop, you could possibly imagine your heater going to very high temperatures possibly causing fires while it goes in an infinite loop and don't converge, providing no temperature values to the app. However, Newton's method is known to be a fast converging solver if it finds a solution.
This would possibly run on other lines e.g. those without an FPU, but likely slower.
https://www.ti.com/product/LMT86
https://www.ti.com/lit/gpn/lmt86
using stm32duino
https://github.com/stm32duino/Arduino_Core_STM32
https://github.com/stm32duino/wiki/wiki
The sketch is like such.
stm32duino sketch:
#include <Arduino.h>
#include <math.h>
void setup() {
Serial.begin();
pinMode(LED_BUILTIN, OUTPUT);
// we need all 12 bits
analogReadResolution(12);
pinMode(PA0, INPUT_ANALOG);
}
float f(float t, float v) {
return 1777.3F - (10.888*(t-30)) - 0.00347*(t-30.0F)*(t-30.0F) - v;
}
float df(float t) {
return -10.888*t - 0.00347*2*(t-30.0F);
}
float nstep(float t, float v) {
return t - f(t,v) / df(t);
}
#define TOLERANCE 0.005
float newton(float v) {
float t0 = 30.0F;
float t;
uint16_t n = 0;
while(true) {
t = nstep(t0, v);
n++;
if(fabs(t-t0) < TOLERANCE)
break;
t0 = t;
}
// Serial.print("loop ");
// Serial.println(n);
return t;
}
void loop() {
digitalToggle(LED_BUILTIN);
Serial.print("pa0:");
uint16_t val = analogRead(PA0);
Serial.print(val);
Serial.print(", ");
float mv = 3.3 * (float) val * 1000.0 / 4096.0;
Serial.print(mv);
Serial.print("mV, ");
float temp = newton(mv);
Serial.print(temp);
Serial.println(" deg C");
delay(1000);
}
The alternatives are like stm32f401/f411 blackpill board (these boards can be searched on AliExpress/eBay) etc.
STM32f4xx series is preferred for this due to the availability of an FPU in the SOC.
That 4 functions in the middle is the Newton–Raphson method to solve the quadratic equation as given in the specs.
It takes about a hundred newton iterations average in single precision floating point to converge to 0.001 C precision.
It is pretty fast on stm32f401 84 MHz, there is hardly any delay waiting for a converged figure.
But accordingly Newton's method may not converge at times, for now it seems stable and converges for a last half hour of run.
The FPU in stm32f401 is perfect for such, it saves encoding a big table. This kind of iterative stuff used to be done on bigger computers, it is cool that microcontrollers are fast enough for all these and close to real time.
I'd refrain from publishing this as a library, and I'd like to put in a note of caution as Newton's method is susceptible to numerical issues, some related to the functions, others related to degenerate floating point issues and may not converge. It has been working for me tested for days running on it, but there is no assurance that it'd always converge for all values. Hence, you'd need to test it yourself if you want to use it. i.e. this is possibly not safe to use in a safety related context. e.g. if you use it as input to a feedback loop, if it stalls in the loop, you could possibly imagine your heater going to very high temperatures possibly causing fires while it goes in an infinite loop and don't converge, providing no temperature values to the app. However, Newton's method is known to be a fast converging solver if it finds a solution.
This would possibly run on other lines e.g. those without an FPU, but likely slower.