MATLAB Examples

Getting Started with Simulink® Coder™

This model shows an implementation of a second-order physical system called an ideal mass-spring-damper system. Components of the systems equation are listed as mass, stiffness, and damping. You can use this model to generate code for real-time deployment of a continuous-time physical system.



Real-Time System Rapid Prototyping

With Simulink® Coder™ you can generate C code from Simulink diagrams, Stateflow charts, and MATLAB functions. The code generation process is a part of the V-model for system development. The process includes code generation, code verification, and testing of the executable program in real-time. For rapid prototyping of a real-time application, typical tasks are:

  • Configure the model for code generation
  • Check the model configuration for execution efficiency
  • Generate and view the C code
  • Create and run the executable of the generated code
  • Verify the execution results
  • Build the target executable
  • Run the external mode target program
  • Connect Simulink® to the external process for testing
  • Use signal monitoring and parameter tuning to further test your program

Real-Time Execution with Simulink External Mode

To quickly run this model in external mode as an interface to the standalone executable:

  1. Open the rtwdemo_secondOrderSystem model.
  2. Save the model to your working folder.
  3. Open the Configuration Parameters dialog box and select the Code Generation > Interface pane.
  4. Select External mode, and click Apply.
  5. To build the model, in the Simulink Editor window, press Ctrl+B.
  6. Open a command prompt window and run the executable: rtwdemo_secondOrderSystem -tf inf
  7. From the Simulink Editor, select Code > External Mode Control Panel.
  8. To establish a connection, on the External Model Control Panel, click Connect.

In the scope, you can view the data from the external process. To test your application, you can modify tunable parameters and monitor signals. For more information, see Real-Time Execution with Simulink External Mode.

After you test the executable:

  1. On the External Mode Control Panel, click Disconnect.
  2. In your command window, stop the process.
  3. Close the rtwdemo_secondOrderSystem model.

For more information on how to generate code from a model, see the Tutorials in the Getting Started with Simulink Coder documentation.