allen bradley

pdcsah5

Member
Join Date
Jan 2003
Location
ohio
Posts
9
I wanting to convert decimal to hex. Inside a slc 500 program. The bcd format will not work. I am looking for other ideas.

Thanks Scott
 
Is this a trick question?

er... The value in an integer (N) register is already in hex, no conversion needed. (OK, it's actually in binary, so you take blocks of 4 bits and you have hex).

If you're trying to change a float (F) register to hex, just MOV it to an N. If it's bigger than 32767, DDIV by 1, and the 32-bit integer is in S:14 - S:13.

If you are trying to extract individual Hex elements, use the MVM instruction. You can enter the mask in hex, just type an 'h' after the number (Ex: 00F0h).
 
Last edited:
aren't you "scott" on another forum?

Yo, pdcsah5,

You'll get more (and better) responses if you'll help us out a little.

How about a range of values?

A few specific examples along the lines of "703710 decimal needs to convert to ABCDE hex" would be very helpful.

What type of processor are you using? Is it really an SLC-500 "brick" as your subject line indicates? Or is it an SLC-5/01; SLC-5/02; SLC-5/03; SLC-5/04 or SLC-5/05? You know - different processors have different capabilities and instructions available.

So far, I'm thinking along the lines of a recursive loop (JMP back to an LBL until the conversion task is done) but it sure would be nice to know exactly what we're shooting for here.

Finally, have you already got the SLC-to-rexroth interface working? In other words, can you manually type a valid hex number into an SLC memory location and properly move the valve? It would be a good idea to get this piece working before you tackle the conversion - so that you KNOW that you've got the format of the conversion's output specified correctly.

Best regards,

Ron

Edit PS to Allen: Oops! Didn't see you coming! Got to hone my speed typing skills.
 
Last edited:
I AM USING A SLC 5/04. I AM TRING TO INPUT A DISTANCE IN mm FROM A PANELVIEW 1000 AND CONVERT THE DISTANCE IN TO A HEX NUMBER.

I WOULD ENTER 100mm IN DECIMAL AND I WANT TO CONVERT IT TO HEX 64h.

THE REXROTH CONTROLLER ONLY TAKES HEX. I AM USING INTERGER FILES TO TALK WITH THE PANELVIEW AND THE REXROTH CARD.

I HOPE THIS IS ENOUGH INFO. I APPERICATE THE HELP

THANKS

SCORR
 
we're getting closer

can you give us a min/max value range? for example:

the smallest number i'll ever enter is:
the largest number i'll ever enter is:

then i think we'll have what we need - but how about that manual entry to the valve? does it work? yes? no?

Edit PS - are you sure that an integer is where you want to store your conversion output? i've never worked with a rexroth - but i'm guessing that it needs something like "7B" hex for a move of "123" mm - if so, then we might have to talk ASCII to this thing - am I even close here?
 
Last edited:
THE MANUAL OPERATION WORKS. I CAN IN THE SLC500 PROGRAM ENTER A HEX NUMBER AND IT SEND IT OUT TO THE CARD.


THE MAX = 190
MIN=0 30 IS WHEN THE VALVE WILL MOVE.

THANKS
 
pdcsah5-

Unless, as Ron states, you are woring with an ASCII transfer to the card, the number you get from the HMI should be able to go right out to the card. As you state, 100d is 64h. The bit patterns are identical.

You said the manual functions worked. How/what did you enter in the plc as hex to get the card to do what you wanted?

Keith
 
i think keith's on to it

scott, i think that keith (and allen even earlier) seem to be on the right track - are you changing the RSLogix500 radix to Hex/BCD before you just type in a number like "64"? - and the valve moves to the 100 mm position? if so, then you're probably home free - if what i just said is correct, then put the radix in decimal mode - and type in 100 (as though it just came in "raw" from the operator's entry) - if i finally understand what you're doing, then you'll probably get the same result as entering "64" in the Hex/BCD mode -

i'm offline for the rest of this evening but i'll bet these guys will help you get everything solved before i get back tomorrow.

PS Edit: If this works, it's because the rexroth is "automatically" interpreting the integer's bit pattern as a hex value - even though the operator is entering it (the SAME) bit pattern in decimal. If it doesn't work - then you'll just need to tell us (as Keith requested) just HOW and WHERE and WHAT values you're entering into the SLC to make this valve work correctly.
 
Last edited:
Binary to Hex Conversion

I need to convert a binary number to its hex equivalent, storing the result in a string register.

Thank you.
 
Number to Hex to String

It's too bad that you have to do this. If I understand you correctly, you have a number (1234) and you want to wind up with a string which is the Hex equivalent of this number ("04D2")

Here's a brute-force approach

Step 1. Separate the integer into 4 elements.
If your PLC is an AB (you don't say), you would use 4 MVM instructions (Move with Mask) using masks of 000Fh, 00F0h, 0F00h, and F000h to 4 different registers. Divide the resulting registers by 1, 16, 255, and 4096 respectively. Now each resulting register consists of a number 0 through 15.

1234 (= 0000 0100 1101 0010) =>=> 0, 4, 13, 2


Step 2. Convert the integer to it's ASCII equivalent.
To each register, add 48 to each of the numbers. If the resulting number is > 57, add an additional 7. (e.g., 10 (="A" hex) + 48 = 58 + 7 = 65 (= "A" in ASCII).
0 + 48 = 48
4 + 48 = 52
13+ 48 = 61 + 7 = 68
2 + 48 = 50


Step 3. Combine the ASCII 8-bit bytes into 16-bit words.
For each letter pair, multiply one of the numbers by 256 and add it to the remaining number. The final registers should be consecutive.

48 * 256 + 52 = 12340 (="04" ASCII)
68 * 256 + 50 = 17458 (="D2" ASCII)

If you are only working with ASCII registers, you can stop here.

Step 4. Put these in a string file.
If this is an AB processor, there are several ways to convert ASCII to string.
a. The instruction MOV N7:1 ST10:0.DATA[1]
b. If you know the lenght of the string, put it in the preceeding word, then use the COP instruction. (Assume the data is in N7:1 and N7:2) MOV 4 N7:0. COP #N7:0 ST10:0 1
 
Allen:

I really liked your explaination. It was excellent.
I have a question:
Using your answer as a guide I created some logic and ran it through RSEmulate. I will add the zip file here in case you are interested in looking at the code.
When I divide by 1000 hex or 4096 decimal the value sometimes comes out negative and fouls up the conversion. I had to add an AND instruction on rung 3 to take care of this. Is there a better way of shifting bits which will avoid this problem.



Kim
 

Similar Topics

Hi, I have a ControlLogix system with 1756-IF16 analogue inputs. I can't scale the inputs at the card as there is a requirement to facilitate...
Replies
11
Views
260
Dear community, I am trying to find a tool for Allen-Bradley PLCs similar to SiVArch for Siemens PLCs to automatically generate faceplates and...
Replies
0
Views
81
Hi everyone, new to forum. Since very long time i having issue with 1734-AENT module, after some period of time its keep stuck in error (simmilar...
Replies
14
Views
429
Hello, I am new here. I am trying to find good places to sell some surplus items that I have that isnt through ebay. Does anyone have any sources...
Replies
5
Views
354
Hi all, installed on chassis A17 an A/I from Allen-Bradley , problem is what ever I do , all channels are sticked on value 39.9 and cannot change...
Replies
1
Views
141
Back
Top Bottom