adccommunitymod (AutomationDirect) asked a question.

Floating point convertor for DL05

Created Date: August 04,2008

Created By: vmcanard

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

I have modbus power meter and DL05. Power meter has floating point modbus values. I need to get values on DL05 in BCD format. Is anybody has the example how to convert foating point in normal BCD format?


  • adccommunitymod (AutomationDirect)

    Created Date: August 04,2008

    Created by: bcarlton

    As the DL05 does not support REAL values you may have a problem. Is it too late to switch to a DL06? Can the power meter be modified to provide the values in another format?

  • adccommunitymod (AutomationDirect)

    Created Date: August 04,2008

    Created by: vmcanard

    It is too late to change processor. The cabinet is ready and the value format of power meter is not possible to change. I made the calculations for some variables, but process is very complex. Does anybody have the discripton of algorithm how convert REAL to BCD in DL05?

  • adccommunitymod (AutomationDirect)

    Created Date: August 04,2008

    Created by: AZRoger

    vmcanard,

    The link below shows how IEEE floating point assigns meaning to it's bits. (Modbus uses this standard format.)

    http://www.psc.edu/general/software/packages/ieee/ieee.html

    It's probably word-swapped in the PLC. It's not trivial to decode, but can be done with a few accumulator operations. However, from what I 've read on other posts, if you ever actually get a negative number from your meter (co-generation, etc.) it could be tough sledding. You also need to know whether 32 bit or 64 bit numbers are arriving as modbus doesn't provide descriptors of what's actually in the data.

    If you can force to meter to produce results with a fixed scaling factor, then things are much easier. Can this be done?

    Roger

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: August 04,2008

    Created by: franji1

    IEEE floating point is optimized for a large range, but limited significant digits, i.e. you can have really big numbers,

    1,234,567,890,000,000,000,000

    or really small numbers

    0.000 000 000 000 123 456 789

    So what range do you expect for the REAL values? 0..100? can they be negative? How precise do you have to be, i.e. is 3.01 much different than 3.02?

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: August 05,2008

    Created by: vmcanard

    I need to read currents, power of electric network. The range from 0 to 30kWt. The accuracy I need is one sign after point. The power meter has 32 bit value.

  • adccommunitymod (AutomationDirect)

    Created Date: August 05,2008

    Created by: franji1

    That's good. If at all possible, if the meter can be configured in "tenths of kW " in BCD, that would be PERFECT. However, a lot of field devices come preconfigured and you cannot change the scaling.

    If they had that, then if the actual reading on the device was 29.8 kW, then you would have the value 298 BCD in your V memory register, which works natively.

    If they do not have the capability of configuring the scaling of the value, then you'll have to do it yourself using the algorithm AZRoger pointed out, which is quite intense for a little PLC. Maybe someone out there has done such a thing in ladder logic (convert IEEE 754 to a binary or BCD value w/1 implied decimal point)?!?

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: August 05,2008

    Created by: franji1

    Or do you need one decimal point beyond a Watt, i.e. 29876.5? I assumed your units were kW.

    What is the model of the power meter, possibly there are other Modbus registers that contain the needed value(s) in other numeric formats???

  • adccommunitymod (AutomationDirect)

    Created Date: August 05,2008

    Created by: AZRoger

    I'm working on the PLC logic to do this conversion. The IEEE floating point numbers have a 24 bit number (the fraction) and an 8 bit number as the exponent. The exponent determines where the binary-point goes in the value.

    The following list of values illustrates an interesting binary-point effect:

    Binary 10.1 = decimal 2.5 = 2-1/2

    Binary 10.01 = decimal 2.25 = 2-1/4

    Binary 10.001 = decimal 2.125 = 2-1/8

    Binary 10.0001 = decimal 2.0625 = 2-1/16

    As you can see, you can't get exact tenths out of the numbers to the right of the binary-point.

    So for the conversion to BCD with 1 digit after the decimal-point we need to keep at least 4 binary digits after the binary-point (1/16ths of a watt). There would then be rounding to get to 10ths.

    Is accuracy to 1/16th of a watt from the meter rounded to 10ths for display OK?

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: August 06,2008

    Created by: AZRoger

    OK. Here's a solution. I think it could be tightened up a bit by remembering what has already been pushed into the stack.

    This takes a 32 bit IEEE floating point number in V10100 and V10101 and produces a 7.1 digit BCD number in V10116 and V10117.

    The rounding isn't perfect but it's close. Binary and Decimal don't really get along that well. http://forum1.automationdirect.com/board/smile.gif

    EDIT: This morning I tested this from 0 to 131,071.9 Watts. The binary calculations overflow above that.

    // Rung 1779

    // Address 6327

    #BEGIN COMMENT

    "Floating Point to BCD conversion Sample "

    "Takes 32 bit IEEE float and make decimal "

    "value with one implied decimal point. NN.N "

    #END

    STRN B10101.15 //Only do Positive Values

    LDD "Float " //Get the whole IEEE value

    ANDD K7fffff //Mask off sign and exponent

    ORD K800000 //Add in the implied 1 bit

    OUTD "Fraction " //save as 32 bit binary

    LD "FloatTop " //get the Top 16 bits

    ANDD K7f80 //Mask or sign and fraction bits

    SHFR K7 //Slide exponent to low orders bits

    OUT "ExponentBin " //Save as 16 bit number

    SUBB K78 //Subtract 120 (which multiplies by 128)

    OUT "BinaryPointPos " //Save binary point position

    INV //negate

    ADDB K18 //And adjust for amount to shift fraction

    OUT "NumBits2Shift " //save number for later shift instruction

    LDD "Fraction " //get the fraction from before

    SHFR "NumBits2Shift " //shift out the low order bits we don't need

    OUTD "BinaryValX128 " //Now we have, in binary, the value x 128

    SHFR K7 //divide by 128

    BCD //make the integerpart of the number BCD

    SHFL K8 //Multiply by 100 (can't use MUL instruction)

    OUTD "BCDValX100 " //save this number

    LD K7f //get a mask to pick up only fractional bits

    AND "BinaryValX128 " //And in to get the non-integer part

    MULB Kc800 //This is 6553600/128 which produces 0 to 99

    //in the TOP HALF of the accumulator

    SHFR K16 //move the answer to the bottom half

    BCD //and make it BCD

    OUT "DecHundredths " //save the hundredths

    ADDD K5 //add 5 to do rounding to tenths

    ADDD "BCDValX100 " //add in the 100X integer from before

    SHFR K4 //drop one digit to make it tenths

    OUTD "BCDValX10 " //save the BCD with one implied decimal

    #BEGIN ELEMENT_DOC

    "V10100 ", "Float ", "DWORD IEEE Float ", "Low 16 Bits Fraction "

    "V10101 ", "FloatTop ", "Sign 8 Bits Exp ", "7 Bits Fraction "

    "V10102 ", "BCDValX100 ", "DWORD 8 Digits ", " "

    "V10103 ", "BCDValX100Top ", " ", " "

    "V10104 ", "BinaryValX128 ", "DWORD 32 bits ", " "

    "V10105 ", "BinaryValX128Top ", " ", " "

    "V10106 ", "BinaryPointPos ", "Exponent - 120 ", "(Automatic * 128) "

    "V10107 ", "ExponentBin ", "WORD 16 Bit Bin ", "Exponent "

    "V10110 ", "Fraction ", "DWORD 32 Bit Bin ", "Bottom 16 "

    "V10111 ", "FractionTop ", " ", "Top 7 "

    "V10112 ", "NumBits2Shift ", " ", " "

    "V10114 ", "DecHundredths ", "DWORD 8 Digits ", " "

    "V10115 ", "DecHundTop ", " ", " "

    "V10116 ", "BCDValX10 ", "DWORD 8 Digits ", " "

    "V10117 ", "BCDValX10Top ", " ", " "

    #END

    Roger

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: August 06,2008

    Created by: vmcanard

    Thank you for help. I will try to implement it in my project.

10 of 13