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

If sufficient processing power and execution time are available, it might be appropriate to implement an embedded controller with floating-point mathematics. When possible, this approach minimizes the effects of quantization and essentially eliminates the possibility of errors due to overflow in the controller calculations. For processors containing dedicated floating-point hardware units or sufficiently fast software implementations of floating-point operations, the use of floating-point math is often the preferred approach.
Converting a MATLAB discrete-time control system model to a fixed-point C or C++ source code implementation consists of a straightforward series of steps. This conversion process has been mechanized in two MATLAB M-files, write_c_model.m and write_cpp_model.m. The help text for each is shown here.
WRITE_C_MODEL Write a C model of a discrete-time system using floating-point math. WRITE_C_MODEL(MODEL) generates a C language implementation of the discrete-time model MODEL using double-precision math and displays it on the screen. WRITE_C_MODEL(MODEL, DEST) directs the C language output to the file indicated by DEST. DEST is a character string name of a...