Storing Row Count

jthornton

Member
Join Date
Jul 2002
Location
Poplar Bluff, MO
Posts
295
I have a 4 position switch that is connected to inputs 0, 1, 2 of an AB SLC500 L511 processer. The following Table (thanks Terry for showing me how) describes the hookup.


Input States at each Position
--------+-------+-------+--------
|Inputs > 0 | 1 | 2 |
--------+-------+-------+--------
| Pos 1 | Off | Off | Off |
--------+-------+-------+-------+
| Pos 2 | On | Off | Off |
--------+-------+-------+--------
| Pos 3 | Off | On | Off |
--------+-------+-------+-------+
| Pos 4 | Off | Off | On |
--------+-------+-------+--------

Desired Results are to place into
N7:0 the following values according
to the selector positon
--------+--------
| Pos 1 | 3 |
--------+-------+
| Pos 2 | 4 |
--------+-------+
| Pos 3 | 5 |
--------+-------+
| Pos 4 | 6 |
--------+-------+



Is there a different solution than the following
to reduce the amount of user words used or shorten the code any?

ladder3.jpg


Thanks Guys for all the help
John
 
I have a pallet stretch wrapper I modified and it needed a switch to set the number of wraps at top and bottom. I did just what you did basically BUT the funny thing is we got another one (same brand/newer model) with a micrologix in it and the program was almost identical to mine. I am sure there are other ways but that seems the simplest to me.
 
I think your logic is the most straightforward. There are usually multiple ways to do anything, but what you've done should be pretty obvious to anybody else who might need to understand the program.

Garryt1's suggestion could work if fourth position of the selector switch could be changed to have inputs 0 and 1 both on. Then you would need to mask off inputs 3 - 15, and add the value of 3. As you've presented it, the selector switch positions correspond to the decimal or BCD values 0, 1, 2, 4, for which you want the corresponding values 3, 4, 5, 6.
 
Because you have the bits in the 0, 1, & 2 pos, and assuming the bits are mutually exclusive (that the position switch mechanincally does not allow 2 bits to be on at the same time (You seem concerned that it might since you check against it in your code), you can simplify your code a bit.

Looking at the first 3 bits only, they produce the following values:
<table cellpadding = 2, border=2 cellspacing=2 ><tr><td> I:0/2 </td><td> I:0/1 </td><td> I:0/0 </td><td> Value </td><td> Desired Vaule </td></tr><tr><td> 0 </td><td> 0 </td><td> 0 </td><td> 0 </td><td> 3</td></tr><tr><td> 0 </td><td> 0 </td><td> 1 </td><td> 1 </td><td> 4</td></tr><tr><td> 0 </td><td> 1 </td><td> 0 </td><td> 2 </td><td> 5</td></tr><tr><td> 1 </td><td> 0 </td><td> 0 </td><td> 4 </td><td> 6</td></tr></table>
(The other way to make a table - raw HTML code (not hard if you use Word and SaveAS an HTML doc)
Except for the last entry, the Value is 3 lessthan the Desired Value.

So, extract the bits:

MVM I:0.0 0003h N7:0

Add 3

ADD N7:0 3 N7:0

And error check the last entry

GRT N7:0 6 MOV 6 N7:0

I don't think it's any better than your code, just shorter.
 
Last edited:
Hi Allen, that is the code I was looking for. Shorter is better for me on this project. Thanks a million. I did have to change the 0003h to 0007h to get it to work.

ladder4.jpg


Thanks for the tip on making a table as well.

You guys are great!
John

Allen Nelson said:
Because you have the bits in the 0, 1, & 2 pos, and assuming the bits are mutually exclusive (that the position switch mechanincally does not allow 2 bits to be on at the same time (You seem concerned that it might since you check against it in your code), you can simplify your code a bit.

Looking at the first 3 bits only, they produce the following values:
<table cellpadding = 2, border=2 cellspacing=2 ><tr><td> I:0/2 </td><td> I:0/1 </td><td> I:0/0 </td><td> Value </td><td> Desired Vaule </td></tr><tr><td> 0 </td><td> 0 </td><td> 0 </td><td> 0 </td><td> 3</td></tr><tr><td> 0 </td><td> 0 </td><td> 1 </td><td> 1 </td><td> 4</td></tr><tr><td> 0 </td><td> 1 </td><td> 0 </td><td> 2 </td><td> 5</td></tr><tr><td> 1 </td><td> 0 </td><td> 0 </td><td> 4 </td><td> 6</td></tr></table>
(The other way to make a table - raw HTML code (not hard if you use Word and SaveAS an HTML doc)
Except for the last entry, the Value is 3 lessthan the Desired Value.

So, extract the bits:

MVM I:0.0 0003h N7:0

Add 3

ADD N7:0 3 N7:0

And error check the last entry

GRT N7:0 6 MOV 6 N7:0

I don't think it's any better than your code, just shorter.
 

Similar Topics

HI all, I have a backup from a Series 7000 Cognex camera. I am trying to restore and see the vision tools used in the job. Can I restore those...
Replies
0
Views
55
Hello, I have an int variable that updates the value every second. I want to store the 100 values in an array. Array should keep storing the...
Replies
7
Views
949
Hi I have a vision camera that I’m getting the string data P908765 from the vision on an advance trigger .which im using a S -move. Then I put...
Replies
1
Views
364
Hello You guys helped me with a similar issue some time back on storing totalized values to different tags each month. I have a similar issue...
Replies
19
Views
1,383
Is there any easy way to store a password for an email address that is changeable on the HMI that is not easily deciphered. aka, don't write it to...
Replies
0
Views
374
Back
Top Bottom