# Need help creating a modified version of the NOR block

Posted 5 years ago
4452 Views
|
|
1 Total Likes
|
 Hi! I need help regarding modifying the NOR block.I have been trying to achieve a NOR block such that when I input all 0's in it, it gives me a 1 for 5 seconds, and then reverts back to 0.Here's how I have modified the NOR block so far:block ModifiedNOR parameter Modelica.SIunits.Time startTime = time; extends Blocks.Interfaces.partialBooleanSI2SO; when (u1=u2) equation y = if startTime+5>time true else false; end ModifiedNOR;I would appreciate if someone shows me where am I mistaken. Thanks.
 Hi Safi Ahmed!You need to have an event that changes a time variable that keeps track of when the values of u1 and u2 last where 0 at the same time, and then check if it has been within 5 seconds since last this occurred. Does the following code work as you intended your NOR block? Once you input two 0:s, it will give a 1 for 5 seconds (even if one of the inputs changes during that time). model ModifiedNOR extends Modelica.Blocks.Interfaces.partialBooleanSI2SO; protected discrete Modelica.SIunits.Time entryTime "Time instant when NOR became true"; initial equation pre(entryTime) = 0; equation when not (u1 or u2) then entryTime = time; end when; y = if time - entryTime < 5 then true else false; annotation(Diagram(coordinateSystem(extent = {{-148.5, -105}, {148.5, 105}}, preserveAspectRatio = true, initialScale = 0.1, grid = {5, 5}))); end ModifiedNOR; Here are some resources if you want to learn more about events and when-statements.Hope that helps!