Upload
vandang
View
219
Download
2
Embed Size (px)
Citation preview
FIXED POINT VERSUS FLOATING POINT MATHEMATICS IN
EMBEDDED SYSTEM PROGRAMMING FOR FLUID POWER
MECHATRONIC COMPONENTS CONTROL: A REAL CASE STUDY
Massimiliano RUGGERI*, Matteo FRACASSI**, Massimo MARTELLI* and Massimo DIAN*
* IMAMOTER, Institute for Agricultural and Earthmoving Machines
National research Council of Italy
Via Canal Bianco 28, Ferrara, 44124 Italy
(E-mail: [email protected])
** Research and Development Dept., Tecnord S.r.l. Company
Via Malavolti 36, Modena, 41100 Italy
ABSTRACT
The increased systems complexity and performance request for electro-hydraulic applications, ask for more performing
electronic systems and control functions. The new powerful microcontrollers and efficient cross compilers, encourage
the floating point mathematics usage in the software control routines, useful to directly reuse the routines generated by
the simulation tools, despite the lack of control for precise resulting routine execution.
The paper describes a practical experience of system performance optimization on a microcontroller installed on
electro-hydraulic systems for mobile applications. A deeper analysis carried out on execution time occupied by floating
point mathematic operations, working on the software side of the mechatronic component, led to a considerably better
performance. Here it is demonstrated that, without lack of precision, fixed point mathematics are more performing, if
executed by modern microcontrollers, even if more instructions are executed by the software routines due to the
necessary rescaling of factors needed by the requested precision.
KEY WORDS
Floating Point, Fixed Point, Electronic Valve Control, Embedded Systems, Real Time
NOMENCLATURE
I : current (A)
ms : milliseconds
ns : nanoseconds
P : Pressure (bar)
µs : microseconds
Q : Flow rate (l/min)
SP : Spool Position (mm)
V : Voltage (V)
INTRODUCTION
In the last years the complexity of digital control of
electro-hydraulic components and systems increased, due
to the continuous request for better performance,
efficiency and safety. Moreover, due to the increased
quality and reliability of the simulation environment the
electronic control of Mechatronic systems is moving
away from maps and vectors towards a model based
approach, in order to model in a better way the
controlled actual systems and to reduce the dependency
330
on control parameterization. In this scenario, useful tools
allow to generate in various automatic ways C/C++
language code or pseudo-code, that can be transferred
into embedded systems compiled binary files, or in
hardware-in-the-loop platforms (HWIL), in order to test,
on the physical bench or directly in the machine, the
designed control strategies. This productivity increment
brings with it a design habit: the floating point
mathematic usage. Floating point mathematic is a
powerful method to calculate and to perform the control
actions, once the system is simulated or treated by a
HWIL powerful platform, but very difficult to be
managed by an embedded microcontroller not featuring a
Floating Point Unit (FPU). Sometimes it can be though
that a limited usage of Floating Point mathematic in a
software program doesn’t affect its real-time; this paper
demonstrates that this is normally a risky approach, due
to the high CPU load resulting from floating point to
fixed point conversions and vice-versa and due to the
uncertainty related to time required by the floating point
/ fixed point data conversion. A real case study of a
product whose control was optimized, and its
performance increased, is presented, analyzing the
performance and performance comparison from the
floating point mathematic to fixed point mathematic used
in two versions of embedded software in the mechatronic
component electronic control unit.
THE SYSTEM
The paper describes a real case study of a Two Stage
Directional Valve Spool Position Control.
The directional valve is a CAN controlled remote of an
agricultural tractor and the spool position is controlled by
a couple of three-way flow regulation valves,
electronically and independently controlled on the basis
of the spool position feedback from a contactless
position sensor. As shown in Figure 1, the two
proportional flow regulation valves are controlled by two
electronically controlled PWM signals, regulated by a
Freescale HCS12 series microcontroller, a powerful
16-bit core microcontroller widely used in mobile and
automotive applications. The only feedback related to the
position of the two proportional flow regulation valves is
the current feedback acquired through the Analog to
Digital Converter (ADC) of the microcontroller, while
the current regulation is realized through an hardware
circuitry, directly controlled by the PWM signal, by the
specialized output of the microcontroller. The two
proportional flow regulation valves are totally
independent, and can be separately controlled, in order to
increase the spool dynamic control performance. This
first stage valve configuration gives the possibility to
reduce the spool speed during transients, opening the
opposite valve in respect to the desired direction of the
spool movement, in order to avoid spool position
overshoot, that is not desirable in a flow control of
actuators. In fact a second stage spool position overshoot
can result in a damage in some applications, due to a
possible wrong actuator final position caused by an
excess of oil flow in the final stage of actuators (e.g.
hydraulic cylinders). The control module that is studied
in the paper is composed by the two first stage valves,
the electronic control unit embedded in the valves
enclosure and the second stage valve spool position
sensor. The module, called Multidrom®, is produced by
Tecnord Company and is mounted in a wide number of
directional valves and widely used both in agricultural
machines and in earthmoving and construction machines,
all over the world. The Multidrom® module adaptability
is a challenging characteristic because of the control
stability and robustness for the entire range of
applications.
In fact the control is the same for all applications, and the
tuning is realized only through a different parameter set
for each different application and valve section.
Figure 1 The Multidrom System Structure with
electro-hydraulic valves and the flow regulation spool
Figure 2 The Multidrom Module coupled with a
Directional Valve
331
THE STATE OF THE ART
The Multidrom module is produced in various versions
and it is provided with a complex control strategy that is
based on a feed forward function implementing the
model of the electro-hydraulic flow control valves and
the second stage flow regulation valve; moreover, in
order to compensate the model uncertainties and the
environment variables, a feedback function based on a
PID with variable gains and a differentiated anti-windup
strategy is implemented, coupled with the feed forward
function. The PID was optimized on a test bench and an
important dependency from oil temperature was
observed. Thus, in order to reach a good compromise
between control stability and performance various
parameter sets were defined, as a function of the second
stage configuration. From the software point of view, all
strategies, implemented in standard C language, were
written using floating point mathematics, allowed by the
Metrowerks CodeWarrior compiler and by the Freescale
microcontroller used for the application. That
mathematics setting is a modern choice, allowed by the
increased calculation power of the new microcontroller
products on the market, protects from some kind of data
type error, leaving the control for data dimension to the
microcontroller, while implies a considerably greater
time to execute the requested operations with the
Arithmetic Control Unit (ALU) of the Microcontroller.
The resulting maximum rate for the control function
execution and the necessary controls for diagnosis and
communication was 5 ms (cycle period). This 200 Hz
control frequency is apt to control a classic second stage
dynamic of the flow regulation valve coupled with
Multidrom modules, whose step response was measured
to be 110 ms from central neutral position to the
complete open position both in extend and retract
direction, as shown in Figure 3; but the control dynamic
can result unable to take advantage of the higher
dynamics of the electro-hydraulic controlled valves of
which is provided the Multidrom module. Tests
performed on a test bench demonstrated that, in some
high dynamic working condition, the control was unable
to avoid flow regulated valve spool position overflow
and that the steady state error was difficult to be
nullified; in fact the control reactivity, needed for
dynamic performance, created a bigger reaction on small
dynamics and near the steady state spool position (in
Dark-Green in Figure 3). This is the classic
demonstration of the limits of linear controls, like the
PID (Red, Light-Green and Blue lines respectively in
Figure 3) even if provided with variable gains and
anti-windup system, that is unable to be tuned for highly
non-linear systems. The main idea of this work is to
reduce the CPU control time in order to increase the
frequency of the control function execution, in order to
observe the dynamics of the controlled systems in a
shorter time period, where the model linearization is
allowed and then the linear controller is apt to regulate
the system behavior.
THE CONTROL IMPLEMENTATION
The control strategy was primarily designed using a
mathematical model of the system, and, in a second
phase, was translated in ANSI C language and
cross-compiled for the HCS12 Freescale microcontroller
family using the CodeWarrior C/C++ compiler.
Many calculations are executed using single precision
float data type, 32 bits, 8 for the exponent, 23 for the
significand and 1 for the data sign as stated in [1] and [2],
that are expressed in the form:
( ) ( )12723
1
2211 −
=
− ⋅
⋅+⋅−= ∑ e
i
iibvalue
sign
(1)
Where sign is the most significant bit, bi are the base
fractional binary values and e is the exponential binary
value. The microcontroller converts all data using Eq. (1)
for each control function run using shift, multiplier and
divider functions of the ALU (Arithmetic Logic Unit)
both for direct and for reverse conversions.
For each addition/subtraction the ALU converts the
floating point numbers in order to obtain the same
exponent for all operation’s elements and then execute
the addition or subtraction; after the operation another
shift can be executed in order to normalize the result in
case of overflow or underflow of the operation executed;
similarly for multiplication and division. To multiply
for example, the significands are multiplied while the
exponents are added, and the result is rounded and
normalized. Thus, the floating point mathematic need for
more instruction to be executed by the microcontroller
ALU, in order to normalize the numbers before and after
the operation over the mantissa in fixed point mode.
Figure 3 Step Response with Floating Point Software
332
The resulting control function task execution time can
vary considerably from the best to the worst case from
550 µs to 820 µs, depending on the number of floating
point operations that need shift for normalizing data to
the standard format. Figure 4 shows the multiple
acquisition of the control function execution time,
obtained using an Oscilloscope with the “persistency”
function activated at 2 seconds of period. The signal
shown is the status of an hardware output pin of the
Freescale microcontroller activated in the first instruction
of the control function and deactivated in the last
instruction of the control function; the task execution
time is then affected by the introduction of two new
instruction for switching the hardware pin status: the
time for each switch is around 25 ns at 80 MHz clock.
The real need for floating point was evaluated as
suggested in [3], and it was found that, using integer
numbers with 32 bit precision in the intermediate
computations of the control function, the range of values
was sufficient to cover the entire range of intermediate
calculations of the actual control implementation (also
solved in [4]). In fact fixed point mathematics does not
reduce the precision with respect to single precision float
data, if the value of variables does not change for more
than 7 orders of magnitude if, when necessary, 32 bit
variables are used; nevertheless the microcontroller
executes faster the control strategy.
Moreover a fixed point algorithm requires the designer to
write much more controlled code, because of the need to
verify the absence of overflows in fixed point operations,
while in floating point mathematics the designer can lose
the feeling on the data dimension in the control function
implementation.
Last but not least, considering the embedded systems
structure and method to design, tune and test digital
control systems, it is clear that a large number of floating
to fixed point and vice-versa are necessary, in order to
perform the complete software structure. Data to be
transmitted to a data logger over CAN network, for
example, are converted from floating point to fixed point,
in order to be sent in a readable format to the logger
through CAN messages; in the same way, control
parameters are sent and stored in memory in fixed point
format, as usual for human thinking. Moreover looking
at the sensor inputs and at the output of the control
system and analyzing the microcontroller peripheral
structure, the spool position is acquired by a 10 bit ADC
channel and the control action is actuated through a
PWM signal by a peripheral where a control register
must be filled with a 10 bit duty cycle value in real time.
All these values are in fixed point format and a
conversion is necessary to pass from/to floating point
format in control function.
Figure 5 Task Control Duration with Floating and Fixed
Point Mathematics
All these conversions and the strategies required by the
application limits the repetition time for the control task
at 5 ms at least. The mean value of the pure control
function time occupation with floating point mathematics
is shown in the Figure 5 above and is around 550 µs.
The new control was then implemented, modifying the
software control code by replacing all floating point
computation and variables with equivalent fixed point,
thus reducing the data dimension to 16 bit integer, when
possible, and using 32 bit variables where needed for
computation requirements.
The result for the mean value of the control function time
occupation with fixed point mathematics is shown in the
Figure 4 Uncertainty in Floating Point Control Task
Duration
333
Figure 5 below and is around 180 µs.
This performance increase was similarly obtained in the
other functions of the application, where floating/fixed
point conversions were operated.
The result in terms of occupation time by the main
control function is shown in Figure 6, where in the above
image is presented the result for control action time
distribution at 5 ms, while in the below image the control
function time distribution at 1 ms is shown. The figures
demonstrate that no delay due to other tasks is present in
the control function time distribution and then that the
control is executed at deterministic time intervals. In
order to ensure the equivalence of the new software a test
version was created where, for each computation
modified both versions were implemented and a control
was added in order to evaluate both the consistency of
the new software version and the precision.
ResultFloatX = float_functionX();
ResultFixedX = fixed_functionX();
if ( ResultFloatX != (float) ResultFixedX )
{
error_management_function();
}
After the new and old versions comparison, the final
software version was settled at 500 µs of cycle time for
the main control function, resulting in a 10 factor for
control dynamic in respect to the original control.
This software configuration increased considerably the
dynamic and steady state system performance.
COMAPRATIVE TESTS AT TEST BENCH
A Multidrom equipped flow regulation valve was
installed at test bench and tested in various working
conditions, using both software versions reloaded on the
same unit for each test. The monitoring of control task
execution time and cycle time was maintained using a
probe directly connected on a software controlled pin of
the microcontroller (the red cable in the Figure 7), while
all other data, both from sensors and from control
corrections, were acquired through the Multidrom CAN
network with Vector Canalyzer at 500 µs frequency.
The same CAN network analyzer was used to simulate
CAN commands to the module through a dynamic script
that simulated time histories of set point for flow
regulation commands automatically sent by the same tool.
Figure 6 Task Control Period and precise repeatability
at 5 ms and 1 ms timing (new software)
Figure 7 The System under test at the test bench
Figure 8 Step full displacement response with control
contribution and Peak strategy: Integral term Blue line,
D term Green line, P term light blue line.
334
Figure 8 shows the main control strategy behavior, that
applies a fully powered command for big errors in set
point spool position, while starting to use the variable
gains PID for small errors [5].
In the figure a full extend to retract transient is presented,
in order to show the second stage spool dynamics.
A very small spool position overflow is observed and it
can be noted that it does not result in a higher flow
because it is in the fully opened spool displacement
region.
Figure 9 Small step response
The green line is the derivative correction, the light blue
is the proportional correction (saturated) and the blue is
the integral term correction. The values in the vertical axis
are the ADC acquisition values in 10 bit resolution. The
total spool displacement is 16 mm (at 0,02 mm/bit).The
best results are in the small set-point variations and in
steady state error, that results stable with the new control.
As show in the comparison in the two graphics in Figure
9 for small step response, here 0,35 mm, the faster control
action results in a 10 times reduced time for reaching the
90 % of the difference and absence of overshoot (new
software with fixed point mathematics: below graphic;
old software with floating point mathematics: above
graphic). In both graphics the green line is the set-point
for spool position and the blue line is the spool position
direct acquisition through the Hall effect sensor in the
Multidrom module.
Figure 10 Sinusoidal Set-point with Step dynamic
As presented in Figure 10 a variable set-point with steps
response and a sinusoidal waveform results in a better
dynamic response in the new software (below graphic in
the Figure) and in a uncorrected spool position error in the
old software version (above graphic in the Figure), while
the dynamic response at big steps are comparable for the
two software versions.
In both graphics the green line is the set point command
and the blue line is the spool position sensor signal.
The same differences can be found in Figure 11, where
step response coupled with a saw-tooth set-point time
history was generated (new software in the below
graphic in the Figure). The most remarkable result is the
control robustness in function of the control pressure that
should be optimal at 20 bar, but that can be varied in a
335
range of values without lack of precision in flow
regulation, except for the dynamic performance.
With the new software version the Multidrom module
allows the control pressure reduction to 8 bar, while the
original software is unable to reach the set-point value
and the diagnostic strategies lead it to protection condition
in safe state (neutral spool position).
Figure 11 Saw-Tooth Set-point with Step dynamic
As shown in Figure 12 a complete retract to extend
transient was generated with low dynamics in 30 s time,
in order to characterize the steady state error with 8 bar of
control pressure in the Multidrom flow control valves.
In the above graphic in the Figure, it can be noted that the
old software strategies, based on Floating point
mathematics, are unable to reach the set-point and, after a
diagnosis time the control valves are switched off by the
module, in order to lead the spool of the controlled vale in
the neutral position (safe state).
Conversely in the below graphic in the Figure, it can be
observed the entire stationary characteristic of the spool
position control response, that is lead by the new software
based on fixed point mathematics, through the neutral
position at 400 ADC value, that corresponds to 8 mm
(0,02 mm/bit for the spool position acquisition), with no
error in steady state control even if in low (degraded)
pressure condition. In the graphic are also in evidence the
two dead-band and the two polarization currents near by
the valve center rest position.
A higher dynamic without spool position overflow, the
absence of steady state error, the complete spool position
hysteresis and an increased robustness against the control
pressure variation are the most remarkable results; all
these performance increase are due to the PID feedback
correction, that results easier for smaller errors that are
observed in shorter time between two control actions.
CONCLUSIONS
The optimization of the control function, obtained with
the sole mathematics optimization performed on a real
product case, represents an important case study for all
research groups that need for more performance for an
embedded control system.
The limited computing power available in the embedded
systems and microcontrollers, even if in continuous
Figure 12 Low pressure quasi-static characteristic
336
growth, is not sufficient to implement floating point
mathematics based control functions, obtained for
example as output products of widely used simulation
tool-suites.
Conversely fixed point mathematics, the standard
embedded mathematical library in the automotive sector
today, is suitable for optimal control and fits the data
field for the most part of applications without lack of
precision in respect to floating point mathematics and
represents a good compromise for real time control of
mechatronic components in electro-hydraulic
applications.
The next step for fixed point mathematics test and
validation, in our study for electro hydraulic controls
design, will be the direct synthesis of fixed point control
blocks in simulation environment and their test on
models and in control function translation for embedded
systems programming [6]. This method should allow a
direct comparison on control performance compared
with floating point mathematics control blocks and
functions directly on simulation environment.
REFERENCES
1. IEEE 754, ed. 2008: IEEE Standard for Binary
Floating-Point Arithmetic, IEEE
2. IEC 60559 ed. 2.0: 1989, Binary floating-point
arithmetic for microprocessor systems, IEC, Swiss.
3. James W. Gray, PID Routines for MC68HC11K4 and
MC68HC11N4 Microcontrollers, AN1215/D
Freescale Semiconductor Inc., 2004.
4 . Elmenreich W., Rosenblatt M., Wolf A., Fixed Point
Library Based on ISO/IEC Standard DTR 18037 for
Atmel AVR Microcontrollers, 5th Workshop on
Intelligent Solutions in Embedded Systems, June
2007,Madrid, Spain, pages 101 – 113.
5. Kum K.; Kang J.; Sung W; AUTOSCALER for C: an
optimizing floating-point to integer C program
converter for fixed-point digital signal processors,
IEEE Transactions on Circuits and Systems II, Vol.
47/9, 2000, Page(s): 840 – 848.
6. Goossens G., Van Praet J., Lanneer D., Geurts W., et
al., Embedded software in real-time signal processing
systems: design technologies, Proceedings of the
IEEE, Vol. 85, Issue 3, 1997, pages 436 -454.
337