S7 Day of Week from SFC1 and FC7

mrt19

Member
Join Date
Mar 2009
Location
Virginia
Posts
42
Hello all, I am having troubel getting the day of week data out of the SFC1 and FC7 functions. I am able to get a number from FC7 but the number continuously counts up from -32000 to 32000 and then repeats. It takes only about 60 seconds for the cycle to repeat.

However, when I go into the simulator it workd fine. But is does not work in the actual plc. I believe I should get an integer between 1 and 7 depending of whick day of the week it is.

I have read though numerous posts on this subject but none of them concern the problem I am having.

Any ideas on why this is happenning, thanks, mrt19
 
The output from FC7 should give you an integer in the range 1 to 7; with 1 being Sunday, 2 being Monday etc up to 7 = Saturday.

What else have you in the PLC?
Are you over writing the same data area that you have assigned the RET_VAL of FC7 elswhere in your program?
 
Try this - example is inside a FB

CALL "READ_CLK"
RET_VAL:=#iResultSfc1 // Temp data type = Int
CDT :=#dtReturned_time //Static data type Date_and_time

LAR1 P##dtReturned_time // Load Address register 1 with D+T

L B [AR1,P#7.0] // Offset to day area
BTI // convert BCD to integer
T #iWeekday // transfer to Static integer Weekday

No FC7 needed

As Moggie says 1 being Sunday, 2 being Monday etc up to 7 = Saturday
 
Last edited:
Note: this will not work if the FB is used in a multiple instance The day of the week is in the lower byte of byte 7. See code below:

timep.jpg
 

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
180
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,669
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,225
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,702
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,361
Back
Top Bottom