#1: heed @5618's comment: duplicate OTEs is a Bad Thing; you are getting away with it to be sure, but just because there is no one else moored in this bay for the night is no reason to accept that your anchor is dragging. Perhaps the simplest would be to move all of the daytime logic from Program File LAD 2 to a new Program File LAD 4, and simply call (JSR)
EITHER one
OR the other from LAD 2, but never both i.e. call LAD 4 (daytime logic) when NIGHT_TIME is 0, or call LAD 3 (nighttime logic) when NIGHT_TIME is 1
#2: Add comments: describe the
process (e.g. "Determine if mode is daytime or nighttime based on hour-of-day") not the bits and instructions; the reader can look at the code to see what is happening with the PLC internals.
#3: Rung 0004, [XIC T4:0/EN TON T4:3 1.0 15 0], is unnecessary: it starts on the same scan as [RED_1 T4:0] TON timer and is done 5s earlier, so
- [XIC T4:3/DN] on Rung 0010 can be replaced by [GEQ T4:0.ACC 25]
- [XIC T4:3/TT] on Rung 0011 can be replaced by [LES T4:0.ACC 25]
#4: Rungs 0012-0014
- 0012: BST XIC RED_1=O:2/5 LEQ RTC:0.HR 23 NXB XIC NIGHT_TIME_BIT=B3:0 BND BST XIO NIGHT_TIME_STOP=B3:0/1 NXB XIC NIGHT_TIME_START=B3:0/3 BND OTE NIGHT_TIME_BIT=B3:0/0
- 0013: GEQ RTC:0.HR 6 OTE NIGHT_TIME_STOP=B3:0/1
- 0014: EQU RTC:0.HR 23 OTE NIGHT_TIME_START=B3:0/3
First of all, I want to compliment you on a classic use of the Start/Stop pattern in Rung 0012, to ensure a clean transition from daytime to nighttime operations.
But after that, oh dear, where to begin ....
- LEQ RTC:0.HR 23 is always TRUE, so it can be eliminated
- XIO NIGHT_TIME_STOP=B3:0/1 on Rung 0013 is the only use of NIGHT_TIME_STOP, and is same as LES RTC:0.HR 6
- So changing the GEQ on Rung 0013 to LES,
- and ORing it with the EQU on Rung 0014
- to write NIGHT_TIME_START
- eliminates NIGHT_TIME_STOP entirely,
- along with Rung 0013
- and the XIO NIGHT_TIME_STOP=B3:0/1 on Rung 0012
- For that matter, that ORed logic on Rung 0014 could simply be moved to the Stop element of the Start/Stop pattern on Rung 0012, eliminating Rung 0014 as well, and leaving only Rung 0012
- BST XIC RED_1=O:2/5 NXB XIC NIGHT_TIME_BIT=B3:0 BND BST LES RTC:0.HR 6 NXB EQU RTC:0.HR 23 BND OTE NIGHT_TIME_BIT=B3:0/0
- OR, using the LIM instruction, with [Low Limit] > [High Limit] i.e. reversed, to match "nighttime" hours 0-5 and 23:
- BST XIC RED_1=O:2/5 NXB XIC NIGHT_TIME_BIT=B3:0 BND LIM 23 RTC:0.HR 5 OTE NIGHT_TIME_BIT=B3:0/0
#5: Flashing is simpler than two timers; LAD 3 need be but one rung:
- XIC S:4/12 BST OTE RED_1=O2:5 NXB OTE YELLOW_3=O:2/12 BND
And I don't see any reason to put those OTE on separate rungs; the branched output is fine.
#6: If you do insist on doing this with sequential TONs, then at least put them in the order they run (RED, GREEN_2_DELAY, GREEN_1, YELLOW, GREEN_1_DELAY; GREEN_2 is unnecessary and should be removed), so it's easier to read.