How can you generate a C code with embedded coder from a simulink model with a cycle time/period (sample time) shorter than 1 ms?

5 次查看(过去 30 天)
I have a simple simulink model same as the example rtwdemo_concurrent_execution (MathWorks Model Concurrent Execution for Symmetric Multicore CPU Platforms). When I change the sample time and the period time of this model from 1 (original value in the sample model) to 0.0001 and try to build the model and creat a C-Code, simulink shows the following error:
How can I make a smaller "Period" time?

采纳的回答

Qing Liu
Qing Liu 2019-12-4
编辑:Qing Liu 2019-12-17
A tricky method : manually modify the tlc file( <MATLAB_ROOT>/rtw/c/tlc/mw/ertwinthread.tlc )
comment out lines 773-780 (as follow) from
773 %if ((period * 1000) < 1)
774 %if LibIsDeploymentDiagram()
775 %assign errormsg = "The periodic trigger %<LibGetTriggerName(ehIdx)> of model %<::CompiledModel.Name> has a base rate smaller than 1 ms. The current base rate is %<period> seconds. Increase the base rate of the periodic trigger by increasing the rate in the model."
776 %else
777 %assign errormsg = "%<::CompiledModel.Name> has a base rate smaller than 1 ms. The current base rate is %<period> seconds. Increase the base rate of the model."
778 %endif
779 %exit %<errormsg>
780 %endif
to this
773 /%%if ((period * 1000) < 1)
774 %if LibIsDeploymentDiagram()
775 %assign errormsg = "The periodic trigger %<LibGetTriggerName(ehIdx)> of model %<::CompiledModel.Name> has a base rate smaller than 1 ms. The current base rate is %<period> seconds. Increase the base rate of the periodic trigger by increasing the rate in the model."
776 %else
777 %assign errormsg = "%<::CompiledModel.Name> has a base rate smaller than 1 ms. The current base rate is %<period> seconds. Increase the base rate of the model."
778 %endif
779 %exit %<errormsg>
780 %endif%/
and the Code Generation process will skip the check of the time step greater than 1ms.

更多回答(1 个)

Krishna Zanwar
Krishna Zanwar 2019-2-25
The "base rate smaller than 1 ms" error message appears when the code generation target is set to GRT (Generic Real-Time) or ERT (Embedded Real-Time) in response to a Windows threading bug- when the base rate of the model is very fast, the timer in the generated code will not be able to issue an interrupt, and the generated executable will hang.
Since this issue only applies to GRT, ERT, and IDELINK targets, you should still be able to build an executable using SLRT. To change your model to use the SLRT target, please use the following steps:
1. Open the Configuration Parameters window in your model.
2. Select 'Code Generation' on the left, then for the 'System target file' parameter, click the 'Browse...' button.
3. In the pop-up that appears, select 'slrt.tlc (Simulink Real-Time)' and click OK.
4. Repeat steps 1-3 for each of the referenced models you are using.
After following these steps, your model will be set up to build for the SLRT target. Please note that for SLRT, you can only have one periodic trigger, so you will need to edit the concurrent execution options for your model to use one instead of two.

类别

Help CenterFile Exchange 中查找有关 Deployment, Integration, and Supported Hardware 的更多信息

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by