Page 51 - The Mechatronics Handbook
P. 51
functions needed in a control system are not available. However, sometimes the values being sensed and
computed, though real numbers, are of a reasonable range. Because of this situation there exists a special
type of arithmetic whereby microcontrollers use integers in place of floating-point numbers to compute
non-whole number (pseudo real) values.
There are several forms of fixed-point mathematics currently in use. The simplest form is based upon
powers of 2, just like normal integers in binary. However, a virtual binary point is inserted into the integer
to allow an approximation of real values to be stored as integers. A standard 8-bit unsigned integer is
shown below along with its equivalent decimal value.
4
2
0001 0100 = (1 * 2 ) + (1 * 2 ) = (1 * 16) + (1 * 4) = 20
Suppose a virtual binary point is inserted between the two nibbles in the byte. There are now four bits
left of the binary point with the standard positive powers of 2, and 4 bits right of the binary point with
negative powers of 2. The same number now represents a real number in decimal.
0 -2
0001 0100 = (1 * 2 ) + (1 * 2 ) = (1 * 1) + (1 * 0.25) = 1.25
Obviously this method has shortcomings. The resolution of any fixed point number is limited to the
-4
power of 2 attached to the least significant bit on the right of the number, in this case 2 or 1/16 or 0.0625.
Rounding is sometimes necessary. There is also a tradeoff in complexity, as the position of this virtual binary
point must constantly be maintained when performing calculations. The savings in memory usage and
processing time, however, often overcome these tradeoffs; so fixed-point mathematics can be very useful.
Calibrations
The area of calibrating a system can sometimes take on an importance not foreseen when designing a
mechatronic system. The use of calibrations, numerical and logical values kept in EEPROM or ROM,
allow flexibility in system tuning and implementation. For example, if different microprocessor crystal
speeds may be used in a mechatronic system, but real-time values are needed, a stored calibration constant
of clock cycles per microsecond will allow this calculation to be affected. Thus, calibrations are often
used as a gain, the value multiplied by some input in order to produce a scaled output.
Also, as mentioned above, calibrations are often used in the testing of a mechatronic system in order
to change the “feel” of the product. A transmission control unit can use a set of calibrations on engine
RPM, engine load, and vehicle speed to determine when to shift gears. This is often done with hysteresis,
as the shift points moving from second gear to third gear as from third gear to second gear may differ.
3.7 Microprocessor Input–Output Control
Polling and Interrupts
There are two basic methods for the microprocessor to control input and output. These are polling and
interrupts. Polling is just that, the microprocessor periodically checking various peripheral devices to
determine if input or output is waiting. If a peripheral device has some input or output that should be
processed, a flag will be set. The problem is that a lot of processing time is wasted checking for inputs
when they are not changing.
Servicing an interrupt is an alternative method to control inputs and outputs. In this method, a register
in the microprocessor must have set an interrupt enable (IE) bit for a particular peripheral device. When
an interrupt is initiated by the peripheral, a flag is set for the microprocessor. The interrupt request (IRQ)
line will go active, and the microprocessor will service the interrupt. Servicing an interrupt means that
the normal processing of the microprocessor is halted (i.e., interrupted) while the input/output is com-
pleted. In order to resume normal processing, the microprocessor needs to store the contents of its registers
before the interrupt is serviced. This process includes saving all active register contents to a stack, a part
©2002 CRC Press LLC