ndzied1
Lifetime Supporting Member
I have the need to find the max and min of three values. Using RSLogix 500 on a SLC 5/04 this becomes a little bit of a trick. I worked it out a couple different ways and came up with the code shown below.
After that, is the same finding of Min and Max with an IEC function block. Hands down this is easier!!!
After that, is the same finding of Min and Max with an IEC function block. Hands down this is easier!!!
Ladder Version - Max & Min of Three Registers
+--[GT]----+ +--[GT]----+ +--[MOV]---+
---+ Reg1 +-----+----+ Reg1 +----+ Reg1 +
| Reg2 | | | Reg3 | | Max |
+----------+ | +----------+ +----------+
|
| +--[LE]----+ +--[MOV]---+
+----+ Reg1 +----+ Reg3 +
| | Reg3 | | Max |
| +----------+ +----------+
|
| +--[LT]----+ +--[MOV]---+
+----+ Reg2 +----+ Reg2 +
| | Reg3 | | Min |
| +----------+ +----------+
|
| +--[GE]----+ +--[MOV]---+
+----+ Reg2 +----+ Reg3 +
| Reg3 | | Min |
+----------+ +----------+
+--[LE]----+ +--[GT]----+ +--[MOV]---+
---+ Reg1 +-----+----+ Reg2 +----+ Reg2 +
| Reg2 | | | Reg3 | | Max |
+----------+ | +----------+ +----------+
|
| +--[LE]----+ +--[MOV]---+
+----+ Reg2 +----+ Reg3 +
| | Reg3 | | Max |
| +----------+ +----------+
|
| +--[LT]----+ +--[MOV]---+
+----+ Reg1 +----+ Reg1 +
| | Reg3 | | Min |
| +----------+ +----------+
|
| +--[GE]----+ +--[MOV]---+
+----+ Reg1 +----+ Reg3 +
| Reg3 | | Min |
+----------+ +----------+
=========================================================
Function Block Version Max &
+--MAX----+
Reg1--+ +--Max
| |
Reg2--+ |
| |
Reg3--+ |
+---------+
+--MIN----+
Reg1--+ +--Min
| |
Reg2--+ |
| |
Reg3--+ |
+---------+