How to check current day of week against a array

Bullzi

Lifetime Supporting Member
Join Date
Jun 2012
Location
Colorado
Posts
1,530
Hi Everyone,
Doing a project with a Automation Direct P2000 PLC. I am using the most up to date version of the Productivity Suite Software.



Using a HMI I will set what days of the week that I want the event to happen. Then I want to check the Current Day of the Week against that array or ? to see if I need to run the event.


I wanted to solicit some ideas on how to do this. The P2000 does have an Current Day of Week tag that will give me a 1=Mon to 7=Sun so I don't need to do any logic on that side. Just wondering the best way to store the days I want the event to run and then best way to check the current day against that.


Thanks!!
 
Here is what I have done so far:
I have a 8 Bit register that I use to store the current day of the week in binary. So for Monday the register is 0000 0001 for Tuesday it is 0000 0010 all the way up to Sunday 0100 0000. I do this first thing after a change in the day.

I also have a 8 Bit register that I store the days that I want the event to run. The 1 in the bit position 1-7 determines if that day is selected.


Now I want to use a For/Next instruction to compare the Day of week bit map against the Days to run bit map and if I find a 1 in the same position in both maps I will set a tag and exit the loop as I know know that today is a day to run.


I am trying to use the compare instruction but I am not sure how to address the bits in a 8 bit word individually in Productivity. Would be easy in a AB controller but scratching my head now.


Thanks for any help you can provide.
 
does each event runs once per selected day, just after the previous midnight?


what programming environment (ST, LAD, FBD)?


I would probably put the day go/no-go bits in a single group (e.g. bits 1 through 7 of some kind of integer) that could be addressed by the day of the week - that leaves bit-0 free as an override to enable or disable events for the entire week without changing the selected days.


That assumes there is a way to indirectly address the bits of the group with the [day-of-week] value.


Each event would be in its own subroutine (module, or whatever Productivity calls it), and each event module would get called every scan from the main routine, and each module would have logic at the top to short-circuit and not execute the event module if

  1. the day-of-week did not change from the value in the previous program scan,
  2. the override bit, bit [0], is 1
  3. bit [day-of-week] is 0
Step 1 means the value of [day-of-week] from the previous program scan is persistent, but that could be done globally and once in the main program and the changed/not-changed result placed in a bit for each module to test.


For Step 3, if Productivity does not make it easy to test individual bits, you can do a bit-wise AND of the current day 8-bit register (00000010 Mon; 00000100 Tue, etc.) as an integer with the 8-bit register of the enabled days-of-week: if the result is 0 then that day is disabled and the event module returns control to the main module at Step 3.


I see you are using bits 0 through 6 for the days-of-week, so maybe bit 7 is your event override.


The only compare is the the bit-wise AND result against 0; no loops required.
 
Now I want to use a For/Next instruction to compare the Day of week bit map against the Days to run bit map and if I find a 1 in the same position in both maps I will set a tag and exit the loop as I know know that today is a day to run.

Bit of word addressing is done using the colon ":". I think bit of word indirection is not even possible.

So your machine will have a bit set for each day of the week it needs to run...
That's just 7 bits, I would not mess with a loop, just have 7 rungs something like this:

By the way, PSuite numbers their bits and array elements starting with "1" unlike every other computer programming language I have ever dealt with. There is no bit zero. There is no array element 0. Stupid. I detest it. There are about 12 things I strongly dislike about PSuite, the lack of bit level indirection and abandonment of the zero position are toward the top of my list of gripes. There are things to love about it though.

PSuiteDayCheck r000.png
 
Last edited:
Thanks Paul, I used your idea and made it work. Guess I was looking for a more elegant solution. As it pointed out many times on this forum brute force is often the best solution.


Well that is too bad that the P2000 wont do Bit of word Indirect addressing. That can be a powerful feature.
 

Similar Topics

Hi All, I don't do much analog, and I do even less with 4-20ma current loops. Here's what I'm thinking of doing; I'd like a double check so I...
Replies
14
Views
7,263
Hello all, I have a Controllogix 1756-L61 with some RIO. There are a couple of 1734-OB4E's that have gone bad. (no output voltage) My boss found...
Replies
10
Views
1,053
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
0
Views
399
Hello I am new here and new to PLC's, I wrote this program for a class that I am taking and my local tech school. The description is switch 7 will...
Replies
10
Views
1,954
I'm trying to save a project as an L5X and I need to uncheck the "Encode Source Protected Content" checkbox, but it's grayed out. How do I get...
Replies
1
Views
932
Back
Top Bottom