Jump to content

Recommended Posts

Posted

Hello 

 

I'm already aware to the fact that transition contacts are not functioning inside UDFB, and there is an example application how to work it out, but what about SET RESET coils?  

 

It seems that SET and RESET coils are not latching as should be, if the bit is define as Local tag. Only as Global, Input or Output 

it works as normal.

 

I tried to walk-around by building a simple holding circuit using simple coil, but this one also refuse to latch in ON state as well. Seems that there is no "memory" for local tags.,,  a bit strange as it is very basic logic circuit..

 

The whole concept, as I understand, with the blessing USFB that one can repeat the same function many times in the project (working less-do more!)  But if required to use many global tags (witch are not "duplicate" with the function) as momentary memory (Input and output tag will also be relate to global tags after all), then what is the point? or do I miss something?

 

Any way to latch local bits ?

 

What about numerical local tags, do they keep the value? 

 

 

Thsnks! Ofer

 

 

 

 

Posted
Off course there is no memory for local tags... they are local.

 

Consider the pseudo code (assume that variables that are declared have a value of 0 and not an 'Undefined' value) 

 



public int Add(int a, int B)
{
int c;
c = a + b;
return c;
}


 

Now, you first call it with: Add (2, 3);

the first time you call Add, c would have the value of 0, and then it gets the value of 2+3 ==> 5

Now you call it again, like Add(3, 5);

 

Do you expect that 'c' would still contain the value of 3?

It is being re-declared and it has the value of 0 again (and then it gets the value of 3 + 5 ==> 8)

 

 

The variable 'c' is being declared on the stack, since it is a local variable. Once you go out of the function, it is gone (this is why it is local... It leaves within the scope of the function.

And if Add would have a recursion (meaning it calls itself again and again, until a certain condition is true), then each call of the function will have it's own 'c' variable.

 

 

Because of the fact that local variables are lost when you leave the function, you can't also have a positive or negative transition on the bits.

The reason why you can't do a positive or negative transition on Function-In/Function-Out bits is because on each call you can pass a different bit (so you can't correctly detect a Rise or Fall).

 

 

If you do want to latch a bit inside a UDFB, then it must be passed by Ref, meaning, it must a be a global bit which is passed by either as Function-Out, or Array of Bits / Strcut that contains a bit that is passed as Function-In

(And with this way, you can pass a different bit on each time),  or just work with a global bit.

  • Upvote 2

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
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.