Sign in to follow this  
Followers 0
Guest trn_psycho

Inputs

15 posts in this topic

What's the best way to code (Micrologix and/or SLC) four inputs to be read as a decimal number? AKA: I have inputs 8, 9, 10, and 11 wired into a plug. If the inputs see voltage on 10 and 11 then the program needs to see this as a value of 4. Make sense?

Share this post


Link to post
Share on other sites
Just copy the inputs to the corresponding bits of the destination word.

Share this post


Link to post
Share on other sites
So you'd have to use four copy statements? AKA COP (source: I:0/8, dest: N7:1/0), COP (source: I:0/9, dest: N7:1/1), etc....

Share this post


Link to post
Share on other sites
if I understand your problem, then this should be an example of your first rung ... you'll need three more similar to this ... if this isn't what you need, then you should post again with more details ... best regards, Ron

Share this post


Link to post
Share on other sites
Just wondering what coding has 1100 = 4? Or was your example just mistaken? or just follow Ron's lead and ignore this comment. Edited by b_carlton

Share this post


Link to post
Share on other sites
Ron, using that wouldn't I have to build a ladder stucture for every possible number in the binary ####. (16 of them).

Share this post


Link to post
Share on other sites
Oops... Bad math, that would be 3 not four... Edited by trn_psycho

Share this post


Link to post
Share on other sites
By copying I did not mean the COP instruction. Activate the destination coils by the input contacts, that's it. XIC X:0/8 OTE N:0/0 XIC X:0/9 OTE N:0/1 XIC X:0/10 OTE N:0/2 XIX X:0/11 OTE N:0/3 But some combination of the inputs will produce values >9. Edited by Sergei Troizky

Share this post


Link to post
Share on other sites
I like Sergei's solution best, only takes four lines of ladder, and the destination word will always have the decimal value. Here's an example, you can use as many compares as you need:

Share this post


Link to post
Share on other sites
He said that if 10 and 11 were on that would be equal to 4 (later changed to 3). It would seem that they would need to be copied in inverse order. A general note - when a set of inputs are to represent a number it is easiest if the least significant bit is wired to the lowest numbered input (in this case I:0/8). But, if the wiring is now in stone, it can be taken care of in the PLC ladder.

Share this post


Link to post
Share on other sites
oops! ... I hate it when I do that ... (got the wrong bits on and the wrong bits off) ... this is what I meant to post earlier ... it satisfies the only specific requirements which were given in the original post ... I’m not sure ... just how many possible numbers does your application require? ... please give us all of the details ... we can handle anything - once we know exactly what we’re shooting for ... best regards, Ron Edited by Ron Beaufort

Share this post


Link to post
Share on other sites
How about a Bitwise AND with a mask value of 3840 decimal (0F00h) and a SWAP of the high and low bytes to get the bits to the LSB? What this code will do is read the status of bits 8 - 11 and show any combination of these 4 bits as a 0 - 15 decimal value in integer N7:0. Edited by mjrx

Share this post


Link to post
Share on other sites
Thanks everyone... What Sergei Troizky said was actually what I was looking for. Sorry if my post was not informative enough Ron. I meant no disrespect. I actually had coded it like you suggested before and was looking for a way to reduce the number of ladders in the program. Dropping from 16 to 4 was a nice change. The whole point of the ? was this: I wanted a better way (AKA: shorter) to identify a program number that is wired into a plug. Four inputs allowed me to get an integer value up to 15 (16 including 0) using a swappable plug. (The value that is connected to this plug determines what program to run...) I'm pretty new to programming in PLC, but have a LOT of C++, C#, VB, Perl experience. So I knew that there must be a more efficient way to capture this data. But Hey! Thanks to y'all, I'll make this transition more quickly! PS: b_carlton, Thanks for advise about lower numbered inputs... That's actually how I set it up. For some reason, when I was asking the ?, I just used the numbers I had written on the right (AKA: Left 8, 9, 10, 11 Right). I guess I just transposed strait down... Edited by trn_psycho

Share this post


Link to post
Share on other sites
mjrx, That one gets me... Can you explain (in stupid terms) what the 3840 mask value is?

Share this post


Link to post
Share on other sites
He is doing a bitwise AND the hex value of 3840 is 0F00, so, you get 0110 1110 1110 1110 (input word) 0000 1111 0000 0000 (3840 in binary) 0000 1110 0000 0000 (result of AND) 0000 0000 0000 1110 (after swapping high and low bytes) Edited by Ken Moore

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0