Sign in to follow this  
Followers 0
bjcanning

decimal to binary conversion

14 posts in this topic

I am trying to send a decimal number to my customer. I am going to use 10 outputs in binary representation. In turn my customer is going to use 10 inputs to get a binary value. I need to know how to convert a decimal number to a binary structure so I know which outputs to turn on. Any help greatly appriciated.

Share this post


Link to post
Share on other sites
What model of AB PLC are you using?

Share this post


Link to post
Share on other sites
Use the windows calculator or better use the tool I uploaded here. It will let you enter a decimal value and show the binary equivalent and vice versa. Very useful tool, I use it on a daily basis! If you click the blue option box you can set signed or unsigned decimal output (re-enter a value and click = to reflect the change), that is the only thing you have to agree with your customer.

Share this post


Link to post
Share on other sites
I think you're looking for TOD (Convert 16-bit integer to BCD). HTH! Susan

Share this post


Link to post
Share on other sites
I don't think I was clear enough in my description. I have a panelview plus connected to the micro. The operator will enter in a value on it. This decimal value is what I want to send to my customer. Please note that the decimal value will change with every part. I want my logic to take care of all this otherwise it isn't feasible. Thanks.

Share this post


Link to post
Share on other sites
Let's make sure I got the scenario right... The operator will enter a decimal # on the Panelview plus. That # will get stored in an N7 (or whatever) register on the Micro1100. You need to change the decimal # to binary to be transferred to a set of 10 outputs. Those outputs are hardwired to the customer's inputs on another controller. If that's right, you can use the TOD instruction to change the decimal # to a binary # for example... If your source is N7:3 and it contains 9760 (decimal) and your destination is N10:0, the TOD instruction will change it to the following N10:0 4-digit BCD 1001 0111 0110 0000 9 7 6 0 Then you mask off the part of N10:0 that you want to send to the outputs and move it.

Share this post


Link to post
Share on other sites
Exactly what I am wanting to do. I just was unfamilar with the TOD instruction. Thanks so much for your time and help.

Share this post


Link to post
Share on other sites
Now I'm totally confused. Why not just MOV N7:XX O:0.0 - Why the conversion? Edit - I noticed the part about 10 outputs. That limits the number to 0-1023. Still the output instruction can be MVM N7:XX 3FF O:0.0 which makes it so that the the upper 6 bits of the output word are not affected. And why the mention of the TOD command? The original poster never said anything about BCD. Edited by b_carlton

Share this post


Link to post
Share on other sites
If I can just move my N7 decimal value to the Output word then that is much simpler. Yes I only need a decimal value of up to 1000 that is why I choose 10 outputs. Thanks.

Share this post


Link to post
Share on other sites
You can still use the tool I mentioned or Windows calculator to test the binary matrix against the entered decimal number.

Share this post


Link to post
Share on other sites
I don't know if you can use this example? I have in the pass used a multiplexing code to do this. You need 4 outputs to the customer and 3 inputs from the customer When the customer sends 001 I send the first digit in binary When the customer sends 010 I send the second digit When the customer sends 011 I send the third digit And so on .......

Share this post


Link to post
Share on other sites
That's an interesting thought! Lots less I/O required for this method. I'll take it into consideration that's for sure.

Share this post


Link to post
Share on other sites
Sorry, you're right. I was thinking about an old Siemens controller that I had to pass info via outputs back in the mid 90's. My customer's supervisory display used BCD, so passing the info already in BCD was the easiest. If bjcanning did it the way I said, he would have been limited to 399 instead of the 1023 he wanted. Mea culpa...

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