Integer Conversions

jridout

Member
Join Date
Mar 2005
Posts
1
Hi,
Does anyone out there know how to convert a double word (32 bit) integer into a single word ( 16 bit ) and vice versa, on a SLC 5/03 processor. I have a Hardy Scale interface card which deals with double word info and I only understand BCD in the single word level.

John
 
John,

If the value in the doubleword is something like 40,000... how are you gonna convert that to a 16-bit Integer? I'm pretty sure that you are gonna lose something in the translation.

It appears that your basic problem is "I only understand BCD in the single word level."

John... this is like saying you know how to Add and Subtract, but you don't know how to Multiply and Divide.

Sure, you can perform Multiplication by Addition... over and over and over...

Sure you can perform Division by Subtraction... over and over and over...

But c'mon... isn't that like banging your head with a hammer?

You would be doing yourself a tremendous favor by recognizing that PLC Math is primarily based in 16-bit and 32-bit Binary... not BCD. BCD is the exception... not the norm... at least, not as far as the internals of the PLC are concerned. The PLC has to bend over backwards to calculate with, and provide information in, BCD.

BCD might be easier for you to understand, but then, you are depriving yourself of a much wider range of possibilities.

As far as converting an Integer to a DoubleWord, that is easy in most PLCs...
...after insuring that the original value of the DoubleWord is "zero", simply write the Integer Word to a LSW (Least Significant Word) of the DoubleWord and then refer to the address of the DoubleWord.

This does open the question of Big-Endian vs. Little-Endian... again.

However, in some PLCs, where the zoning laws are strict, you have to find a particular instruction that will allow you to do this. Since you are talking AB and since I haven't done AB for years, you'll have to wait for someone else to provide that instruction.

John... seriously, you can and should certainly keep the BCD ways in mind, there are uses for that mode of thinking. But by all means, learn how to deal with normal 16 & 32-bit Binary! 16 & 32-bit Binary is the basis of PLC computing power... not BCD.

If nothing else, I hope I piqued your curiosity.
 
Getting is all done!

I have a Hardy Scale interface card which deals with double word info and I only understand BCD in the single word level.

John, like Terry said, working in BCD is unwieldy at best and not recommended as a medium. However, you have the Hardy Scale thing that is somehow giving you BCD info. You did not say how you were getting it into the SLC5/03. Is it coming in in serial form over a link? Is it broadside loaded, parallel? Also, how many digits are there in your BCD values? Do you have 999, or 9999 or 99999 BCD. This is important to know if you are going to effectively convert it to anything. But you can convert up to 5 digit BCD in the 5/03 by using the FRD instruction. If you do 4 digit or below, it is a simple thing. Doing 5 digit, requires some manipulation of the math registers. If you do not have an instruction set for the SLC processors, you can download a copy from the AB manuals online site. Look for 1747-rm001c-en-p and it is in PDF format so it is a big file and will take some time if you are using dial-up like I do for internet.

At any rate, you will need to read in section 5 on data handling pages 5-5,6,7,8. There is a good explanation on how the FRD instruction works and will help you deal with what you have coming from your scale input.

Does anyone out there know how to convert a double word (32 bit) integer into a single word ( 16 bit ) and vice versa, on a SLC 5/03 processor.

This is a separate issue and really does not have anything to do with BCD, as I understand it. In the AB processors, there is single precision, 16bit, and there is double precision, 32 bit, but that has nothing to do with BCD, per se. The single or double precision only applies to math functions such as multiply and divide. The 16bit words of the data table are only capable of holding an integer value up to +\-32,767. If you go to floating point in some processors then you effectively have all the number handling capability you could want but you still must follow the rules that the processor designers laid down for using these features.

 
On the 5/03 you have a 32 bit math register available. It is at S:13, S14. You can use the 32 bit math instruction DDV. If you are using a series C processor (or you can flash upgrade the processor to series C) then you can set the overflow bit at S:2/14 and get the truncated lower sixteen bits in your destination register for any math function.
 

Similar Topics

Hi. I'm using a Modbus ProSoft where I basically map data to a big INT array. Example, where GX_I_63HPU is a REAL, MNETC.DATA.WriteData[200] an...
Replies
21
Views
428
Good morning all, I'm integerating a device with a Rockwell PLC with V34 Studio 5000. The device reports error codes using a single integer to...
Replies
19
Views
1,283
Ex If I Read from Integer file N7:0 N7:0 is an 8 point input card , input 0 and 2 are on , rest off When I look at : N7:0 -7 6 5 4 3 2 1 0 I...
Replies
5
Views
742
The analog array has 16 individual bits and each bit is an alarm. SCADA is having issues getting the BIT bool value. However they can get the...
Replies
9
Views
1,019
I set up a Mitisubishi test system on the bench. Q03UDSPU Q173DCPU MR-J3-40B HF-KP43 HMI is a LS XP50 TTA/KP43 I am trying to use a signed...
Replies
1
Views
394
Back
Top Bottom