You are on page 1of 3

RSLogix 5000 - Controller_Kim:MainTask:MainProgram:Day_Of_Week

in file C:\RSLogix 5000\Projects\Kim_DayOfWeek.ACD


Relay Ladder Logic Listing - Total number of rungs: 7

7/22/2003 3:41:31 PM Page 1

To have the user program access the Time of Day Clock on ControlLogix processors, do the following.
1. Create a 7 element DINT array called Wall_Clock
2. Have rung with GSV instruction.
CIP Object Class = WallclockTime
CIP Object Name= n/a
Attribute = Date|Time
Dest = CLOCK[0]
3. Real Time clock values will be stored in CLOCK[0] through CLOCK[6] as year, month, day, hours, minutes, seconds.
Wall_Clock(0) = YEAR,
Wall_Clock(1) = MONTH,
Wall_Clock(2) = DAY,
Wall_Clock(3) = HOURS,
Wall_Clock(4) = MINS,
Wall_Clock(5) = SECS,
Wall_Clock(6) = MICRO SECONDS
GSV
Get System Value
Class Name WALLCLOCKTIME
Instance Name
Attribute Name
DateTime
Dest
Wall_Clock.Year
2003

FORMULA FROM "THE MATH FORUM", "http://mathforum.org/library/drmath/view/55837.html"


Here is a formula for finding the day of the week for ANY date.
N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2
where d is the number or the day of the month, m is the number of the month, and y is the year. The brackets around the divisions mean to drop the
remainder and just use the integer part that you get.
Also, a VERY IMPORTANT RULE is the number to use for the months for January and February. The numbers of these months are 13 and 14 of
the
PREVIOUS YEAR. This means that to find the day of the week of New Year's Day this year, 1/1/98, you must use the date 13/1/97. (It sounds
complicated, but I will do a couple of examples for you.)
After you find the number N, divide it by 7, and the REMAINDER of that division tells you the day of the week; 1 = Sunday, 2 = Monday, 3 =
Tuesday,
etc; BUT, if the remainder is 0, then the day is Saturday, that is: 0 = Saturday.
--------------------------------------------------------------------------------------------------N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2
Y = Year
M = Month
D = Day
Misc_Dints(1) = [ 3 ( M+1 ) / 5 ]
Misc_Dints(2) = [ YEAR / 4 ]
Misc_Dints(3) = [ YEAR / 100 ]
Misc_Dints(4) = [ YEAR / 400 ]
N = Day + (2 * Month) + Misc_Dints[1] + Year + Misc_Dints[2] - Misc_Dints[3] + Misc_Dints[4] + 2
MOV
MOV
MOV
Move
Move
Move
Source Wall_Clock.Day
Source Wall_Clock.Month
Source Wall_Clock.Year
22
7
2003
Dest
Day
Dest
Month
Dest
Year
22
7
2003
LES
Less Than (A<B)
Source A
Month
7
Source B
3

ADD
Add
Source A
Month
7
Source B
12
Dest

SUB
Subtract
Source A
Source B
Dest

Month
7

Year
2003
1
Year
2003

RSLogix 5000 - Controller_Kim:MainTask:MainProgram:Day_Of_Week


in file C:\RSLogix 5000\Projects\Kim_DayOfWeek.ACD
Relay Ladder Logic Listing - Total number of rungs: 7

7/22/2003 3:41:32 PM Page 2

Misc_Dints(1) = [ 3 ( M+1 ) / 5 ]
CPT
Compute
Dest

Misc_Reals[0]
4.8
Expression (3 * (Month + 1)) / 5
SUB
Subtract
Source A Misc_Reals[0]
4.8
Source B
0.5
Dest

Misc_Reals[1]
4.3

MOV
Move
Source Misc_Reals[1]
4.3
Dest
Misc_Dints[1]
4

MISC_DINTS(2) = [ YEAR / 4 ]
DIV
Divide
Source A

Source B

Year
2003
4

SUB
Subtract
Source A Misc_Reals[2]
500.75
Source B
0.5

Dest Misc_Reals[2]
500.75

Dest

DIV
Divide
Source A

SUB
Subtract
Source A Misc_Reals[4]
20.03
Source B
0.5

MOV
Move
Source Misc_Reals[3]
500.25
Dest
Misc_Dints[2]
500

Misc_Reals[3]
500.25

MISC_DINTS(3) = [ YEAR / 100 ]


4

Source B

Year
2003
100

Dest Misc_Reals[4]
20.03

Dest

DIV
Divide
Source A

SUB
Subtract
Source A Misc_Reals[6]
5.0075
Source B
0.5

MOV
Move
Source Misc_Reals[5]
19.53
Dest
Misc_Dints[3]
20

Misc_Reals[5]
19.53

MISC_DINTS(4) = [ YEAR / 400 ]


5

Source B

Year
2003
400

Dest Misc_Reals[6]
5.0075

Dest

Misc_Reals[7]
4.5075

MOV
Move
Source Misc_Reals[7]
4.5075
Dest
Misc_Dints[4]
5

RSLogix 5000 - Controller_Kim:MainTask:MainProgram:Day_Of_Week


in file C:\RSLogix 5000\Projects\Kim_DayOfWeek.ACD
Relay Ladder Logic Listing - Total number of rungs: 7

N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2


N = Day + (2 * Month) + Misc_Dints[1] + Year + Misc_Dints[2] - Misc_Dints[3] + Misc_Dints[4] + 2
Y = Year
M = Month
D = Day
Misc_Dints(1) = [ 3 ( M+1 ) / 5 ]
Misc_Dints(2) = [ YEAR / 4 ]
Misc_Dints(3) = [ YEAR / 100 ]
Misc_Dints(4) = [ YEAR / 400 ]
N = Day + (2 * Month) + Misc_Dints[1] + Year + Misc_Dints[2] - Misc_Dints[3] + Misc_Dints[4] + 2
SAT = 0, SUN = 1, MON = 2, TUE = 3, WED = 4, THUR = 5, FRI = 6
EXAMPLES:
3/18/98, N=2510, REMAINDER OF N/7 = 4, WEDNESDAY.
1/1/98, OR 13/1/97, N=2518, REMAINDER OF N / 7 = 5, THURSDAY.
SAT=0, SUN=1,
MON=2, TUE=3
WED=4, THUR=5
FRI=6
CPT
Compute
Dest

7/22/2003 3:41:32 PM Page 3

Day_of_Week
3
Expression (Day + (2 * Month) + Misc_Dints[1] + Year + Misc_Dints[2] - Misc_Dints[3] + Misc_Dints[4] +2) MOD 7

(End)

You might also like