Let’s wrap up our recent discussion of how to get accurate real-time measurements from a thermocouple or other sensor. I first discussed the problem and the fact that the relationship between temperature and voltage is nonlinear with a thermocouple, and described the polynomial that could deliver accurate results. I followed that post with a look at the brute-force approach to reading accurate temperatures with an ADC integrated on a microcontroller (MCU) such as the Renesas RX. A pre-calculated conversion table stored in memory may be a good choice in some applications. But for a minimum memory footprint, and therefore minimum system cost, your design must calculate the polynomial in real-time and a floating-point unit (FPU) can greatly accelerate that task.
You can certainly calculate a polynomial expression with a fixed-point MCU. The programmer must take care in coding the algorithm. First the constants or coefficients for each degree or order of the polynomial must be converted into a format conducive to integer math. Typically a portion of a 32-bit representation is the integer part of the constant and another portion is the fractional component. One such format would use a sign bit, 11 bits to represent the integer, and 20 bits to represent the fraction.
The algorithm would have to calculate each term of the polynomial. And each term would have be precisely shifted before the terms can be added. The integer approach can certainly work in some applications.
Alternatively, a programmer working with a fixed-point MCU could rely on a floating point library. The library handles the complex formatting and shifting operations. But the library approach won’t likely yield compact code or optimal performance.
A programmer using a floating point MCU such as the RX has a relatively simple task. In the case of the RX MCU, floating point add instructions execute in four to five clock cycles and multiply instructions can take one cycle less.
Renesas application engineers performed some benchmarks to accurately project both the code size and execution time associated with the different approaches that we’ve discussed to deriving accurate temperature readings. The tests included both the pre-calculated table stored in memory, and the three approaches that we’ve discussed here today to calculate the polynomial in real time
The tests were based on evaluating a 5th order polynomial. And the test were run on an MCU operating at 32 MHz. The table below summarizes the results. The table-look-up approach is the fastest, but has a huge impact on code size. The library approach is clearly a poor choice. Fixed-point math could work in some applications, but the clear winner is using an FPU. The MCU with FPU handles the task in 7 µsecs using only 38 bytes of code.
This blog post was originally published on the Renesas Rulz Doctor Micro blog.
Post a Comment