Stateflow implementation on Arduino very slow

11 views (last 30 days)
Hendrik2k1
Hendrik2k1 on 1 Dec 2025 at 15:02
Answered: Aditya ungefär 8 timmar ago
I have always assumed with Simulink's Arduino support that if I have a Simulink model and declare it as “Run On Board,” all content will be transferred to the board as C code and my computer will not execute any of it itself. In other words, the computing load is completely implemented in hardware.
Now, when I want to implement a simple StateFlow implementation (PWM with Dead Time Insertion) in it and then transfer the whole thing to the Arduino board via “Build Start and Deploy,” I unfortunately find that I basically have no control over a KNOB with which I can set the properties of the PWM on the fly, so to speak. Only when I press "Monitor and Tune" can I change the knob. But then I realize that my StateFlow chart seems to be running within Simulink? At least I can follow the sequence of states (when opening the StateFlow-Chart), and the output on the hardware board (LEDs) is very slow. It is far away from a kHz range. Have I misunderstood something? I've also tried setting the SampleTime of the StateFlow to a very low value, but then I get problems with the XCP protocol (overload).
Any idea how to get this to work? Perhaps Arduino is not the best choice for it? Im using Ardunio DUE, one of the more speedy Arduinos. Of course communication is working over COM.

Answers (1)

Aditya
Aditya ungefär 8 timmar ago
Hi Hendrik ,
When you use Simulink’s Arduino support, deploying your model with "Deploy & Start" runs all code directly on the Arduino, but you cannot change parameters live—they are fixed until you redeploy. If you use "Monitor & Tune" (External Mode), the code still runs on the Arduino, not your PC, but you can adjust parameters and view live Stateflow animation through a serial connection. However, this live interaction is much slower due to communication overhead, making it unsuitable for high-speed tasks like PWM in the kHz range. The slowness and potential XCP overload are caused by the limited speed of the serial link, especially at fast sample times. For high-speed control, you should use Deploy & Start, and for live tuning or debugging, use Monitor & Tune at moderate speeds.

Products


Release

R2025b

Community Treasure Hunt

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

Start Hunting!