apostolakisl
Senior Member
The non-blocking delay function isn’t well documented in the user manual. You can place a set of brackets [] after variables, ttl inputs, an ttl outpus in most PLC lines. How this worked exactly I endeavored to figure out. So I did a bunch of experiments and found the following:
First off, Whenever a variable, ttl input, or ttl output changes value, CAI logs the old value, new value, and the time of change.
There are two tests that occur on any line of code evaluating for a “true” or “false” response when a delay operator is used (like TSTGT, TSTEQ, etc).
1) The statement is evaluated as it would have normally (had no delay operator been present).
2) The value(s) with delays are checked to see if they have changed during the previous x milliseconds where x is what you put in brackets. If they have changed, the statement will be false regardless of what the previous value was.
For example: TSTGT VAR1[500] 1
1) Check if var1 is greater than 1, just like normal.
2) Check to see the last time VAR1 changed value. If VAR1 changed within the previous 500ms, it will be false, even if both the old and new value were greater than 1. For example, VAR1 might have been at the value 100, then 200ms prior to the above line of code executing it change to 200, even though both are 100 and 200 are greater than 1, it still runs false.
Both 1 and 2 must be true for the statement to be true.
Another example: TSTEQ VAR1[300] VAR2[200]
This will 1) check if var1 and var2 are currently equal, if yes, it checks to see if var1 has been unchanged for 300ms and var2 for 200ms. If no changes occurred, and var1 and var2 are equal, then it is true, otherwise it is false.
When a line of code sets a value and that value has a delay operator, the value will be set for the period of time specified, then it will revert to the old value.
For example, if VAR1 was currently set to 10 and the following line of code were encountered.
For Example: ADD 4 5 VAR1[2000]
The function will add 4 and 5 and place the answer (9) into VAR1. After 2000ms VAR1 will revert back to the original value of 10.
If you have a mathematical function (like add, sub, mul, etc), and one or more of the values have delay operators, the entire line of code is aborted if the values were not constant throughout the delay time period.
For example: ADD VAR1[500] 5 VAR2
The function will add the value of VAR1 plus 5 and place the answer in VAR2 only if VAR1 has remained unchanged for the previous 500ms. If VAR1 has not been stable during the previous 500ms, the function is not performed and VAR2 is left unchanged. When the function is aborted, the zero bit is not updated. So a BZ, or similar command in the next line will branch according to the zero bit value as it was prior to the aborted “ADD” line above.
First off, Whenever a variable, ttl input, or ttl output changes value, CAI logs the old value, new value, and the time of change.
There are two tests that occur on any line of code evaluating for a “true” or “false” response when a delay operator is used (like TSTGT, TSTEQ, etc).
1) The statement is evaluated as it would have normally (had no delay operator been present).
2) The value(s) with delays are checked to see if they have changed during the previous x milliseconds where x is what you put in brackets. If they have changed, the statement will be false regardless of what the previous value was.
For example: TSTGT VAR1[500] 1
1) Check if var1 is greater than 1, just like normal.
2) Check to see the last time VAR1 changed value. If VAR1 changed within the previous 500ms, it will be false, even if both the old and new value were greater than 1. For example, VAR1 might have been at the value 100, then 200ms prior to the above line of code executing it change to 200, even though both are 100 and 200 are greater than 1, it still runs false.
Both 1 and 2 must be true for the statement to be true.
Another example: TSTEQ VAR1[300] VAR2[200]
This will 1) check if var1 and var2 are currently equal, if yes, it checks to see if var1 has been unchanged for 300ms and var2 for 200ms. If no changes occurred, and var1 and var2 are equal, then it is true, otherwise it is false.
When a line of code sets a value and that value has a delay operator, the value will be set for the period of time specified, then it will revert to the old value.
For example, if VAR1 was currently set to 10 and the following line of code were encountered.
For Example: ADD 4 5 VAR1[2000]
The function will add 4 and 5 and place the answer (9) into VAR1. After 2000ms VAR1 will revert back to the original value of 10.
If you have a mathematical function (like add, sub, mul, etc), and one or more of the values have delay operators, the entire line of code is aborted if the values were not constant throughout the delay time period.
For example: ADD VAR1[500] 5 VAR2
The function will add the value of VAR1 plus 5 and place the answer in VAR2 only if VAR1 has remained unchanged for the previous 500ms. If VAR1 has not been stable during the previous 500ms, the function is not performed and VAR2 is left unchanged. When the function is aborted, the zero bit is not updated. So a BZ, or similar command in the next line will branch according to the zero bit value as it was prior to the aborted “ADD” line above.