0

I am trying to accomplish very simple task, but it looks like I cannot figure our how.

My task is daily schedule. output Q1 have to be HIGH every day from 1:00 to 2:00. I could not find function block that would help me. I decided to create my own.

Here are my definitions.

FUNCTION_BLOCK Shedule
VAR_INPUT
    EN: BOOL;

    MO: INT;
    TU: INT;
    WE: INT;
    TH: INT;
    FR: INT;
    SA: INT;
    SU: INT;

    T1: STRING;
END_VAR
VAR_OUTPUT
    Q: BOOL;
END_VAR

The idea is this. EN is input. It should be HIGH for output Q to become HIGH too.

Others are days of the week. I can set 1 or 0 if I want Schedule work on that day. Pretty much universal function block to create any type of schedules.

Question 1: When I make week day variables type BOOL, when I add block to the LD line, it creates contact for every week day parameter.

enter image description here

What can I do to make only EN contact connected to the line?

If I try to add function block with EN/ENO, then I do not know

1) How do I know inside function block that EN is HIGh or how do I get access to that variable? 2) I cannot connect coil to my Q output. it only connects to ENO. how do i control state of ENO?

But that is not all. I added Time and Date library

enter image description here

But only thing I found to work with time is RTCLK.GetDateAndTime function block. And i cannot figure out how to work with it.

My simple task is to get current TIME only and current day of the week and if this week is enabled and current time in the range in input T1 - make Q = HIGH otherwise LOW.

Any hints on that?

Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38

2 Answers2

1

Write a function block as follows which will be called cyclically (e.g. every 60sec):

  1. Reset your control bit at the beginning (you will set this bit too high if the current day and time is inside your specified interval)
  2. Read the current date and current time of the system clock of the CPU (Controller)
  3. Extract the actual time and actual day. Check if the actual time is inside your specified interval (e.g. 1:00 to 2:00) and set your control bit appropriate

You should use library functions for the handling of the day and time values. Maybe you should check out the free library OSCAT BASIC. The website is in German but the documentation and the software is in English.

dergroncki
  • 798
  • 1
  • 12
  • 24
  • Finally I've got it working. The key suggestion was OSACT BASIC. I have managed to get realtime bit I think I am getting it wrong. Could you show example how to read PLCs real time? – Sergey Romanov Sep 16 '15 at 17:58
0

This example is used to read the plc time and converts it to a string. This code was developed for a Siemens PLC with SCL (Structured Control Language):

(*************************************************************************************)

FUNCTION  FC11 : STRING

TITLE = 'Convert date and time to string'


(*******************************************************************************

 FUNCTION: Convert date and time to string

*******************************************************************************)

// ------------------------------------------------------------------------------
// parameter
// ------------------------------------------------------------------------------

VAR_TEMP

DTAsString          : STRING[14];

DateTime            : DATE_AND_TIME;
DateTimeAsByteArray AT DateTime
                    : ARRAY[0..7] OF BYTE;

ReturnValue         : INT;

Year                : INT;
Month               : INT;
Day                 : INT;
Hours               : INT;
Minutes             : INT;
Seconds             : INT;

END_VAR

// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------

//Inizialize 
DTAsString  := '';

//Read PLC date and time 
ReturnValue := READ_CLK(CDT := DateTime  // OUT: DATE_AND_TIME
                        );

//Split data and time value    
Year        := BCD_TO_INT(DateTimeAsByteArray[0]);
Month       := BCD_TO_INT(DateTimeAsByteArray[1]);
Day         := BCD_TO_INT(DateTimeAsByteArray[2]);
Hours       := BCD_TO_INT(DateTimeAsByteArray[3]);
Minutes     := BCD_TO_INT(DateTimeAsByteArray[4]);
Seconds     := BCD_TO_INT(DateTimeAsByteArray[5]);

//Build string
//------------

//Year
//----
IF (Year >= 10) THEN
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '20');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= INT_TO_STRING(Year),L:=2));
ELSE
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '200');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= INT_TO_STRING(Year),L:=1));    
END_IF;    

//Month
//-----
IF (Month >= 10) THEN     
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= INT_TO_STRING(Month),L:=2));
ELSE
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '0');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= INT_TO_STRING(Month),L:=1));        
END_IF;

//Day
//---
IF (Day >= 10) THEN
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Day),L:=2));
ELSE
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '0');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Day),L:=1));
END_IF;

//Hours
//-----
IF (Hours >= 10) THEN
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Hours),L:=2));
ELSE
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '0');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Hours),L:=1));
END_IF;

//Minutes
//-------
IF (Minutes >= 10) THEN
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Minutes),L:=2));
ELSE
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '0');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Minutes),L:=1));
END_IF;

//Seconds
//-------
IF (Seconds >= 10) THEN
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Seconds),L:=2));
ELSE
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= '0');
    DTAsString :=  CONCAT (IN1:= DTAsString, IN2:= RIGHT(IN:= I_STRNG(Seconds),L:=1));
END_IF;

//Return Date and Time as String
//------------------------------    
FC11 := DTAsString;

END_FUNCTION

//*******************************************************************************

(* Nothing beyond this *)
dergroncki
  • 798
  • 1
  • 12
  • 24
  • What is READ_CLK? Where did you take that function? – Sergey Romanov Sep 19 '15 at 16:47
  • The system functions (SFC) SFC 1 "READ_CLK" is contained in the operating systems of the Siemens CPUs of the S7-300 and S7-400. With SFC 1 "READ_CLK" (read system clock), you read the current date or current time of the system clock of the CPU. On the other hand with SFC 0 "SET_CLK" (set system clock), you set the time and the date of the CPU clock. Normally functions like this should be provided by the PLC manufacturer and are part of the operating system which is running on the PLC. What kind of system (PLC) you are using? – dergroncki Sep 20 '15 at 07:28
  • Now I get it. This is supported by siemens. Unfortunately not by may PLC which is OWEN. – Sergey Romanov Sep 21 '15 at 10:58
  • The PLC must be equipped with a “Real Time Clock” (RTC) and the manufacture must provide functions to read and write the RTC. – dergroncki Sep 21 '15 at 15:22