Unintended behavior for triggers?

Hi,
I was chasing a bug in my function block and it comes down to one BOOL flag (trigEnable) being TRUE all the time when setMotorEnable=TRUE.
It should only be one short peak and then go back to FALSE (just like trigDisable is doing).
Here is the catch: If I add the last line (R_TRIG for undervoltage detection), this mentioned ‘bug’ occurs. Why is that?
F_TRIG1(CLK := setMotorEnable, Q => trigDisable);
R_TRIG1(CLK := setMotorEnable, Q => trigEnable);
R_TRIG1(CLK:= (ErrorStatus=15), Q=>trigErrUndervoltage);


Here 2 pictures from the analyzer. In Picture 1 it can be seen that trigEnable is always the same value as setMotorEnable which is wrong. In pic 2 the behavior is correct, with the 3rd trigger-statement removed.
Why is that?

The problem is that you’re using the same Function Block instance (R_TRIG1) in both lines 2 and 3.
Using the language of Object Oriented Programming, you can think of a Function Block (e.g. R_TRIG) like a Class, and a Function Block instance (e.g R_TRIG1) like an Object. In the case of R_TRIG, each instance has internal data that remembers the state of the input on the previous execution of the instance, which allows it to detect the transition of the input from false to true.
If you use the same R_TRIG instance in multiple locations, the state of the internal data in that instance will be messed up by the multiple calls and the results won’t be what you want.
The solution in this case is to use a new instance of the R_TRIG FB in line 3 - e.g. R_TRIG2 - which will have its own internal data value(s) independent of any other R_TRIG instances.
The general rule is to call all FB instances precisely once in every task execution cycle.
Note that this is different for Functions, which don’t maintain any internal state.