simonongsk

Edge Detection in Structure Text

12 posts in this topic

Is there any instruction in Sysmac Studio Structure text to detect rising Edge (DIFU/DIFD) ?

Share this post


Link to post
Share on other sites

Oops

Edited by vasekd
Oopps

Share this post


Link to post
Share on other sites

why not make one?

that is what i do whenever i work on a platform that does not have what i need. 

edge detection is simple, just compare current state with previous state. this means creating variable that will hold last value. then you do comparison and update the variable.

Share this post


Link to post
Share on other sites

How will it work if I am only interested in Trigger Up?

 

 timeOut:= Timer(TimeBit,UINT#100,TimerSt,TimerDone,ElapseTime);

IF ( timeOut<>PreviosState ) THEN
    
   Counter:=Counter+1;
   PreviosState:=timeOut;;

END_IF;

The Counter will increase  by 2.

 

with ladder, with dIFU, that will not happen

Share this post


Link to post
Share on other sites

This is why ladder is way easier for many things.  Here is how I would do this:

TimeOut:=Timer(TimeBit,UINT#100,TimerST,TimerDone,ElapseTime);

IF TimerDone=TRUE AND Oneshot=false THEN;
    Counter:=Counter+1;
    Oneshot:=TRUE;
END_IF;

IF TimerDone=FALSE AND Oneshot=TRUE THEN;
    Oneshot:=FALSE;
END_IF;
    

Share this post


Link to post
Share on other sites

simonongsk: in your code the rising and falling edge is increase the counter.

One other solution:

IF timeOut AND NOT PreviosState THEN
   Counter:=Counter+1;
END_IF;

PreviosState:=timeOut;

 

Or in ST you can use R_TRIG variable:

rtrigTimeout(Clk := timeOut);

IF rtrigTimeout.Q THEN

      Counter := Counter + 1;

END_IF;

In that case declare rtrigTimeout with R_TRIG data type.

1 person likes this

Share this post


Link to post
Share on other sites

language does not matter. if you speak it well enough, you can do anything you want to. if you need to detect rising and falling edge of a BOOL signal, why waste INT or TIMER or COUNTER when just another BOOL is needed to store old value? 


suppose you want to detect one or both edges of some signal "A"
we need another variable that stores old value of A (previous scan). this variable is same type as A but separate memory location.


for example, consider pseudo code::

RisingEdge= (A==TRUE) AND (OLD_A==FALSE)
FallingEdge = (A==TRUE) AND (OLD_A==TRUE)
OLD_A=A ; copy current A value to OLD_A to be used in next scan

this can be written shorter as:

RisingEdge= A AND NOT OLD_A
FallingEdge = OLD_A AND NOT A
OLD_A=A ; copy current A value to OLD_A to be used in next scan

and if you only need rising edge... so be it, remove middle line with FallingEdge signal. this is very simple and short piece of code using only the most basic logic operations that every controller and programming language can handle (NO, AND and assignment):

RisingEdge= A AND NOT OLD_A
OLD_A=A

note that length of the pulse is one scan time.

 

edge_detection.jpg

Share this post


Link to post
Share on other sites

that is no different that using Ladder. It is the exact same code.

language does not matter. it is how one thinks and uses it.

execution time may be different depending on efficiency of interpreter or compiler but logic IS the same

 

edge_detection_Ladder.jpg

Share this post


Link to post
Share on other sites

Geez - an up or down arrow in a contact looks simple hey - or an @ on a function. LOL

Share this post


Link to post
Share on other sites

Did anyone think about the F_TRIG and R_TRIG function blocks?  They are built in and create a rising or falling edge...

Toolbox, Sequence Input...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now