Logix 500 - Setting one bit element inside an integer value

TimD

Lifetime Supporting Member
Join Date
Aug 2007
Location
New Hampshire
Posts
235
Hello,

I have a need to set one binary element inside an integer.

Say, I have N7:0 and it contains 16 bits and I want to modify just N7:0/7 to be "1" or "0"

I tried MOV instruction, but Logix complains I must copy the whole word level...

I am hoping not to have to "read" the integer state and then "write", because if the int changes, etc.

Thanks Everyone :)
 
have you looked at the MVM (Masked Move) instruction? ...

TIP: your MASK entry would be 0080h for the operation that you specifically mentioned ...
 
Last edited:
I have a piece of equipment that is controllable by an integer, being split up into 16 bits (vendor compact logix) that I cannot change.

So, for the 16 bit elements, instead of a binary word, they use an integer word.

My HMI can write directly to the integer-bit element, but Logix 500 cannot.

I suppose I can set up a conversion, but like I said, every time I need to do something, I have to read the state first and insert a bit then write, I thought that could get messy...
 
Last edited:
if rising edge 1 add 8 if falling edge subtract 8?

Would have to latch the states of the input so someone can't sit there and hit the button thousand times and keep subtracting
 
if rising edge 1 add 8 if falling edge subtract 8?

Would have to latch the states of the input so someone can't sit there and hit the button thousand times and keep subtracting

Is it 8 or 16?

but to dlwebers point you'll have to manipulate the binary level of the integer at the word level.
 
Which ever number corresponds to the bit you need to change 1 2 4....etc

Instead of latching input you can use a OR with a mask of 1111111101111111 to check the state of desired bit before you try to change it

tempvar = desiredvar OR maskvar
IF tempvar = number and input rising add...and so on
Something to that effect...
 
There are several bitwise methods to skin this cat, at least in C (most of my training was in C) but I think most of the abilities are in ladder logic to
 
The OTL and OTU commands work just fine on the bit level in a word - OTL N7:0/7 - for example

If the specific bit to be Latched or Unlatched is variable then the indirect should work on most units -

OTL N7:0/[N7:1] would set the bit indicated by the value in N7:1. Make sure that the value in N7:1 is 0 - 15 before this rung.

If you want to be sure that ONLY 1 BIT is turned on the preceed the OTL with a CLR N7:0
 
Last edited:
It might be able to but I am not by any means a PLC expert, but I can code decently in a couple languages, I am still working on transitioning from writing code to building ladders
 
expanding on the idea from Post #2 ... the MVM instruction is intended to do precisely the type of operation that you've described ... naturally there are other ways - but most professional programmers would tend to use the proper tool to get the job done ...

going further ...

the MVM instruction will let you control more than one bit at a time - by setting the Source and the Mask entries appropriately ...

granted - this might indeed make the logic somewhat complicated for Cletus to troubleshoot on night shift - but this is probably the most professional way to accomplish the task ...

party on ...

.

MVM.PNG
 
Last edited:
Instructions like that are the thing I need to learn in ladder. But yeah that is exactly what I was doing just somebody took similar code to what I was talking about and already put it into a nice little box.

Ron I would agree, however, there is a difference in professional and proficient in a discipline. I would consider myself a professional programmer, just not proficient in ladder logic and all of its built in functionality. As with any transition I will become more and more familiar with what capabilities and features exist. I am not used to too many predefined functions like there is in ladder. I am used to creating my own, as I am sure once upon a time these functions did not exist in abundance like they do now for even the PLC world.
 
Instructions like that are the thing I need to learn in ladder.

which is precisely why I mentioned it in Post #2 - and then demonstrated its use in Post #13 ...

I'm sorry if it seemed that my "professional" comment was meant to offend you in any way ... I was merely looking for a comment to say: "The MVM instruction would generally be preferred" ...

we're ALL still learning – which is what makes this such an interesting trade ...

again, I apologize if my comment seemed derogatory ... it wasn't meant that way ...
 
Last edited:

Similar Topics

Alright, here is what I know. In the lab we are building a new OSIsoft PI system and need to inject some real life data into the machines for...
Replies
9
Views
11,649
I wrote a program for a SLC5/05, downloaded it and it won't set the bit when I'm online with the program. Is there a limit to the addresses that...
Replies
2
Views
3,927
I have been doing logic programming and troubleshooting for about 25 years. I started working for a new company as PLC Application Engineer and I...
Replies
5
Views
122
Hello, Haven't been on in a while. I need to generate a bit level pdf of the I/O for RSLogix 500. I can generate a report but it just shows the...
Replies
1
Views
115
I would like to copy register N61:131 thru N61:147 into ST252:0 I keep failing What happens is I copy into ST252:0,1, 2 etc. What am i missing...
Replies
18
Views
489
Back
Top Bottom