› PLCGurus.NET Live & Interactive Forum › PLC Questions and Answers › Rockwell, Allen-Bradley, Stratix › Time Elapsed
- This topic has 4 replies, 4 voices, and was last updated 1 year, 9 months ago by
ishortho.
- AuthorPosts
- December 22, 2021 at 12:27 pm #20462
Ranga
ParticipantKarma: 25Rank: Padawanhow do you calculate time elapsed between two dates
December 22, 2021 at 12:46 pm #20463tfgmedia_admin
KeymasterHi Ranga and welcome to the forums.
Since you did not specify the type of controller you’re using, I’m going to assume it is a ControlLogix platform of controller. In this case, you can use the GSV (Get System Value) instruction to get the current date/time from your CPU. You can parameterize the GSV as follows:
Class Name: WallClockTime
Instance Name:
Attribute Name: LocalDateTime
Dest: Get_Date_Time[0]
The Get_Date_Time[] tag is setup by creating an array of DINT[7] with each element of the array holding a corresponding portion of the date/time. Below is the actual array assignment:
DINT[0] = Year
DINT[1] = Month (1..12)
DINT[2] = Day (1..31)
DINT[3] = Hour (0..23)
DINT[4] = Minute (0..59)
DINT[5] = Seconds (0..59)
DINT[6] = Microseconds (0..999,999)Once you have the tag setup and the GSV parameterized and added to your logic to execute every scan you can build the additional logic you’ll need to grab the time stamps. This could get tricky when your dates span different months, but hopefully this will get you started in the right direction.
If you provide more information, perhaps we can get more community involvement to help solve your issue.
Cheers
December 22, 2021 at 5:21 pm #20471mark88590
ParticipantKarma: 20Rank: PadawanIf it is AB we are discussing there is a neat AOI you can use to calculate time between dates. It is in the sample code library. Just search something like “time between”. It should be one of the top hits from the search.
December 23, 2021 at 10:02 am #20496Ranga
ParticipantKarma: 25Rank: PadawanIt is an AB controller. i need to set a reminder to replace UPS batteries after every 2 years. thanks for the suggestions. i will try them and give feedback once i get back to office early next year.
Cheers. A happy Festive season.
December 23, 2021 at 10:12 am #20497ishortho
ParticipantKarma: 21Rank: PadawanUsed that AOI it’s easy to implement and does the job. Search for “Elasped Time Add-on Instruction” (Yes, Elapsed is spelled wrong ?)
- AuthorPosts
- You must be logged in to reply to this topic.