Sign in to follow this  
Followers 0
pfort

Structured text in FB

6 posts in this topic

I have a question on programming a FB in ST: Is there a way to read and copy the content of a variable on a rising edge of the EN input, or, in a very short laps of time? In that FB i need to make some maths with the value that this variable had at the moment of the step that enable the EN input. What i mean is something similar to : @MOV Thanks

Share this post


Link to post
Share on other sites
Hello pfort, Be careful using a rising edge contact (or falling edge) on the EN pin of a FB. The initial scan of a FB is used for initialisation of the variables. After that, nothing will happen inside the FB. There are two ways that you could tackle this (probably more, but well, this is free advice ). 1. On your event trigger, set a coil with a diff-up property, create an Input variable for your FB, which then uses a contact of the Diff'd coil. 2. Use your event trigger as an Input variable for you FB, and write some one-shot code in ST Maybe something like... If EventTrigger And Not InternalReset Then Internal Reset := True ; (* YOUR ONE SHOT CODE GOES HERE *) Else ; If Not EventTrigger Then InternalReset := False ; Else ; End_If ; End_If ; Hope this helps

Share this post


Link to post
Share on other sites
That's a slick way of doing it. Should the InternalReset be an external value, or will it maintain its value as a internal value. Just wondering since it is a function block.

Share this post


Link to post
Share on other sites
Some ideas/comments. Always, always using the ALWAYS ON flag [i think it's CF113] ahead of each function block declaration!! Define a Global Symbol variable as ONESHOT of type BOOLEAN at a memory location. For example W0.0. Use the following inside the FB:- IF ONESHOT THEN (*Enter the code you want to process here*) END_IF; ONESHOT:=FALSE; There are three methods to access ONESHOT within the FB:- 1.If ONESHOT is declared as an Input Variable of type Boolean then you need to enter the required input in the function block instance in ladder. From above example W0.0. 2.If ONESHOT is declared as an Internal Variable of type Boolean then you need to use the AT setting. AT = W0.0. 3.If ONESHOT is declared as an External Variable of type Boolean in the FB then you need to declare an identical ONESHOT variable in the Global Symbols as type Boolean. [note that text case is critical to the variable name. A variable "OneShot" is evaluated as a different variable than "ONESHOT"] With the above code you can use a DIFU or @SET ladder instruction on the Global Symbol ONESHOT to trigger your FB code. I prefer method 3 above since if I change the Global symbol from W0.0 to say W100.12, the FB automatically changes.

Share this post


Link to post
Share on other sites
Hello Arjan, "InternalReset" is an Internal variable, and will hold its value until otherwise set by the conditions of the ST.

Share this post


Link to post
Share on other sites
Thanks anonymous, I switched to Omron recently. I've been using CP1Hs sofar. I used to use the S7-200 through the microwin software. I was used to Function blocks where you loose the internal variables every time it scans through the function. I am really liking the structured text function blocks, I started programming basic, pascal, & C++ back in the 80's when I went to school. I am using the edge detection for a counter, counting the edges if P_1S. It's an easy way to create your own timer.

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
Sign in to follow this  
Followers 0