S7-SCL check for empty variable when FB called

bert_iv

Member
Join Date
Apr 2011
Location
somewhere
Posts
5
Hello,
I have used this forum a few times already but this time the search function didnt give me what I needed.

this is my problem i made a FB (FB1) to process errors. this FB1 is called in a different multi-instance FB (FB2,DB2).
input variables:
Code:
VAR_INPUT               //entrees
    HFPos       : BOOL; //position of sensor
    Ack         : BOOL; //acknowledge error
    Delay       : S5TIME; //optional delay of HFPos signal
    T_NO        : INT; //to identify timer
END_VAR
now how do i check whether Delay is empty or not. If Delay is empty i do not need the timer. SCL does not support 'NULL' i have tried to generate a S5T#0ms time value to compare Delay with that but it would not compile. it seems i cant use S5T# values in an if statement or in a comparison.

when i call FB1 with S5T#0ms as Delay then it will call the FB and it will work but i think 10ms is minimum so it will use 10ms instead of 0ms? true?

full code
Code:
FUNCTION_BLOCK FB_ERROR_GEN 
TITLE = 'FB_ERROR_GEN'
//
// Analog Input 
//
VERSION: '1.0'
AUTHOR: 'IVENS'


(*VARIABLES******************************)
VAR_INPUT               //entrees
    HFPos       : BOOL;
    Ack         : BOOL;
    Delay       : S5TIME;
    T_NO        : INT;
END_VAR

VAR_OUTPUT              //sorties
    FAULT       : BOOL;
END_VAR

VAR_TEMP
    END_OF_TIMER :BOOL;
    BCD_time_value :S5TIME;
END_VAR

VAR
    Acknowledged: BOOL;
END_VAR

BEGIN
//
//start timer
//
BCD_time_value := S_ODT(
    T_NO:=T_NO,
    S:=HFPos,
    TV:=Delay,
    R:=FALSE,
    Q:=END_OF_TIMER);
//
//If timer finished set FAULT bit
//
IF END_OF_TIMER = TRUE THEN    
    FAULT:=TRUE;
//
//If timer no longer being activated and Ack=true then set FAULT bit to 0
//
ELSIF END_OF_TIMER = FALSE AND Acknowledged = TRUE THEN
    FAULT:=FALSE;
END_IF;   

//
//
//
IF FAULT = TRUE AND Ack=true AND Acknowledged = FALSE THEN
    Acknowledged := true;
ELSIF FAULT=FALSE AND Acknowledged = TRUE THEN
    Acknowledged := FALSE;
END_IF;
END_FUNCTION_BLOCK
thanks in advance!
 
Last edited:
Can you possiblly use IEC timers in stead ?

Dont know much about S5timers when it comes to "special" situations, such as when the setpoint is 0 ms. My guess would be that the output from the timer would be on allways. But not 100% sure, as S5timers are finicky. Best avoided.

IEC timers makes life much easier. For examply you can embed the IEC timers in the multiple instances. You can manipulate the timer setpoint with simple math, do compares etc.
 
Add a Bool input which you place TRUE or FALSE in. Then jump over the timer.

OR... set the timer number to a specific number, i.e. 1000 entered in timer int = no timer.
 
thanks for the tips.
I must admit i never used IEC timers before (force of habit i guess) I will look into that. If it doesnt work the way i want i will go for peter's solution.

Thanks, much appreciated
 
Use the AT keyword to acces the s5time variable as a word
e.g.

Code:
FUNCTION_BLOCK FB777 
TITLE = 'FB_ERROR_GEN'
//
// Analog Input 
//
VERSION: '1.0'
AUTHOR: 'IVENS'

(*VARIABLES******************************)
VAR_INPUT               //entrees
    HFPos       : BOOL;
    Ack         : BOOL;
    Delay       : S5TIME;
    T_NO        : INT;
    wTime AT Delay:WORD;    
END_VAR
VAR_OUTPUT              //sorties
    FAULT       : BOOL;
END_VAR
VAR_TEMP
    END_OF_TIMER :BOOL;
    BCD_time_value :S5TIME;
END_VAR
VAR
    Acknowledged: BOOL;
    bDoSomething:BOOL;
    bDoSomethingElse:BOOL;
END_VAR
BEGIN
//
//start timer
//
IF (wTime = w#16#0) THEN bDoSomething:=True; ELSE bDosomethingElse:=True; END_IF;
     
BCD_time_value := S_ODT(
    T_NO:=T_NO,
    S:=HFPos,
    TV:=Delay,
    R:=FALSE,
    Q:=END_OF_TIMER);
//
//If timer finished set FAULT bit
//
IF END_OF_TIMER = TRUE THEN    
    FAULT:=TRUE;
//
//If timer no longer being activated and Ack=true then set FAULT bit to 0
//
ELSIF END_OF_TIMER = FALSE AND Acknowledged = TRUE THEN
    FAULT:=FALSE;
END_IF;   
//
//
//
IF FAULT = TRUE AND Ack=true AND Acknowledged = FALSE THEN
    Acknowledged := true;
ELSIF FAULT=FALSE AND Acknowledged = TRUE THEN
    Acknowledged := FALSE;
END_IF;
END_FUNCTION_BLOCK
 

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
105
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
583
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
357
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
667
Hi all, This is my first post; I am new to PLC Controls stuff and English is not my native language, so I apologize in advance if something is...
Replies
4
Views
522
Back
Top Bottom