Introduction
Our INFORM language does not have an instruction that can directly determine if the value of a variable is odd or even. PLC programmers using RS Logix can do this and may be looking for a way to do this with INFORM instructions. Below we will introduce an example scenario and the steps needed to accomplish this. NOTE: this will not determine the value of the variable, only if it is an even or an odd number. The purpose of this document is just to show you how to find out if a variable value is even or odd, there are of course other ways to track this programmatically.
Scenario
We are incrementing Variable I000 with every part that we place on our pallet, and we have an odd shape at one end of the part. We would like to add an offset for every other part to allow us to stack tighter. We would like to track this by checking if I000 is an odd or an even number.
Solution
To do this, we will need to select an unused output group (a byte) to write to. This example will use Output Group #6. Now you can use the SET command write the value of the integer to the output group.
Now that the variable is written to the output group, all we need to do is monitor the first bit of that group, in our case Output#41. If it is on, the value of the variable must be an odd number. If it is off, the value must be an even number. We can monitor this with an if then statement and continue our programming.
This works, because the first bit of an odd number is always 1. See below.
Comments
0 comments
Please sign in to leave a comment.