Monthly E-letter

Latest edition | Subscribe

Floating-point MCUs offer smart sensor calculation perks

On-chip FPUs speed up calculations and require less code in MCU smart sensor applications.

The importance of smart sensors in embedded system designs has increased due to a recent spate of R&D activity. Engineers have made progress in designing sensors that have plug-and-play capabilities and offer automatic calibration data identification and downloads. Furthermore, I/O transformation algorithms have become sophisticated enough to provide highly accurate measurements. Powerful processors are required to perform the detailed data translation calculations and handle networking protocols.

Various design issues are associated with the different methods for generating accurate sensor readings from measured analog-to-digital Converter (ADC) values. These methods can be illustrated by a sample application with a simple Type J thermocouple (Figure 1) as the input. This sensor can measure temperature from 0 ∞C to 760 ∞C and produce a temperature measurement output with a range of 0 mV to 42.9 mV.

Figure1
Figure 1
(click graphic to zoom by 1.7x)

The temperature computation

Translating the thermocouple’s mV reading into the proper temperature ∞C value requires the use of a seventh- or higher-order polynomial equation, with specific values for the equation’s coefficients. The nonlinear relationship between the temperature at the thermocouple’s junction and the voltage differential is approximated by this equation:

Sidebar1
Sidebar 1
(click graphic to zoom by 1.5x)

The coefficients Dn are shown in Table 1, courtesy of the National Institute of Standards and Technology ITS-90 Table for Thermocouples Coefficients of Approximate Inverse Functions.

Table1
Table 1
(click graphic to zoom by 1.5x)

In the smart sensor, a processor with an on-chip ADC measures the voltage X and then converts it into the digital data of its proper temperature value using the nonlinear equation.

Conversion techniques

Four different transformation methods apply this equation to generate digital temperature readings from measured ADC values.

Lookup table

The simplest way to translate from mV to ∞C is to create a lookup table that uses the measured ADC value from the thermocouple as an index. Table 2 lists the ADC values and the corresponding differential voltages and temperatures, represented as a 4-byte floating-point value.

Table2
Table 2

The table lookup method is the fastest approach in terms of CPU execution time. Its drawback is the array size, which results in a large amount of code requiring a substantial amount of memory for storage. When a 10-bit ADC is used, the array index is 1,024, and the resulting array is 4,096 bytes (4 KB). If a 12-bit ADC is used, the array size grows to 16 KB. For a 16-bit ADC, the array size will be 64 KB.

Integer arithmetic

Integer (fixed-point) mathematics can be used to compute temperature from the measured ADC value. If the processor in the smart sensor has a register 32 bits long, each fixed-point coefficient is expressed as a whole number and fractional number with a suitable place for the demarcation point. (The demarcation point is generally known as decimal point in the decimal world or a binary point in the computer realm.)

For this sample thermocouple design, the binary point was set at 20 bits. Thus the fractional part of the temperature value is represented by the 20 lower-order bits, and the integer part is represented by the 12 higher-order bits with a sign, as shown in Figure 2. For example, the number 26.54 has two components in integer math: 26 is represented in the integer part, while 54 is represented in the fractional part (as a sum of 1/2, 1/4, 1/8, 1/16, 1/32, and so on).

Figure2
Figure 2
(click graphic to zoom by 1.6x)

Since the first bit is a sign bit, the range of integer numbers in this format is from -2,048 to 2,048. After each coefficient is converted into its proper format, the measured ADC values are computed using the aforementioned equation. To preserve the proper integer and fractional parts in the result after multiplication, appropriate bit-shifting operations must be done. (These math operations are standard operations in the processor.) A disadvantage of this method is that software engineers often have difficulties understanding the code written by others.

Floating-point math library

Because of integer math’s limitations and the normalization it involves, system engineers generally prefer using a floating-point library to perform the data translation process that achieves the accurate calculations needed for proper results. However, this approach has both code size and execution time penalties. On the plus side, whenever the program is transferred from one software engineer to another, the code is easy to understand.

Simple FPU implementation

By implementing floating-point operations in FPU circuitry built into the smart sensor’s processor and using the corresponding instructions to its instruction set, designers can achieve speed and code size benefits. At minimum, the hardware FPU only needs four basic instructions: add, subtract, multiply, and divide.

As shown previously in Figure 2, the floating-point representation uses bit 31 as the sign bit, bits 23-30 as the exponent, and the remaining bits as the fractional part. Once again using 26.54 as an example, this number is transformed as 0.2654 x 10^2, where the exponent is 2 and the fractional part is 2654.

When two floating-point numbers are multiplied, the result is expressed as exponent and mantissa and proper normalization is done. This representation handles a much larger range of numbers than integer math can, yet still preserves accuracy. Therefore, performing calculations using a processor with an on-chip FPU offers advantages with regard to range and normalization.

Evaluating sensor calculation methods

To obtain design data useful for comparing the lookup table, fixed-point math, software library, and floating-point math sensor calculation methods, programs for each were coded in C in the Renesas High-performance Embedded Workshop development environment. The R32C/111, a device in the R32C/100 microcontroller series, was selected as the target. This MCU provides the four basic instructions – add, subtract, multiply and divide – plus three more – compare, convert to float, and convert to integer, as shown in Table 3.

Table3
Table 3
(click graphic to zoom by 1.7x)

Besides an IEEE 754 FPU, this low-cost microcontroller features power-efficient operation from 3 V to 5 V, a memory interface for up to 16 MB, and up to 512 KB of flash and 63 KB of SRAM. The set of on-chip peripheral functions this MCU provides is illustrated in Figure 3.

Figure3
Figure 3
(click graphic to zoom by 1.6x)

Code size and execution speeds were measured with this microcontroller running at a 32 MHz clock. All measurements were kept identical for consistency and proper comparison. Table 4 shows the test results both in their basic form and in a comparative form that uses fixed-point integer math as a base.

Table4
Table 4
(click graphic to zoom by 1.7x)

On-chip FPUs make a difference

As pointed out earlier, the lookup table method is the quickest conversion technique, operating about 14x faster than the base method. However, lookup table requires a great deal of code; code size is almost 28x that of the integer math method. For example, when the microcontroller has to handle eight sensors with its 10-bit ADC, code size is more than 32 KB due to tables. The R32C/111 device has an ADC with 26 channels. If all of these channels are used to make measurements, the code size will be 104 KB for data plus the basic code size for the lookup table. Of course, processor cost rises as the on-chip memory requirements increase.

The test data for making sensor calculations with a software library reveals that this method is very slow and requires a significant amount of code. Execution time is 6x slower than the fixed-point math method, and code size is 12x bigger.

When the FPU instructions in the R32C/111 microcontroller were applied to perform the Type J thermocouple translations, the smallest code size was achieved, along with an increase in speed compared to the integer math approach. The FPU-based calculations were 3x faster and required about 75 percent less code.

As seen from these results, an MCU with an on-chip FPU used in a smart sensor application can provide a substantial system design advantage in the form of optimized computational time and memory requirement benefits.

Yashvant Jani is director of applications engineering at Renesas Technology America, a U.S. subsidiary of Tokyo-based Renesas Technology Corp. He has more than 15 years of experience in embedded systems, with the past four years focused on advanced motor control applications, including developing and testing vector control for brushless DC motors. A regular presenter at Embedded Systems Conference, Yashvant has taught seminars on networking, VoIP, and brushless DC motors. Prior to joining Renesas, Yashvant participated in the development of integrated guidance, navigation, and control systems for several NASA space shuttle programs. He received his PhD in Physics from the University of Texas at Dallas in 1976.

Renesas Technology
408-382-7500
yashvant.jani@renesas.com
www.renesas.com

©MMX Industrial Embedded Systems.
An OpenSystems Media publication.