Embedded Control Systems in C/C++: An Introduction for Software Developers Using MATLAB

In this chapter, I began by showing how to convert a continuous-time state-space model of a controller (or observer-controller) in MATLAB to a discrete-time system. A number of different discretization methods are available and some of the benefits and drawbacks of each were discussed. If you do not have a particular reason to favor one of the discretization methods over the others, the first-order hold is a good general-purpose choice. This method provides a good match between the phase and magnitude responses of the continuous-time and discrete-time models over a wide range of frequencies.
When choosing a sampling period for the discrete-time model, a number of factors must be considered. A too-short sampling period requires excessive computation time and I/O activity. An excessively long sampling period can result in poor controller accuracy or even system instability. Selecting a suitable sampling period is a critical element of the control system design process.
A discrete-time controller model can be implemented with floating-point mathematics in C or C++ with the assistance of the write_c_model .m and write_cpp_model.m MATLAB M-files provided on the enclosed CD-ROM. These functions generate C and C++ source code to implement a discrete-time state-space model that uses floating-point math.
When the embedded processor used in the control system does not support floatingpoint mathematics or the resource requirements for floating-point math are excessive, fixed-point math can be used instead. In fixed-point mathematics, scaled integers represent continuous quantities. Although fixed-point math can be much more efficient than floating-point...