Arduino Uno /Simulink: Sample Time not updating with different values

6 visualizzazioni (ultimi 30 giorni)
Figure 1: Simulink Model Figure 2: Sample Time @ 0.01
I am using Simulink (R2024a). I am using a pendulum to try to purposely get a scope of aliasing with the signal coming from the Arduino Uno. When I input the SampleTime (0.01), the program outputs a sine wave as expected.
Figure 3: Sine Wave at Sample Time @ 0.01 & Stop Time @10.0
When I change the Stop Time to 30.0 sec and ensure the Simulation pacing is 1:1, it outputs a sine wave and runs the whole simulation.
Figure 4: Sine Wave Sample Time @ 0.01 & StopTime @ 30.0
However, when I change the Sample time to any other value, the program doesn't work as intended. The simulation is done in 1 sec even though the Simulation Pacing is a 1:1 ratio. It does get some aliasing, but it looks very incomplete.
Figure 5: Incomplete Aliasing with Sample Time @ 1.0 & Stop Time @ 30.0
The end result is supposed to look like this.
Figure 6: Goal of Aliasing graph on older MATLAB release
The diagnostic viewer reports no errors.
I have alternated with using different hardware (arduino board vs computer) and they both do not run correctly. I have experimented with different Sample Times, Stop Times, and 3D Array/Timespace/2DArrays (To Workspace) with no change or success.
I am thinking it has something to do with the updated version vs the older version that this experiment was based on.

Risposta accettata

Muskan
Muskan il 17 Giu 2024
Hi Scarlet,
You can follow the below steps to troubleshoot the issue,
Verify Sample Time Configuration
  • Ensure that the sample time you're setting is correctly applied to the blocks that are interfacing with the Arduino. This usually involves configuring the blocks that read from or write to the Arduino's pins
Check the Solver Configuration
  • For real-time simulation with hardware, it's crucial that the solver configuration matches the nature of your simulation. Go to "Model Configuration Parameters" and ensure you're using a fixed-step solver with a step size that matches your desired sample time.
  • The solver's step size directly influences the simulation's ability to run in real-time, especially when using simulation pacing.
. Understand Simulation Pacing
  • Simulation pacing ("Simulation Pacing Options") is designed to slow down the simulation to approximate real-time execution. However, it doesn't guarantee precise real-time execution, especially if the computational load is high or if the sample time is too short for the model to execute in real time on your hardware.
  • If the simulation finishes too quickly (e.g., in 1 second regardless of the stop time), it suggests that the pacing might not be effectively limiting the simulation speed. This could be due to the computational demands of the model versus the capabilities of your system.
Adjusting for Accurate Aliasing Visualization
  • When trying to visualize aliasing by varying the sample time, make sure that the signal frequencies you're trying to sample are well-defined and that you're crossing the Nyquist rate intentionally to observe aliasing.
  • Use a Spectrum Analyzer block to visualize the frequency content of your signal at different sample times to better understand how aliasing is affecting your signal.

Più risposte (0)

Categorie

Scopri di più su General Applications in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by