SCL question / problem

userxyz

Member
Join Date
May 2002
Location
any
Posts
2,768
Hi, I'm new to SCL. Please don't say: use STL or something, the reason that I want to make it in SCL is because I can put formulas in it without ACCU thinking. I have to be able to show it to other people who are not programmers. So, I know STL, LAD, and FBD, but I'm new is SCL.


First I'll try to explain a bit:

We have 2 kind of carpets, loper and tapijt. Tapijt is the actual carpet where machines have to work.

So, when we start the machine now, everything starts. But to reduce the energy consumption, they want to start the several machine in the line when the carpet is located there.

So TAPIJT = Production and LOPER = the precarpet (just garbage).

We have a sensor connected on an INPUT that can say at the beginnening of the line that it's a production or loper.

So, when production starts, INPUT = 0, then a pulse sensor that gives 0,4 m/puls counts the meters.

When we arrive at a machine (DIST = distance to machine) - minus the predistance of 2m for example, then TAPIJT is 1, that machine has to start all burners, sprays or whatever. The endpoint is also calculated.

The problem is now, this WORKS, but..., if 2 or 3 short peaces of production are running in the line, then this will not work.

So in a max of 3 short productions we have to think something out. I am thinking on, calculating the beginpoint, endpoint of each peace ... and using a database...

Other ideas ?

This is my code until now (like I said, I'm a beginner who bought an SCL license, so I really want to keep it in SCL):



FUNCTION FC007: VOID
VAR_INPUT
INPUT :BOOL;
RUN: BOOL;
PULS_FP: BOOL;
PULS_LENGTE: REAL;
DIST_NAAR: REAL;
DIST_VOOR: REAL;
DIST_NA: REAL;
DIST_AGG: REAL;
END_VAR

VAR_OUTPUT
LOPER: BOOL;
TAPIJT: BOOL;
POS_NAAD_Loper: REAL;
POS_NAAD_Tapijt: REAL;
END_VAR

VAR_TEMP
PULS: REAL;
END_VAR

BEGIN

IF PULS_FP THEN
PULS := 1;
ELSE
PULS := 0;
END_IF;

IF RUN AND INPUT THEN // LOPER TELLING
POS_NAAD_Loper:= POS_NAAD_Loper + (PULS * PULS_LENGTE);
POS_NAAD_Tapijt:= 0;
END_IF;

IF RUN AND NOT INPUT THEN // TAPIJT TELLING
POS_NAAD_Tapijt:= POS_NAAD_Tapijt + (PULS * PULS_LENGTE);
POS_NAAD_Loper:= 0;
END_IF;

IF DIST_NAAR-DIST_VOOR < POS_NAAD_Tapijt AND DIST_NAAR + DIST_NA + DIST_AGG > POS_NAAD_Loper THEN // EVALUATIE TAPIJT OF VOORLOPER
TAPIJT:= True;
LOPER:= False;
ELSE
LOPER:= True;
TAPIJT:= False;
END_IF;


END_FUNCTION
 
Sounds like a job for a shift register. Store the type of carpet from your carpet sensor and shift the register each time you receive a length pulse. Make the shift register long enough and you will then have "knowledge" of what type of carpet is where in your process.
 
...

I understand a shift register, but if there are 3 carpets in the process..., how can I define if a machine needs to start an stop, compare with 3 stored values ?

L D[AR2 said:
Sounds like a job for a shift register. Store the type of carpet from your carpet sensor and shift the register each time you receive a length pulse. Make the shift register long enough and you will then have "knowledge" of what type of carpet is where in your process.
 
but

but I understand you shift register idea, and it's very good

If INPUT is low, then it's productioncarpet

If INPUT is high, then it's no productioncarpet

On rising and falling edges I need to store in a shift register.

Something like this in STL I think:

DATA REGISTER =
DB10.DBD0
DB10.DBD4
DB10.DBD8
DB10.DBD12
DB10.DBD16
DB10.DBD20

So example for falling edge:

A #INPUT
FN #MEMBIT_1
JCN E_1
OPN DB10
L DBD16
T DBD20
L DBD12
T DBD16
L DBD8
T DBD12
L DBD4
T DBD8
L DBD0
T DBD4
L #CURRENT_LENGTH
T DBD0
E_1



How can I do this in my scl code ?
 
Here's some example code. I've shown two methods for the shift register, one using DB reference, the other referring to a static array.

Code:
FUNCTION_BLOCK FB01
VAR_INPUT
INPUT:BOOL;
CURRENT_LENGTH:DWORD;	
END_VAR	
VAR
bEdgeStore:BOOL;	
ShiftRegister:ARRAY[1..10] OF DWORD;
END_VAR
VAR_TEMP
  // Temporary Variables
bEdgeDetected:BOOL;
i:INT;
END_VAR
//Falling Edge detection
bEdgeDetected:= (NOT INPUT) AND bEdgestore;
bEdgeStore:=INPUT;
IF bEdgeDetected THEN
//shift directly addressed DB
 DB10.DBD20:=DB10.DBD16;
 DB10.DBD16:=DB10.DBD12;
 DB10.DBD12:=DB10.DBD8;
 DB10.DBD8:=DB10.DBD4;
 DB10.DBD4:=DB10.DBD0;
 DB10.DBD0:=CURRENT_LENGTH;
	
END_IF;   
IF bEdgeDetected THEN
//shift a static array	
	FOR i:=1 TO 9 DO
	 ShiftRegister[11-i]:=ShiftRegister[10-i];	
	END_FOR;	
	ShiftRegister[1]:=CURRENT_LENGTH;
END_IF;
END_FUNCTION_BLOCK
 
Some quenstions

Tnx a lot,

just some questions about your code:

Can you explain how a FN works in SCL:

//Falling Edge detection
bEdgeDetected:= (NOT INPUT) AND bEdgestore;
bEdgeStore:=INPUT;

???


AND, how can I do a Possitive edge detection, because, the shift has to work on both.



L D[AR2 said:
Here's some example code. I've shown two methods for the shift register, one using DB reference, the other referring to a static array.

Code:
FUNCTION_BLOCK FB01
VAR_INPUT
INPUT:BOOL;
CURRENT_LENGTH:DWORD;	
END_VAR	
VAR
bEdgeStore:BOOL;	
ShiftRegister:ARRAY[1..10] OF DWORD;
END_VAR
VAR_TEMP
// Temporary Variables
bEdgeDetected:BOOL;
i:INT;
END_VAR
//Falling Edge detection
bEdgeDetected:= (NOT INPUT) AND bEdgestore;
bEdgeStore:=INPUT;
IF bEdgeDetected THEN
//shift directly addressed DB
DB10.DBD20:=DB10.DBD16;
DB10.DBD16:=DB10.DBD12;
DB10.DBD12:=DB10.DBD8;
DB10.DBD8:=DB10.DBD4;
DB10.DBD4:=DB10.DBD0;
DB10.DBD0:=CURRENT_LENGTH;
 
END_IF; 
IF bEdgeDetected THEN
//shift a static array	
	FOR i:=1 TO 9 DO
	 ShiftRegister[11-i]:=ShiftRegister[10-i];	
	END_FOR;	
	ShiftRegister[1]:=CURRENT_LENGTH;
END_IF;
END_FUNCTION_BLOCK
 
Positive or rising edge detection:

Code:
//Rising edge detection
bRisingEdgeDetected := INPUT AND (NOT bEdgeStore);
//Falling Edge detection
bEdgeDetected:= (NOT INPUT) AND bEdgestore;
bEdgeStore:=INPUT;

bEdgeStore is the value of INPUT from the last scan.
Rising edge detected when INPUT=1 and the value from the last scan=0
Falling edge detected when INPUT=0 and the value from the last scan=1
 
I think Combo is asking for this

Code:
//Rising and falling Edge detection
bRisingEdgeDetected:= INPUT AND (NOT bEdgestore);
bFallingEdgeDetected:= (NOT INPUT) AND bEdgestore
bEdgeStore:=INPUT;
I think the methods above are as easy as any method but there should be a R_TRIG and F_TRIG function too as they are part of the IEC 61131-3 specification. So far no one has verified if SCL has either. I am too lazy right now to find out.

Notice this is an example of how one bEdgeStore can be used for two one shots. Normally I recommend caution and use an edgestore only once instead of twice as above.
 
Hi

I've tried this:

FUNCTION FC010: VOID
VAR_INPUT
INPUT :BOOL;
END_VAR

VAR_OUTPUT
PULS: BOOL;
END_VAR

VAR_IN_OUT
Store: BOOL;
END_VAR
VAR_TEMP
Detec: BOOL;
END_VAR
BEGIN
//Falling Edge detection
Detec:= (NOT INPUT) AND Store;
Store:=INPUT;

END_FUNCTION



And this is written on the outside of this block to test:


CALL FC 10
INPUT:=I0.0
PULS :=Q5.0
Store:=M50.0
A Q 5.0
CU C 1
L C 1


The counter doesn't count up when I change INPUT
 
Code:
IF Detec
THEN PULS:=true;
ELSE
PULS:=false;
END_IF;
So why not write
Code:
PULS:=Detec;
I hate using IF...THEN...ELSE statements for Boolean assignments.

Regards
Ken
 
hey

PULS is an INT

Ken M said:
Code:
IF Detec
THEN PULS:=true;
ELSE
PULS:=false;
END_IF;
So why not write
Code:
PULS:=Detec;
I hate using IF...THEN...ELSE statements for Boolean assignments.

Regards
Ken
 

Similar Topics

HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
103
Hello, When you want compare values of an array to a range of numbers is it a right way to do that? FUNCTION ADD VAR_IN_OUT A:ARRAY[1..50]...
Replies
5
Views
2,091
I just found a piece of code using an operator "+=" IF tag1 AND tag2 THEN tag3 += tag4; tag5 := tag5 + tag6; END_IF; I don't...
Replies
11
Views
4,859
I am having difficulty doing something i do in every other plc without a problem I have created an SCL AOI. I have an integer input to it. Lets...
Replies
3
Views
1,618
I am new to PLC programming. Is there a standard way to incorporate alarms / warnings / events such as the exceptions in C++ or Java where you can...
Replies
5
Views
2,007
Back
Top Bottom