0
votes

I have a system with some embedded Matlab blocks where I'd like to perform some actions after a certain amount of time, in this case turn on lights and switches in an interface to which I send signals from Simulink.

The problem is that I thought I'd use "tic"-"toc" and "while" in a Matlab function block to perform these actions, say one parameter becoming 1 after 5 seconds, the following parameter becoming 1 after 12 seconds and so on, but I noticed that tic-toc apparently doesn't work in Simulink for embedded functions.

Is there any similar functions that could be used in Simulink for embedded functions or is there any other way to do this?

Edit: I've tried to get the clock's time as well, but it's a growing value. Is there any way to "lock" the time as a parameter when the block's function is executed?

1
I tried to write a code with "clock" function, which I got to work as I wanted in matlab but unfortunately "clock" has the same problem as "tic-toc" and is not supported by Simulink.user2703642

1 Answers

2
votes

You shouldn't be using absolute time in an embedded system, which is at least one of the reasons why tic-toc and clock from MATLAB don't work with Simulink Coder.

You should create your own counter, which you start and stop when you need to. This is pretty easy to do using a Unit Delay and Summation block.

If you need to be able to enable and/or reset the counter then use the appropriate block from the Additional Discrete library.