Real-Time Hysteresis Inverter Control in Simulink – ADC Accuracy Issues with Arduino Due, Looking for Better ADC with Raspberry Pi 4

9 views (last 30 days)
Hi everyone,
I'm working on a real-time inverter control system using Simulink and the Arduino Hardware Support Package. The setup includes a hysteresis current controller implemented in Simulink. I'm using current sensors (LEM LES 6-NP) whose analog voltage outputs are connected to the analog inputs of an Arduino Due. The signals are compared with reference current waveforms, and based on the hysteresis logic, Simulink generates PWM signals that control the transistors of an IPM inverter module.
The system works as expected in general, but I'm facing two key issues:
  1. Sampling time limitation – The best real-time performance I can get is with a step size of 1/2500 s. Going below that causes Simulink to fall out of real-time, introducing delays.
  2. Low ADC accuracy – The analog-to-digital conversion on the Arduino Due is quite noisy and not very precise. Because of this, I can't set a narrow hysteresis band (e.g., 0.01). I have to use a wider band (0.05 or more), otherwise, due to noise, the transistors switch incorrectly. At low frequencies, the current waveform is acceptable, but at higher frequencies (e.g., 50 Hz), the waveform degrades due to insufficient sampling and poor resolution.
I’d like to improve the sinusoidal current tracking and I believe the key issue is the ADC quality. I have a Raspberry Pi 4B available and I’m considering adding an external ADC module to it, with the intention of using existing Simulink support packages.
My questions:
  • Would the Raspberry Pi 4B be a better platform for this kind of real-time application, in terms of ADC quality and achievable step size?
  • Can anyone recommend a compatible ADC module (preferably with Simulink support out-of-the-box) that could provide higher resolution and better noise performance?
  • Has anyone had success implementing hysteresis control or other fast current control strategies using Raspberry Pi + external ADC in Simulink?
  • Or is Raspberry Pi simply not suitable for this kind of high-speed control task (due to OS latency, limited real-time precision, PWM generation etc.) and should I be looking into a different platform like an FPGA or a real-time microcontroller instead?
I’m attaching a screenshot of the Simulink model and a sample of the output current waveform (10, 25 Hz) for reference.
Thanks in advance for your help!

Accepted Answer

Sameer
Sameer on 4 Jul 2025
While Raspberry Pi with Simulink is easy to use, it's not well-suited for fast control tasks like hysteresis current control. This is mainly because:
  • No real-time OS – The Raspberry Pi runs Linux, which causes unpredictable delays and jitter.
  • Slow ADC performance – External ADCs (like ADS1115) use I²C or SPI, which are slower and add latency.
  • Limited PWM and timing precision – Software-based PWM and OS scheduling reduce timing accuracy.
Better Alternatives
  • Microcontrollers (e.g., STM32, Teensy): Run without an OS, give fast and precise control.
  • TI C2000 MCUs: Built for motor/inverter control, with real-time ADC–PWM sync.
  • FPGA or SoC (e.g., Xilinx Zynq): Hardware-level control with nanosecond precision.
  • Speedgoat + Simulink Real-Time: Best for guaranteed real-time control (but expensive).
Hope this helps!

More Answers (1)

Seweryn
Seweryn on 7 Jul 2025

Hi @Sameer,

thank you very much for your detailed explanation!

I have a follow-up question: How much additional load does the Simulink External Mode (real-time target) typically place on a microcontroller compared to Build and Deploy?

So far, I’ve mostly used External Mode and monitored signals using a single Scope block with three waveforms (e.g., from ADC inputs). I’m wondering how much this might be affecting timing and performance – especially when sampling at higher rates.

Thanks again for your insights!

Best regards, Seweryn

  1 Comment
Sameer
Sameer on 8 Jul 2025
Edited: Sameer on 8 Jul 2025
Yes, Simulink External Mode does add some extra processing load on the microcontroller compared to just using Build & Deploy. When you run in External Mode, the microcontroller has to not only execute your control code but also handle communication with Simulink to send back data for scopes or signal monitoring. This introduces overhead, especially noticeable at higher sampling rates.
If you're sampling fast (say below 500 µs step size) and streaming multiple signals (like three ADC waveforms to a Scope), this can affect timing and even cause missed deadlines or unstable behavior. The system might struggle to keep up, especially on hardware with limited RAM or CPU bandwidth. Scopes in particular are resource-hungry since they buffer and send a lot of data continuously.
For better performance, it's a good idea to test final control behavior using Build & Deploy mode—this runs the code standalone without the communication overhead. During External Mode debugging, try to log only the most important signals, reduce the number of waveforms per Scope, and use decimation if needed.
Hope this helps!

Sign in to comment.

Categories

Find more on Real-Time Deployment and Code Generation in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!