0

I am using a s-function built in Simulink and I need to implement a waiting time. For example I need to do this :

send the first frame    
wait 20 ms
send the second frame
wait 20 ms
send  third frame

How could I establish this waiting time between 2 frames. I am using C language and a Level-1 Matlab S-function.

  • This is the same as your [previous question](http://stackoverflow.com/questions/22785027/waiting-time-in-s-function). The answer hasn't changed: you can either make the S-Function discrete and specify the sample time, or use the [mdlGetTimeOfNextSampleHit](http://www.mathworks.com/help/simulink/sfg/mdlgettimeofnextvarhit.html) method to change the sample time each time the block is called. – Phil Goddard Apr 09 '14 at 00:26

1 Answers1

0

First of all, it is very difficult to get millisecond accuracy. it depends a lot on your hardware, OS, proccesses running..

you could try to achieve it by simply using the pause command

send the first frame    
pause(0.020)
send the second frame
pause(0.020)
send  third frame

or using timer objects http://www.mathworks.com/help/matlab/ref/timerclass.html

both solutions are not accurate. the best solution would be to base your timing in external events. is there any event triggered after sending each frame?

eventHandler
  • 1,088
  • 12
  • 20
  • Yes, I have a trigger after sending a frame and this is why I need to wait to be sure that the trigger was triggered. – Alexandru Tat Apr 08 '14 at 12:42
  • generally you can attach functions to handle events. does your frame object have such event handlers? you could inspect the frame and find out if it is possible. – eventHandler Apr 08 '14 at 15:03
  • maybe you've already visited this link http://www.mathworks.com/help/simulink/sample-time-1.html but i guess there is what you need. maybe the "S-Function Callback Methods" section. – eventHandler Apr 08 '14 at 15:23