Jittery ESC motor output on Teensy 4.0 in Simulink despite successful PWM/Servo write attempts

I am using the Simulink Arduino support package with a Teensy 4.0 for custom flight controller firmware. I can successfully read sensor data over SPI and I2C, and I can also calibrate my ESCs, but normal motor operation is jittery and inconsistent.
I tried both:
  • PWM Write
  • standard Servo Write
In both cases, the motors do not respond smoothly or consistently during normal operation, even though ESC calibration works.
Since the model is also reading sensors over SPI and I2C, I am wondering whether the issue is related to timing or scheduling in the generated code. For example, sensor communication may be interfering with the timing of the motor output updates.
My questions are:
  1. Has anyone gotten stable ESC control on a Teensy 4.0 through the Simulink Arduino support package?
  2. Is PWM Write or Servo Write the better choice for driving ESCs in this setup?
  3. Can SPI and I2C sensor reads in the same model introduce enough timing jitter to affect motor outputs?
  4. Are there recommended sample times or block configurations for reliable ESC control?
I am trying to determine whether this is a model configuration issue, a code generation/timing issue, or a limitation of the support package itself.
All of my wiring and my custom flight controller PCB has been validated and works in arduino, so the physcial layout is likely not the issue.

Réponses (1)

Hello,
1) Has anyone gotten stable ESC control on Teensy 4.0 in Simulink?
Yes, stable ESC control is achievable on Teensy 4.0 using the Simulink Arduino package, as long as timing is configured carefully.
Teensyspecific Simulink workflows also exist via the Embedded Coder Target for Teensy.
2) Is PWM Write or Servo Write the better choice for driving ESCs in this setup?
PWM Write is better for ESCs because Teensy’s hardware PWM (FlexPWM/QuadTimer) is more tolerant to interrupt latency and produces more stable pulses.
Servo Write is more sensitive to interrupt jitter and uses shared timers; conflicts easily degrade output.
3) Can SPI and I2C sensor reads in the same model introduce enough timing jitter to affect motor outputs?
Yes. The Simulink Arduino I2C and SPI blocks use controllerdriven, blocking exchanges per step; large transactions or slow buses can stall the task that runs them. MathWorks even advises using longer sample times when combining PWM/Servo with serial I/O to avoid overruns. Thats a red flag for jitter-sensitive outputs.
I2C on Teensy can hold SCL low (clock stretching) or wait for ACK, which further extends transaction time; the support package docs documentation explains wait states/NACK/ACK semantics that can stall the controller.
4) Are there recommended sample times or block configurations for reliable ESC control?
Hope this helps.

Produits

Version

R2025b

Question posée :

le 16 Mar 2026

Réponse apportée :

le 20 Mar 2026

Community Treasure Hunt

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

Start Hunting!

Translated by