Multicore Programming with Simulink
Learn how to use Simulink® to model and generate code for software applications targeted for multicore CPUs. This video uses an example that illustrates how to model field-oriented control of a permanent magnetic synchronous machine. The controller successfully drives the motor to the desired speed and torque when executing on a single core, and the video then walks through how to configure it for a multicore target to meet the timing requirements. The video shows how to create tasks, map blocks to these tasks in a flexible manner, and generate code for a multicore processor.
Hi, my name is Matt and I'm a developer for Simulink. Today, I am going to show you how you can model and deploy a software application such as a controller onto a multicore target. This is useful, in our case, because our controller needs to meet some pretty aggressive timing requirements, and this workflow will enable us to model the tasks executing on the individual cores, as well as to generate the code that will eventually run on more than one core of our CPU.
The example shown in this video models field oriented control of a permanent magnetic synchronous machine. The top level model is split into four components-- the desired speed and torque of the motor, the model of the motor, a speed controller, and a torque controller.
When we simulate the model, we can see the controller successfully drives the motor to our desired speed and torque. Right now, our controller is only executing in a single task. So let's start making the required modifications to our model so we can simulate and generate code for our multicore target.
To enable multicore support, we need to open the configuration parameters, and allow tasks to execute concurrently on the target. With concurrent execution enabled, we can then click on the configure tasks button, and begin creating tasks and associating them with blocks.
On the left side, you can create and view a list of tasks. You're able to specify properties such as period, task color for visualization purposes, and the task name. Now let's create two tasks that'll execute on the multicore processor.
The first task, just named Task, will have a period of one millisecond and the second task, named Task1, will also have a period of 1 millisecond. Since we want the two controllers to execute on separate cores, we assign the speed controller to Task and the torque controller to Task1.
After updating the diagram, you are able to see badges hover over each of the blocks in the model. These badges signify which task the block is mapped to based on the color. Also note, that the unassigned blocks, like desired inputs and our motor, have an automatically mapped by Simulink to a third task, signified by the hollow badge.
Now, let's simulate the model, and see the effects of the mapping. As you can see, there are some slight variations in the response from our original simulation. This is caused by the data transfers between tasks that are being simulated in our model.
The data transfer options can be changed individually by selecting a signal, navigating to the data transfer tab, and selecting a new option in the dropdown. They can also be changed globally in the data transfer pane, in the same place we created and mapped our tasks.
There are multiple options to transfer data between tasks, where the current setting is signified by the small icon seen at the input signals of each block.
Now that we have simulated the tasks and configured our data transfer settings, the next step is to generate the code we will deploy to a multicore target. For this demo, we are generating code for the host machine running Windows with embedded coder.
In the generated code, you'll be able to see entry point functions, either both output and update functions, or a single step function for each task. Inside each entry point function is the code associated with the blocks that were assigned to that task, along with the data transfer code which might use semaphores or mutexes for implementation.
Now, in the main function these task functions are realized using Windows threads.
This brings us to the end of this demo on how to model and generate code for a multicore target in Simulink. As a summary of what I've shown you, we have created tasks, mapped blocks to these task in a flexible manner, simulated the effects of the data transfers and mappings, and generated code for our multicore processor.
If you found this quick intro to modeling and applying code for a multicore target with Simulink useful or have any suggestions for future videos, please let us know in the comments. Thanks for watching.
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: .
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.
- América Latina (Español)
- Canada (English)
- United States (English)
- 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)
- United Kingdom (English)
- Australia (English)
- India (English)
- New Zealand (English)
- 日本Japanese (日本語)
- 한국Korean (한국어)