clockAlarm (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


clockAlarm is a convenient way of setting an alarm at a specific time. This function block lets you set alarms that will occur periodically. If one or more of the input parameters to the function block are omitted, they are not used in setting the alarm time.

 

Input:

 

enable : BOOL

Set to true to activate the timer.

 

month : INT (-1, 1 .. 12) (Default: -1 (not used in comparison))

The month.

 

day : INT (-1, 1 .. 31) (Default: -1 (not used in comparison))

The date.

 

hour: INT (-1 .. 23) (Default: -1 (not used in comparison))

The hour.

 

minute : INT (-1 .. 59) (Default: -1 (not used in comparison))

The minute.

 

second : INT (-1 .. 59) (Default: -1 (not used in comparison))

The second.

 

Output:

q : BOOL

When the time is reached, q will become TRUE.

 

Declaration:

FUNCTION_BLOCK clockAlarm;
VAR_INPUT
  enable : BOOL := false;  
  Month : INT := -1;   // 01..12    
  Day   : INT := -1;   // 01..31    
  Hour   : INT := -1;  // 00..23    
  Minute : INT := -1;   // 00..59    
  Second : INT := -1; // 00..59    
END_VAR;
VAR_OUTPUT
  q     : BOOL;    
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  Alarm_1 : clockAlarm; // Declare an instance of the clockAlarm functionblock
  Alarm_2 : clockAlarm; // Declare an instance of the clockAlarm functionblock
  Alarm_3 : clockAlarm; // Declare an instance of the clockAlarm functionblock
END_VAR;
 
// Set the alarm to December 24th. Please note that the hour, minute and second are not assigned, and therefore not used in the alarm time.
Alarm_1(enable:=TRUE, month:=12, day:=24); // This will give an alarm at midnight 00:00:00 the 24th of December
// Set the alarm to December 31th every year at 23:55. Please note that the second are not assigned, and therefore not used in the alarm time.
Alarm_2(enable:=TRUE, month:=12, day:=31, hour:=23, minute:=55); // This will give an alarm exactly at 23:55:00 the 31th of December
// Set the alarm to occur on each full hour.
Alarm_3(enable:=TRUE, minute:=0); // This will give an alarm at the beginning of each hour
BEGIN
  Alarm_1();
  Alarm_2();
  Alarm_3();
  ...
  IF Alarm_1.q THEN
    DebugMsg(message:="Merry Christmas");
  END_IF;
  IF Alarm_2.q THEN
    DebugMsg(message:="New year in 5 minutes !");
  END_IF;
  IF Alarm_3.q THEN
    DebugMsg(message:="A new hour has begun");
  END_IF;
 ...
END;
END_PROGRAM;