Still thinking about it, and don't understand what the OP question is, if any, but welcome to the forum (as a poster), and well done!
With the caveat that I do not know the process, here are some initial thoughts:
- I think the HSL instructions are basically correct, although
- I would use negative values for the low preset, to ensure [LAD 4] is never called on an LPR trigger, even if [LAD 4] does nothing.
- I would think about using different trigger logic for the HSLs; read on.
- Rungs 0002 and 0003
- There is no need to load the HSC presets every scan
- Also note that the current logic here could change the presets while a fill is active
- Put an [XIO* <SIXTEL IS FILLING>] on Rung 002
- Put an [XIO <HALF BBL IS FILLING>] on Rung 003
- The <HMI START ...> bits are only read, and not re-assigned to 0, in the PLC program,
- so I am assuming the HMI does the clearing,
- but it's generally a bad idea to trust the HMI to perform process-critical work
- An alternate approach would be to only assign a 1 to those bits via the HMI, and then, when those 1s are detected in the PLC, unlatch them to 0 in the PLC on these rungs
- This is called "Set-and-Forget," and eliminates problems caused by the well-known issue where an HMI momentary control assigns a 1 to a bit in the PLC, and then fails to assign a followup 0.
- Set-and-Forget enforces the momentary behavior in the PLC
- Also, consider whether the two <HMI START ...> bits could both be 1 at the same time; that would be bad.
- E.g. combine them into a single bit
- Or do the Set-and-Forget mentioned above
- With logic like the above, the reset of the HSC could be done on the output side Rungs 0002 and 0003
- Although there should be logic to ensure that another press of an <HMI START ...> cannot re-start a fill if one is already in progress.
- I.e. so only <HMI STOP> or <HIGH PRESET REACHED> can re-arm the logic on Rungs 0002 and 0003.
- I don't see where <FILL HOSE TIL CLEAR PB> is assigned a 1
- So with that, plus the PB (PushButton?), I assume that is another bit driven by the HMI
- Use Set-and-Forget again
- For style/clarity, I would shift current Rung 0001 to be after current Rungs 0002 and 0003, to keep the Latches/Unlatches of the <... IS FILLING> bits rungs logic together.
- The <First Pass> bit should protect against any problems here, but only using OTEs for bits is sometimes a better approach
- The <FILLING HOSE> bit can only be turned off by <HMI STOP> in that start-stop circuit on current Rung 0001. That will re-activate the output rung (current Rung 0004) and the re-open <KEG FILL VALVE>, even after an <HSC PRESET REACHED> event resets everything else; consider the following sequence of events at the end of a fill:
- <HIGH PRESET REACHED> becomes 1
- Rung 0004 goes false on [XIO <HIGH PRESET REACHED>]
- <KEG FILL VALVE> becomes 0, presumably closing the valve
- Rung 0000 resets the HSC [RAC HSC0 0]
- The HSC reset will ensure <HIGH PRESET REACHED> is 0 no later than the next scan
- I think Rung 0000's RAC, activated when <HIGH PRESET REACHED> becomes 1, will not clear <HIGH PRESET REACHED> for the rest of the scan when the RAC executes, but it will definitely be 0 on the the next scan.
- <FILLING HOSE> is still 1
- Assuming there has been no <HMI STOP> to break current Rung 0001
- Rung 0004 goes true again on [XIC <FILLING HOSE>] => [XIO <HIGH PRESET REACHED>]
- So <KEG FILL VALVE> becomes 1 again, presumably opening the valve immediately after the preset was reached, indicating the keg was already full.
* XIO is --]/[--
Again, I do not know the process, but from the comments on current Rung 0001, I assume the <FILLING HOSE> bit relates to an activity distinct from filling a keg, i.e. seeing clear beer at the end of the filling hose (instead of foam?). So the general programming principle "separation of concerns" suggests to me that <FILLING HOSE> should be decoupled as much as possible from filling a keg. One way to do that would be to wrap the [XIC <FILLING HOSE>] branch around
all the XIC/XIO instructions above it on Rung 0004, and add an [XIO <FILLING HOSE>] instruction to those upper instructions.
- The bypass of [XIO <HMI STOP>] on Rung 0004 is justified because the [XIO <HMI STOP>] on current Rung 0001 would still deactivate Rung 0004, when Rung 0004 had been activated by <FILLING HOSE>.
- The bypass of [XIO <HIGH PRESET REACHED>] is justified because looking for clear beer coming out of the hose is a separate activity from filling a keg.
Finally, I noticed there is nothing in [LAD 4], which is executed when the <HIGH PRESET REACHED>, and I think it is executed as an interrupt i.e. it can happen at any time, either between program scans or even during a program scan. For the current program, an unlatch of the valve and filling signal bits could be put here, along with the other reset actions currently in Rung 0000. Such a [LAD 4] could also be called on [XIC <First Pass>] or [XIC <HMI STOP>]. That said, it would also require some very careful logic in the main [LAD 2] to latch the valve outputs to start a fill or clear the hose, because an HSC-triggered interrupt that executes [LAD 4] could potentially interrupt between the main program logic that triggers the latch and the latch itself. That may not be a problem here, but it should be considered.
Note that [LAD 4] is also executed then the low preset is reached, so if it was used for something, those low presets should be set to something other than 1 e.g. a negative value that will never occur.