Adventures in Data-driven Automation Systems

Sunday, March 29, 2009

ControlLogix DateTime Add-ons

A cool new feature of ControlLogix v17 is add-on instructions. I had originally hoped that these would be great replacements for indirectly addressed subroutines since zooming into an instruction shows you the logic but only displays the data of the current instance of the instruction. However, Rockwell strongly discourages using add-ons for large, complex subroutines, and the inability to edit them online really made them undesirable for that use.

They are good for encapsulating reusable pieces of code though, and Rockwell has provided some samples that perform manipulation of DateTime values, which I have already put to good use. The instructions included are:


  • T_Add - Adds a time span to a DateTime and returns a new DateTime
  • T_Clock - Sets or returns the controller clock time
  • T_Diff - Returns the difference between two DateTime values
  • T_Dow - Returns the day of the week for the passed in DateTime value
  • T_Equ - Compares two DateTime values for equality
  • T_Geq - Compares if one DateTime value is greater than or equal to another
  • T_Grt - Compares if one DateTime value is greater than another
  • T_Leq - Compares if one DateTime value is less than or equal to another
  • T_Les - Compares if one DateTime value is greater than another
  • T_Lim - Compares if the DateTime value is within a low and high limit range
  • T_Neq - Compares two DateTime values for inequality
  • T_Now - Returns the current controller clock value
  • T_Scan - Returns the previous scan time
  • T_Sel - Uses an input bit to select one of two DateTime values
  • T_Sub - Subtracts a time span from a DateTime value and returns a new DateTime value
  • T_Sun - Returns the local sunrise and sunset times
  • T_TtoS - Converts a DateTime value into a human-readable string
  • T_Valid - Checks if the given DateTime value is valid

I used the T_Now and T_Sub instructions to calculate the local date/time using a local offset. We use UTC time in the PLC to avoid time change issues and calculate local time using the current local time offset.

You can find these by opening the Start Page in RSLogix5000, selecting Open Sample Project, and then choosing Add_On_Instruction_Samples.acd, or going to [Drive]:\RSLogix 5000\Projects\Samples\ENU\v17\Rockwell Automation\.

No comments: