day of week

joejoe

Guest
J
Hi, i have a controllogix. I made a routine who calculated a day of week.

ctu 0 to 6
acc = 6 and time clock is at midnith then reset ctu
ctu value = 0 then is sunday

it works good.

It is possible to know a day of week like a slc5/04
S:53 = day of week

i used GSV instruction
class name = WALLCLOCK
attribut name = datetime
dest = realtime[0]

I get year,date, hour, second only!!!
There is a way to get a day of week as 1 to 7?????????

thanks
 
I didn't think that you could get the day of the week out of an SLC. I would be interested in learning this. S:53 is not the day of the week.
 
to ganutenator

S:53 is the day of the week!
look up your rslogix500


Why in a plc like controllogix, who is very flexible, faster, smaller and EXPENSIVE, there doesn't have a day of the week!

Why AB scrap it from slc to controllogix.They was just a little word

Where is the logical!!!!!!!!

Controllogix is builted in ontario?
 
I stand corrected. The first thing I am going to do, is create a new program for my processor type in RSLogix. Then I am going to overwrite my old, defunct Status registers comments with the correct ones. Thanks.
 
Here try this. I found this on the RSLogix forum and it was submitted by Jon Trusik, Syntronix, Inc., St. Louis, MO

I tried it and it works (compact and effecient, only 7 rungs). Just make sure that you define the tag "Misc_Reals" as a real and not a DINT. It will seem to work, but there will be some days that will be incorrect.
==============================================

Here are 7 rungs in mnemonic form for a CLX processor to return the day of the week as 0 to 7, with Monday being 0. This should cover all years. Should you find any bugs, please let me know.


GSV(WALLCLOCKTIME,,DateTime,Wall_Clock.Year);

[MOV(Wall_Clock.Day,Day)MOV(Wall_Clock.Month,Month)MOV(Wall_Clock.Year,Year),LES(Month,3)[ADD(Month,12,Month),SUB(Year,1,Year)]];

[CPT(Misc_Reals[0],0.60000002*(Month+1))MOV(Misc_Reals[0],Misc_Dints[0]),SUB(Misc_Dints[0],Misc_Reals[0],Misc_Reals[0]),GRT(Misc_Reals[0],0)SUB(Misc_Dints[0],1,Misc_Dints[0])];

[DIV(Year,4,Year_R[0])MOV(Year_R[0],Year_I[0]),SUB(Year_I[0],Year_R[0],Year_R[1]),GRT(Year_R[1],0)SUB(Year_I[0],1,Year_I[0])];

[DIV(Year,100,Year_R[0])MOV(Year_R[0],Year_I[1]),SUB(Year_I[1],Year_R[0],Year_R[1]),GRT(Year_R[1],0)SUB(Year_I[1],1,Year_I[1])];

[DIV(Year,400,Year_R[0])MOV(Year_R[0],Year_I[2]),SUB(Year_I[2],Year_R[0],Year_R[1]),GRT(Year_R[1],0)SUB(Year_I[2],1,Year_I[2])];

CPT(Day_of_Week,(Misc_Dints[0]+Year_I[0]-Year_I[1]+Year_I[2]+Year+Day+(2*Month))MOD 7);


Jon Trusik
Syntronix, Inc.
St. Louis, MO
 
Day of the Week

I have found a much easier way to figure out the day of the week. I use this code to do "working hours" for the day shift from 6-4. At midnight the "day" counter counts up and then resets back to 1 on Sunday night at midnight. Day 1 is Monday, day 2 is Tuesday...day 7 is Sunday. You can take it further and assign the .ACC value of the counter to a string text to display a day of the week or use the number in a compare function if you're looking to do daily reminders.

This code was done in RSLogix 5000 v20.12

DayofWeek.jpg
 
The problem you may run into with code like this is that it relies on the processor being powered on, not faulted, and in run mode every single day at midnight. Most of the people on this forum will probably agree with me that in most cases, this is not realistic. Problems happen. That's why I personally prefer the calculation off the RTC as opposed to midnight-counters. Cinderella may not always make it to her carriage on time.
 
Yes you are correct, I should have specified this code is running on a 24/7 monitoring system with redundancy. Thank you for pointing that out.
 
I have some PLC 5 code that first calculates the Julian date from the clock and then calculates the day of the week, but its 18 rungs long.
 
Structured text for Logix:

Code:
(*To use this routine, create a DINT array of 12 elements called "MonthValue", and assign it as follows:
MonthValue[0] := 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5
The final value, DayOfWeek is just that, Sunday = 0, Monday = 1, etc.
*)

IF ((Year MOD 4) = 0) AND NOT ((Year MOD 100) = 0)
THEN 
    MonthValue[0] := 6;
    MonthValue[1] := 2;
ELSE
    MonthValue[0] := 0;
    MonthValue[1] := 2;
End_If;

DayOfWeek := (DayOfMonth + MonthValue[Month-1] + (Year MOD 100) + ((Year MOD 100) / 4) + 6) MOD 7;

This takes into account leap years, and non-leap years (centuries).
 
Oh well, too late to edit my above post, but I just recognized an two errors in it (memory failing me).

Here is the correct code:

Code:
(*  Day of Week Routine - rdrast
    This version compensates for leap years and non-leap years, as well as the oddball leap century.

To use this routine, create a DINT array of 12 elements called "MonthValue", and assign it as follows:
MonthValue[0] := 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5
The final value, DayOfWeek is just that, Sunday = 0, Monday = 1, etc.
*)

Year         := PLC_Time[0];
Month         := PLC_Time[1];
DayOfMonth     := PLC_Time[2];


IF (((Year MOD 4) = 0) AND NOT ((Year MOD 100) = 0)) OR ((Year MOD 400) = 0)
THEN 
    MonthValue[0] := 6;
    MonthValue[1] := 2;
ELSE
    MonthValue[0] := 0;
    MonthValue[1] := 3;
End_If;

DayOfWeek := (DayOfMonth + MonthValue[Month-1] + (Year MOD 100) + ((Year MOD 100) / 4) + 6) MOD 7;
 
S:53 is the day of the week!
look up your rslogix500

S:53 is only Day Of Week on the SLC5/05 - on all others SLC's it's "Reserved" for future use, in case a project is transferred to a different CPU.

But I still add my own routine even on a 5/05 when I need to know the Day Of Week, in case it ever needs put on a different CPU.
 

Similar Topics

Hi All, I'd like to know can we use DTR instruction to get a week pulse ? Could anyone please help me to understand that one ? I've managed to...
Replies
4
Views
163
The day of week program started changing day of week 2 hours early. It changes at 10 P.M. instead of 12A.M. Just started this year.
Replies
22
Views
2,570
For some reason that I do not understand, FactoryTalk is showing the Day of Week in the time and date display, despite the fact that this isn't an...
Replies
5
Views
1,202
This is the reason why I signed up here and decided to get some help before I tackle the traffic light program on Wednesday. It looked good on...
Replies
17
Views
11,641
Hey everyone. I am trying to create some logic that will turn on an output only during production times. M-F 5am to 3:30pm. The output is for...
Replies
3
Views
1,349
Back
Top Bottom