Based in my last post, I decided to modified a little bit the code and create a 'Clock Pulses Counter'.
It is very easy following the steps explained in 'Increment/Decrement Variable (counter)' and adding some additional features.
Since the example is based in my last post, the main block will be the 'Matlab Function' block.
The schematic in this example can be seen in the next figure:
Clock pulses counter Schematic |
As it can be seen, the schematic is almost identical, but a global variable called flag has been added.
The code I used in this example is the following:
function y = fcn(u)
%clock
flag counter
global
A;
global
flag;
if u
if flag
A = A+1;
flag = false;
end
else
flag =
true;
end
y = A;
Global variable A is an int counter and global variable flag a boolean, which can be true or false.
Global variable A properties |
After initialized the global variable flag in the fuction Matlab block like it was explained in the last post, the example is ready to be run.
The output in this case would be a little bit different:
Output when clock period is 0.1 seconds |
Output when clock period is 0.05 seconds |
hi
ReplyDeleteplease help me
I have simulation in simulink,I want to one parameter be global after that I use this parameter for another simulation in simulink but I got one error about "Invalid setting in 'emulator/Gain' for parameter 'Gain'."
what do I do to solve my error