RSlogix 5000, odd or even?

wendaiyu

Member
Join Date
Jun 2014
Location
toronto
Posts
87
Hi, guys, how’s going?

In RSlogix 5000, if the integer in tag “number” (DINT) is odd, then the output “ODD.1” is ON. How can we program it?

Thanks a lot.
 
Actually the first bit of any integer is odd/even. So number.0 = 0 (even), number.0 = 1 (odd). In other words, XIC number.0. If it's false your DINT is even, of it's true, your DINT is odd.
 
My answer was going to be a CMP instruction with the expression
Code:
My_Tag MOD 2 = 0
...which will evaluate true if the number is even, and false if it is odd

But I guess an XIC is simpler :site:
 
I would do it dmroder's way.
If were doing assembly language programming I would rotate the word right through carry and jump or not jump if carry.
This way I don't need to load the constant 1.

Depending on the assembly language instruction set, you may not need to load a 1 at all if the constant is embedded in the instruction word.
 
You can address to the bit level in DINT tags in RS/Studio5000.

Bit 0 is the least significant bit, and has a binary "weighting" of 1, which is Odd. All the binary weightings of all the other bits are Even (except the sign bit, of course)

All "odd" numbers will have bit 0 turned on, so it is simply a case of inspecting bit 0 of your DINT tag, if it's on, then DINT tag has an "ODD" value, if it is off, the DINT tag holds an "EVEN" value, or more simply "Not ODD".

And you do not even need to write any code to test for this... If you make a new tag "My_Value_Is_Odd", and ALIAS it to "MyValue.0", where MyValue is your DINT tag.

"My_Value_Is_Odd" will inherit the BOOL data-type of the base tag, i.e. bit 0 of "MyValue"

XIC MyValue_Is_Odd : True if MyValue is Odd

XIO MyValue_Is_Odd : False if MyValue is Even (Not Odd)

Use your own tag-names as appropriate...

Using an alias with a descriptive moniker like ".....is_odd" may be preferable to just addressing bit 0 in MyValue directly, which of course is always a contender.
 

Similar Topics

I am completely stuck on building a ladder program that requires a start button to be pressed 3 times to turn on motor 1. Then motor 2 starts...
Replies
20
Views
520
First off, I'm a hobbyist-level programmer, and this program isn't controlling anything anything that could even remotely be considered "life...
Replies
18
Views
502
Hello all, I have a question in regards to RSlogix 5000. I am having issues with the program force closing when I try to make online edits. We...
Replies
0
Views
115
Greetings ... someone sent me a request for some student handsouts that I developed ... turns out that I had this hosted on my business website...
Replies
0
Views
127
Back
Top Bottom