Regarding the execution time in the 'Simulink Support Package for Arduino Hardware'

60 次查看(过去 30 天)
Hello,
I have some questions regarding the execution time in the 'Simulink Support Package for Arduino Hardware'.
Q1. If I want to run a Simulink model at 100Hz on Arduino Hardware, should I set the Fixed-step size to 10ms in the Solver details? (My model is based on sensor values)
Q2. Or my model is based on sensor values, and I want it to run at 100Hz. In this case, should I set the sample time of the I2C controller read block to 10ms?
Q3. What happens if the execution time of my model exceeds 10ms (an overrun occurs)?
For example, let's assume that the model operates based on sensor values received (start model) every 10ms. If the algorithm takes 15ms to run, I see two possible options:
  1. The algorithm runs with the sensor values from time t, and the sensor values from t+10ms are discarded (since the algorithm is still running), and the algorithm runs again with the sensor values from t+20ms.
  2. The algorithm runs with the sensor values from time t, and as soon as the algorithm finishes, it starts again with the sensor values from t+10ms at t+15ms.
Which one happens? I believe it is option 1.
If someone knows, please provide an answer.
Thank you.

采纳的回答

Abhinav Aravindan
Abhinav Aravindan 2024-8-20,10:49
  1. Fixed-step size: Setting the ‘Fixed-step size to 10ms is appropriate if you want your Simulink model to run at 100Hz, as this means the model updates every 10ms.
  2. Sample time for I2C controller: Specifying the sample time of the I2C Controller Read block to 10ms means an I2C read is initiated every 10ms. If other blocks in your model use the same sampling rate, a 10ms step size is appropriate. Alternatively, using "Auto" for the step size can help manage different block rates more efficiently.
  3. When the execution time of your model exceeds 10ms, a task overrun occurs. When a task overrun occurs, the model continues running, but the effective sample time will be longer than specified. You can fix overruns by decreasing the frequency with which tasks are scheduled to run, and/or by reducing the number of tasks defined by your model.
For more details on setting the step-size and sampling rate’ please refer to the links below.
Please refer to the documentation below for further detail on task overrun:
  3 个评论
Hyunuk Ha
Hyunuk Ha 2024-8-23,1:27
권순호님,
안녕하세요. MathWorks Korea 하현욱 입니다.
질문 주신 내용에 대해서 간략하게 추가 답변 드리겠습니다.
Embedded Coder 로 코드 생성을 해보시면, step 함수는 Overrun 체크 하는 부분 내부에서 호출됩니다.
그렇기 때문에 생각하시는 것 처럼 Overrun 을 어떻게든 핸들링 하셔야 됩니다.
일반적으로 많이 접근하는 방법은,
  1. 제어 주파수를 낮춘다. (== 제어주기를 늘린다.)
  2. 알고리즘을 최적화 한다. (==연산량을 줄인다.)
  3. 프로세서의 클럭을 높인다.
정도 입니다.
위 보기 중에서, 3번째 옵션은 추가비용이나 하드웨어의 변경이 필요하니 일반적으로 선택하지 않으실 것 같고,
현실적으로 첫번째나 두번째 보기 중에서 선택하시면 됩니다.
제 개인적으로는 연산량을 줄이기 위해서 알고리즘을 최적화 해보고, 더 이상 최적화할 내용이 없다면 Solver 에서 Sample time 을 늘려서 제어주기를 늘려서 동작시키려 시도해 볼 것 같습니다.
알고리즘을 최적화 하기 위해서는 Simulink profiler 를 활용하셔서, 어떠한 알고리즘이 연산시간을 많이 소요하는지 확인해 보고 소요시간이 많이 걸린 블럭부터 최적화 할 것이 없는지 순차적으로 확인해 보는 것이 효율적입니다.
간략하게 적어 두었는데, 이 내용에 대하여 세부적인 내용이 궁금하시면 MathWorks Korea 엔지니어와 컨퍼런스콜을 진행하는 것도 좋다고 생각합니다.
필요하시면 메세지 남겨주시면, 저희 엔지니어가 연락드리겠습니다.

请先登录,再进行评论。

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by