Convert Decimal value into DINT bit value - RSLogix 5000

JJH

Member
Join Date
Oct 2015
Location
South Carolina
Posts
57
Hey all,

I've reviewed many threads regarding converting one data type to another and I have something I'm working on that I'm stumped on and haven't found an answer for yet.

Without getting into the details, I need to get a DINT bit value from an entered decimal value. A user will enter in a whole number in an entry box and then it needs to get converted to the number of whatever number of bits that the number holds in a DINT. For instance:

# Entered Variable Bit value
------0----------------0
------1----------------1
------2----------------3
------3----------------7
------4---------------15
etc....

I'm looking for a fairly clean way to do this, with perhaps just two or three instruction blocks to handle it, if possible.

I can provide a screenshot of the HMI and the logic (4 rungs) if necessary.

Any suggestions or advice the group can provide would be greatly appreciated!
 
Let me see if I have this straight...
You are looking for inputs 0 thru 32 with results having that many bits set ON. i.e. for the following inputs you get these patterns:

0 0000 0000 0000 0000
1 0000 0000 0000 0001
2 0000 0000 0000 0011
3 0000 0000 0000 0111

If that is the case, I see two methods.

Simple, but fairly long -
Use a series of 32 rungs like this:
EQU EnteredVariable 0 MOV 0 Result
EQU EnteredVariable 1 MOV 1 Result
EQU EnteredVariable 2 MOV 3 Result
EQU EnteredVariable 3 MOV 7 Result

Compact, but calculation intensive -

CPT Result 2**EnteredVariable-1

Or 2 raised to the power of the Entered Variable minus 1 equals the result.
 
Last edited:
Thanks to the respondents!

MELLIS had a good solution with the CPT block. Had to add a -1 for the offest but other than that, it was a great solution!
 
We actually had a somewhat similar thread just yesterday...

Does RS5000 have a decode instruction

Once you've built your DCD AOI, to suit your data type, it is now compacted into just one instruction. It will then handle the 32-bit multiplexing of your data to the destination bit. You simply assign the "TagSource" and "TagDest" parameters for your AOI and sit back.

But the CPT instruction is also a very useful and simple solution, once you have the right arithmetic.

Regards,
George
 
Question what is the plan for the selected bit use it to trigger something else or what
that said I think the simplest way would be to use indirect addressing of the bit
tag.[HMI Tag]
I have used indirect addressing many times usually simple to and understand
 
This project involves a checklist on an HMI that an operator had to go through before it would allow a machine to run. I am working on creating an Add-On Instruction to contain all the logic but needed to make it flexible because this checklist may contain anywhere from 1 to 15 buttons (or more).

Therefore, I needed to have an input for the AOI to know how many buttons were being used in the program so that once that number of buttons were pressed, it would register the process as complete. As each button was pressed, it increased a variable by the relative bit address (1,3,7,15,etc) and I need to convert the number of buttons set to match the bit value of the variable to know when it was done.

Savvy?
 
the way I think would work is to first define the bits needed for each process 0-32 by setting them in a tag
then as each button is pressed set the corresponding bit in the compare tag
when the 2 tags are equal check list is complete this would also give you the advantage of checking for buttons no in the list.
you could store all the predefined setups in an array and just call the correct element of the array for the compare
just a thought there may be other ways
 

Similar Topics

I’m using a 05 PLC which cannot handle real (floating point) numbers. The operator must enter the cut length into the C-Micro panel. (I used a...
Replies
2
Views
3,589
Hi all! looking for help converting an 8 bit word SINT tag into decimal. I have an IFM SBN246 flow sensor wired in my controller (L310ER) and it...
Replies
4
Views
2,174
Hey All, i have been fortunate enough to play around with an Applied Motion Products Servo Drive SV200 with 100 watt/ 24vdc congif. I managed...
Replies
2
Views
1,889
Anyone have a good way to convert a decimal number to fractions. Need to convert decimal inches to fractions before sending to HMI
Replies
16
Views
6,602
Hey all, Here's a tricky decimal to binary conversion project I could use some help with: In my RSLogix 5000 application, I have a "checklist"...
Replies
7
Views
3,074
Back
Top Bottom