Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

date algorthim for an Allen Bradley PLC

Status
Not open for further replies.

DASKAT

Industrial
Nov 7, 2003
26
Does any one know of an algorithm for converting the date stored in the S2 status file to the day of the week? I have been toying with this and am having dificulty trying to truncate and find the mod ie the remainder of a division while trying to program this PLC-5.thanks again folks
THE KAT
 
Replies continue below

Recommended for you

First we'll assume dates in the Gregorian calendar that fall between 01/01/1800 to 12/31/9999. All math must be 16-bit integer math. If you use floating point numbers, the answer won't be correct. In the PLC-5, you can use a series of CPT commands. For example, the first one: Dest=N7:10 Expression=(14.0 - S:20) | 12.0. The next CPT Dest= N7:11 Expression= S:18 - N7:10. The next CPT Dest= N7:12 Expression=(S:19 + (12 * N7:10)) - 2. And the final CPT Dest= N7:13 Expression= ((((S:20 + S:18) + (S:18 | 4)) - (S:18 | 100)) + (S:18 | 400)) + (((31 * S:19) | 12) MOD 7).

N7:13 contains the answer. 0=Sunday thru 6=Saturday.
 
Sorry, I had a small mistake in the last CPT command. The expression should read ((((S:20 + N7:11) + (N7:11 | 4)) - (N7:11 | 100)) + (N7:11 | 400)) + (((31 * N7:12) | 12) MOD 7)
 
Rdub,
thanks for the help but every time I attempt to use the MOD function in the program my PLC crashes horifically and I think the basic equations may be off as I attempted to work them by hand and was unable to come up with a sufficient answer.But thanks again for your time.
TTFN
THE KAT
 
Sorry to hear that you are having problems. Unfortunately, I do not have a PLC-5 here to verify this code. Note that all division must be integer division. If you verify this equation using your calculator, the answer will be incorrect since your calculator using floating point division. Also, The MOD instruction is only used in Enhanced PLC-5 Series C Revision C and later processors.
This equation was obtained from the web site
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor