Detecting EN of function inside the function in step 7

syma710

Member
Join Date
Sep 2008
Location
Konstanz
Posts
15
Hi all of you,

I am working with Step 7 and having some trouble to do this. What I want is to detect when the function becames active but inside the function. Specifically, what I'm trying to do is reset a bit inside the function when the function is called. Can that be done?
Any bits of status word can help me on that? I remember I once worked with a CLP, can't remeber which was, that had a bit active for the first cycle, something like OB101 in Step 7. Have functions something alike?

Thanks.
 
If the function is being called it will execute, if not it will not execute. Thus code inside the block will be:
Code:
SET
R aBitInsideTheFunction

How will the bit ever get set again?
 
Understood. But I think I haven't explined myself quite well.

The thing is. I have this bit inside the function which is set and indicates the operation of the function is done and should be reset when the function is called once again, but only with a rising edge.
I would say is something like a JOB_DONE and JOB_REQUEST for the SFB47 Counter for example. Except that it wouldn't be a Funtion Block but just a Function.
What is tricky here is that I wouldn't like to make as an input, but as an extension from EN, so that with a conditioned call I can solve the problem of calling the funtion and detecting it was called.

I am really just asking if anyone has done it already. Hope it is clearer now.

Thanks.
 
couldnt you call the block by the request bit, and have the done bit as the last statment?
 
Something like that yes.

I would like to execute this instruction once when the function is called and then no more until it is called again, when it would again run just once.
The problem is that the cyclic nature of CLPs doesn't allow me to do that.
 
I alredy tried with a timer. But it also needs a positive edge to start working so I remain with the same problem. My function executes once and then no more because my done bit is set.


FUNCTION 312 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
Handling_Unit_DB : BLOCK_DB ;
Counter_DB : BLOCK_DB ;
Cylinder_Up : BOOL ;
Z_retracted : BOOL ;
FB_Reference_Interface_1 : BOOL ;
Home_position : BOOL ;
Reference_Position : DINT ;
Initial_Position : DINT ;
Counter_Delay : TIMER ;
auxTimer : TIMER ;
END_VAR

VAR_OUTPUT
Motor_Clockwise : BOOL ;
Motor_Counterclockwise : BOOL ;
Reference_end : BOOL ;
Lift_cylinder : BOOL ;
Z_axis : BOOL ;
END_VAR
VAR_TEMP
JOB_DONE : BOOL ;
InitialPos_is_clockwise : BOOL ;
Actual_Position : DINT ;
Home_flag : BOOL ;
Clockwise_flag : BOOL ;
Counterclockwise_flag : BOOL ;
Done_reference : BOOL ;
auxFlag : BOOL ;
END_VAR

BEGIN
NETWORK
TITLE =Flags inisitalisation
// AUF #Handling_Unit_DB
// L B#16#0
// T DBB 12
// T DBB 13
// T DBB 14
// T DBB 15
// O DBX 4.0
// ON DBX 4.0
// S DBX 14.0

NETWORK
TITLE =Reference vertical cylinder
AN #Cylinder_Up;
S #Lift_cylinder;

NETWORK
TITLE =Reference Z axis
A #Cylinder_Up;
AN #Z_retracted;
R #Z_axis;

NETWORK
TITLE =Home position
AN #Home_position;
A #Z_retracted;
AN #Reference_end;
S #Home_flag;
A( ;
O #Home_position;
O #Clockwise_flag;
O #Counterclockwise_flag;
O #Reference_end;
) ;
R #Home_flag;
NOP 0;

NETWORK
TITLE =Counter Delay
A #Home_position;
L S5T#1S500MS;
SD #Counter_Delay;
NOP 0;
NOP 0;
NOP 0;
NOP 0;

NETWORK
TITLE =Counter reference

A( ;
O M 0.0;
ON M 0.0;
) ;
= L 7.0;
BLD 103;
A( ;
A #Home_position;
S M 0.4;
A #Counter_Delay;
R M 0.4;
A M 0.4;
) ;
= L 7.3;
BLD 103;
CALL "COUNT" , #Counter_DB (
SW_GATE := L 7.0,
JOB_REQ := L 7.3,
JOB_ID := W#16#1,
JOB_VAL := #Reference_Position,
COUNTVAL := #Actual_Position,
JOB_DONE := #JOB_DONE);
NOP 0;

NETWORK
TITLE =Arm is referenced
A #Home_position;
A #JOB_DONE;
S #Done_reference;

NETWORK
TITLE =Intial position detection
L #Initial_Position;
L #Reference_Position;
<D ;
= L 7.0;
A L 7.0;
BLD 102;
S #InitialPos_is_clockwise;
AN L 7.0;
R #InitialPos_is_clockwise;

NETWORK
TITLE =Jump for couterclockwise
A #InitialPos_is_clockwise;
JCN CCLK;

NETWORK
TITLE =Initial position clockwise
A( ;
L #Actual_Position;
L #Initial_Position;
>D ;
) ;
A #InitialPos_is_clockwise;
A #Counter_Delay;
A #JOB_DONE;
S #Clockwise_flag;
A( ;
L #Actual_Position;
L #Initial_Position;
<=D ;
) ;
R #Clockwise_flag;
NOP 0;

NETWORK
TITLE =Reference end Clockwise
A( ;
L #Actual_Position;
L #Initial_Position;
<=D ;
) ;
A #Done_reference;
= #Reference_end;

NETWORK
TITLE =Clockwise end
L #Actual_Position;
L #Initial_Position;
<=D ;
JC OUT;

NETWORK
TITLE =Initial position counterclokwise
CCLK: A( ;
L #Actual_Position;
L #Initial_Position;
<D ;
) ;
AN #InitialPos_is_clockwise;
A #Counter_Delay;
A #JOB_DONE;
S #Counterclockwise_flag;
A( ;
L #Actual_Position;
L #Initial_Position;
>=D ;
) ;
R #Counterclockwise_flag;
NOP 0;

NETWORK
TITLE =Reference end counterclockwise
A( ;
L #Actual_Position;
L #Initial_Position;
>=D ;
) ;
A #Done_reference;
= #Reference_end;

NETWORK
TITLE =Motor clockwise
OUT: A #Clockwise_flag;
= #Motor_Clockwise;

NETWORK
TITLE =Motor counterclockwise
O #Home_flag;
O #Counterclockwise_flag;
= #Motor_Counterclockwise;

END_FUNCTION

Here is what I have done. I have came up with two possibilities: in one it executes just once and in the other it keep going from the initial postion to the reference position back and forth.
I don`t wanna make a step sequence here because I would have troubles reseting the steps and the program could loose itself.

The code was done in Funtion Blocks (I'm not very good wit IL) and it was genereted by Step7 in IL.
 
Last edited:
The done bit is reset when the function detects a positive transition of the enable bit. If the function completes within the scan, then none of this will work. The function MUST take longer than one scan to complete. When the function completes, then set the done bit. External to the function, the set done bit should cause the enable input to reset (clear), the function MUST run at least once to detect the cleared enable input, then the enable input can be set to execute the function again. The key is remembering that this must take place over multiple scans.
 
Then in the function, if the enable bit didn't go through a positive edge (a cycle off, then a cycle on), or if you choose to use a level-triggered enable, i.e., run while the enable is set and the done is clear. In any case, if the condition for running the function is NOT met, then the code should exit the function. This becomes more like conditional logic (IF-THEN-ELSE).
 

Similar Topics

I've been called to a site to assist with an ASi fault. The line has been down for a couple of weeks following a failure of the ASi power supply...
Replies
6
Views
1,295
I am looking at an application where I will need to detect small hairline cracks in stamped metal parts. The sensing will need to be done in the...
Replies
10
Views
1,123
Hello everybody, I am working on a project which has HMI FTView SE 13 (Local) and controllogix L71 PLC. I have a question how does PLC detect a...
Replies
0
Views
510
So, we have one servovalve that is very critical to machine operation and idea is (or was) to detect if valve gets disconnected from analog output...
Replies
11
Views
2,890
I had bought a used PLC before but I had to return it. Once in a while its run mode shut off momentarily. I had the PLC on my desk. (No I/Os...
Replies
22
Views
5,362
Back
Top Bottom