Simulink - Output 1 every 30 seconds, 0 otherwise

Viewed 3708

I need a subsystem that needs to output 1 at interval or 30 seconds or slightly over 30 seconds.

Written in matlab code it should work like that

function y = fcn(time,uplinkTimeInterval)

%#codegen

persistent lastTriggerTime

if isempty(lastTriggerTime)

    lastTriggerTime = 0;

end 

if time>=lastTriggerTime || time == 0

    y = 1;

    lastTriggerTime = time + uplinkTimeInterval;
else

    y = 0;

end

end

where ulplinkTimeInterval is 30 seconds. Of course I tried to use the matlab function block with this code but for some reason it does not work (in debug mode I can see that y takes value 1 as it should but it simply does not ouput the value outside the block), therefore I wanted to use blocks but I do not know how to do it.

Thanks very much for your help

2 Answers
Related