Clear Filters
Clear Filters

How to implement millisecond delays in Simulink model while using signal editor?

12 views (last 30 days)
I have currently built a Simulink model and used signal editor to inject signals in a time sequence to confirm my expected logic operation.
During this I had the Solver set for Fixed step with a fixed-step sample time of 1.0.
This worked fine as the signals from the signal editor changed every second.
The problem I have now, is that I would like to introduce some delay logic in my model which includes delays from 50 to 100 milliseconds.
The delay logic uses samples, but only takes integer numbers.
I can reduce fixed-step sample time, however this is causing problems with my test scenario which is given in seconds as mentioned.
How could I go about showing the correct timing on the scope output from my test scenario where each of the inputs change every second, whilst implementing my delay logic which is in milliseconds?

Answers (1)

Gagan Agarwal
Gagan Agarwal on 15 Nov 2023
Hi Daniel
I understand that you are trying to implement millisecond delays in Simulink Model while using the signal editor. To accurately achieve this please try to follow these steps :-
  1. Change the fixed-step sample time in the Simulink model to a smaller value, such as 0.001 seconds. This will ensure that the delays introduced are incorporated accurately.
  2. Adjust your delay logic to work with the new sample time. Since the delay logic only takes integer numbers of samples, "Discrete-Time Integrator" block or a counter that will keep track of the number of samples corresponding to the desired delay in milliseconds can be used.
  3. Now to ensure the correct timing for the test scenario, introduce a counter or a timer in the model that will keep the track of the number of seconds elapsed. This counter will be incremented by 1 every millisecond (based on the new sample time).
  4. Connect the counter or timer output to the signal editor block to control the timing of the input signal changes.
I hope it helps!

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!