Skip to content
MathWorks - Mobile View
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
MathWorks
  • Products
  • Solutions
  • Academia
  • Support
  • Community
  • Events
  • Get MATLAB
  • Sign In to Your MathWorks AccountSign In to Your MathWorks Account
  • Access your MathWorks Account
    • My Account
    • My Community Profile
    • Link License
    • Sign Out

Videos and Webinars

  • MathWorks
  • Videos
  • Videos Home
  • Search
  • Videos Home
  • Search
  • Contact sales
  • Trial software
3:04 Video length is 3:04.
  • Description
  • Full Transcript
  • Related Resources

How to Partition and Schedule with Export Functions in Simulink

From the series: Run-Time Software Modeling

Partition and schedule models with the Export Function modeling style to integrate functions into your software environment easily and have a clear mapping from model to code. This style is contrasted with rate-based modeling.

With Export Functions, the code separates out into functions that can be integrated into a larger system. Partitioning the model for scheduling and easier code integration are two of the main reasons to use these functions for Run-Time Software Modeling.

Export Function modeling style allows you to integrate functions from your model into your software environment easily and provides a clear mapping from model to code. 

To show how this works, I will start with a model of a Throttle Control System in which the desired software functions have already been modeled using subsystems.

In this model, we have Simulated Pedal Input, going into a Throttle Control, which is then being simulated by a model of a Throttle Body acting as a plant. Inside the Throttle Control Subsystem, we have functions for sensors and sensor management, including one for the primary and secondary throttle sensors, and the sensor monitor. We also have a controller and actuator.

To understand the need for Export Function modeling, let us generate the default code for this model. Although I have modeled the desired functions with subsystems, Simulink optimizes the code and in-lines the functions. In addition, function execution order is determined by Simulink’s built-in scheduler. As a result, the code does not reflect the interface of the functions and does not provide the ability to control execution order. This may not match the needs of your software architecture. 

Let’s look at the Export Function modeling version. The model is now architected differently. First, the Throttle Controller subsystem is now a model block with a fixed-step discrete solver, instead of a variable step solver, because it’s intended for software and integration.

And within the model block, they are in function call subsystems. Export Functions allows you to model the interface, where functions that are to be integrated into the architecture are represented as function trigger ports. If we look at the sample time on the function calls, we can see that they are sampled every 5 milliseconds, except for the Throttle Position Sensor Primary, which is sampled at every 10 milliseconds, and the Acceleration Pedal Position Sensor, which has an event which triggers when this will run.

With Export Functions, no inherent scheduler is assumed, allowing you to more flexibly integrate to a custom environment. You can choose to schedule via the ports or the Schedule Editor to make a simple test harness. For simulation purposes, the software scheduler, in this case, is the Schedule Editor.

The Schedule Editor sends an event to the different function calls every 5 or 10 milliseconds based on when the function call needs to be invoked. The Acceleration Pedal Position Sensor is an explicit aperiodic partition that has scheduled hit times. If you use Stateflow to do the scheduling for run-time software modeling, you can use logical constructs to alter when components are called depending on different situations.

A more extensive test harness for unit testing the controllers can be set up, using the Simulink Test product.

When we generate code for the model block, we get code that separates out the functions, which is taken from the names off the function call ports, making software easier to build. More realistic modeling with scheduling and easier code integration are two of the main reasons we use export functions for real-time software modeling.

Related Products

  • Simulink
  • Embedded Coder

Bridging Wireless Communications Design and Testing with MATLAB

Read white paper

Feedback

Featured Product

Simulink

  • Request Trial
  • Get Pricing

Up Next:

Rate-based subsystems can be partitioned and scheduled as well, allowing you to combine modeling styles with schedulable components.
2:40
How to Combine Modeling Styles with Schedulable Components...
View full series (6 Videos)

Related Videos:

2:06
Scoping Simulink Functions
2:44
Simulink Functions
26:41
Optimizing Transmission Shift Schedule and Powertrain...
36:42
Simulink: Tips and Tricks
41:49
How to Develop Interactive User Interfaces for Simulink...

View more related videos

MathWorks - Domain Selector

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

  • Switzerland (English)
  • Switzerland (Deutsch)
  • Switzerland (Français)
  • 中国 (简体中文)
  • 中国 (English)

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
    • 简体中文Chinese
    • English
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

  • Contact sales
  • Trial software

MathWorks

Accelerating the pace of engineering and science

MathWorks is the leading developer of mathematical computing software for engineers and scientists.

Discover…

Explore Products

  • MATLAB
  • Simulink
  • Student Software
  • Hardware Support
  • File Exchange

Try or Buy

  • Downloads
  • Trial Software
  • Contact Sales
  • Pricing and Licensing
  • How to Buy

Learn to Use

  • Documentation
  • Tutorials
  • Examples
  • Videos and Webinars
  • Training

Get Support

  • Installation Help
  • MATLAB Answers
  • Consulting
  • License Center
  • Contact Support

About MathWorks

  • Careers
  • Newsroom
  • Social Mission
  • Customer Stories
  • About MathWorks
  • Select a Web Site United States
  • Trust Center
  • Trademarks
  • Privacy Policy
  • Preventing Piracy
  • Application Status

© 1994-2022 The MathWorks, Inc.

  • Facebook
  • Twitter
  • Instagram
  • YouTube
  • LinkedIn
  • RSS

Join the conversation