1

I think my questions are unusual, but I wanna work on real time targeting in MATLAB Simulink, but I don't want to use XPC target. I just want no interrupt on the program (simulink) when it is running in order to have a real time interruptless control system. and in that order i can use my control module without target system. first of all, please ignore my weak english. and I have some questions: 1. can we force a core to only be used by simulink and nothing else? 2. how much usually (and how much maximum) does an interrupt take time? 3. is there any other way that we can use in simulink?

thank you

am304
  • 13,758
  • 2
  • 22
  • 40

3 Answers3

1

a. In case you have a multicore platform: Stay away from core 0. Windows assigns certain tasks specifically to core 0. See the SetThreadAffinityMask function to get information how to run a thread on specific cores.

b. Possibly raise the thread/process priority. See the SetThreadPriority function and the SetPriorityClass function for details about setting priorities and Scheduling Priorities for dertails about the priority ranges.

Priority class REALTIME_PRIORITY_CLASS with thread priority THREAD_PRIORITY_TIME_CRITICAL will run your thread at utmost priority whenever it is ready to run. Be aware that such a priority setting will disallow any other process/thread to gain CPU on that core while your thread is running.

Arno
  • 4,994
  • 3
  • 39
  • 63
  • This may be a silly question, but what happens if the other process is in the middle of something? Can it simply pause that or do you have to wait till the subtask is done? – Dennis Jaheruddin Sep 02 '13 at 12:30
  • @DennisJaheruddin: Not silly, the thread with high priority will be scheduled to get the CPU when it is ready to run. At that time other threads/processes are stopped on that core when they have lower priority. However they may continue on antother thread when they are selected by the scheduler again. Fixing the high priority thread/process on a specific core (affinity) basically "locks" that core for the high priority process/thread. – Arno Sep 02 '13 at 12:42
  • thank you for your answer, but i'm confused. please explain a way to change this settings on MATLAB. Did you mean to use a C++ code for this goal? if yes, how we can integrate it with MATLAB simulink. thx – adel darbandi Sep 02 '13 at 12:58
  • @adeldarbandi: You may use the task manager to change a processes priority and/or the affinity. You may also use matlab tools like [this](http://www.mathworks.com/matlabcentral/fileexchange/1841). – Arno Sep 02 '13 at 13:04
1

Well, Simulink is essentially a single-threaded application. There are some ways in which you can use a second core when running in Rapid Accelerator mode (see documentation), but by and large, everything runs on one core. I'm guessing it may change in the future, as a lot of people would like to split the execution of a single large model across multiple cores, but right now it's not possible as far as I know.

Simulink, however is not a real-time application, given that it runs on Windows or other non-real time O/S. Why do you not want to use xPC Target? As you are working on a real-time target, that would be the best option. Other options would be to use Real-Time Windows Target, SIL or even PIL if you have access to your real-time target hardware. Have a look at the example Software and Processor-in-the-Loop (SIL and PIL) Simulation. I think you can configure the code generation process to be executed on one core only, but better to ask MathWorks to be sure.

am304
  • 13,758
  • 2
  • 22
  • 40
  • thx for your answer, i want to ignore xpc, because it needs another hardware and im lack of money. i think real time windows target needs another hardware too? can you tell me more about SIL and PIL? – adel darbandi Sep 02 '13 at 14:06
  • No, Real-Time Windows Target does not require any additional hardware, it uses a real-time engine in windows kernel mode. Have a look at http://www.mathworks.co.uk/products/rtwt/description2.html for more details. – am304 Sep 02 '13 at 14:31
  • You'll need a license of Simulink Coder to generate the C code from the Simulink model and a licence of Real-Time Windows Target. SIL essentially wraps the generated C code into a DLL for the part of the model intended to run on the target, and the rest of the model runs in normal Simulink. PIL is similar, except that you run the generated code on the actual target hardware, which communicates with the rest of the Simulink model on the PC via serial. – am304 Sep 02 '13 at 14:35
0

Using imageCFG you can preset affinity of a program. It modifies the exe file to run on desired core. http://www2.robpol86.com/guides/ImageCFG/