ABSTRACT

Before we look at how code is generated for this control system, let's as­ sume that the Simulink model for the control system is the simple two input single output block shown in Figure 10 (the block labeled "controller"). The first step in developing code for this control system is to isolate the control block. In Simulink, open a new model through the File menu under New and Model. Once this w in ­ dow is open, copy the control block into the subsystem and add input and output ports. Note the enable subsystem icon is kept in this block so that the entire con­ troller w i l l be triggered. When the C code is generated from this block, the sample time w i l l be computed using the integration time. When the block is actually im­ plemented, the user only needs to modify the code to read a clock at the times that the block is executed to get the sample time. Remember that the sample time is used in the discrete integrator to perform the integration. Figure 12 shows the blocks created by this process.