AKD Basic using Single Precision Floating Point Decimal over Modbus
This explains the necessary conversion of floating-point decimal values sent over Modbus, such as for an AKD-T Basic program variable defined as a "float" and mapped to Modbus as "$MBMapfloat".
The drive sends the data over Modbus in the format of a single precision floating point decimal. The master must convert the binary value to the floating point decimal value. If the master doesn't do this automatically, you must convert it manually. This depends on how the variable is defined and used in the master program. If the program uses the value as a true floating point decimal, then it is ready to use. But if the program is using it as a decimal (not a floating point), then it must be converted.
This also applies to sending data from the master to the drive. If the AKD-T Basic program variable is a float, the format must be floating point decimal.
You can't just read the value as signed int or unsigned int. You can’t even read it as hex and do a simple integer hex to decimal conversion. It must be read as a floating point decimal (32bit float) or converted manually.
Conversion (binary to floating point decimal)
Single precision floating point decimal: Data size = 32bit
Floating point decimal value = (-1)^[Sign Bit] x 2^(Exponent - 127) x [1 + Mantissa/2^23]
- Sign Bit: MSB in high register (bit 31)
- Exponent: bits 30 - 23
- Mantissa: bits 22 - 0
Example
- High register value = 0xC42A = 1100 0100 0010 1010
- Low register value = 0x4F9E = 0100 1111 1001 1110
Breakdown:
- Sign Bit = 1
- Exponent (8 bits) = 10001000 = 136 dec
- Mantissa (23 bits) = 0101010 01001111 10011110 = 2772894 dec
Floating point decimal value = (-1)^[Sign Bit] x 2^(Exponent - 127) x [1 + Mantissa/2^23]
Floating point decimal value = (-1)^1 x 2^(136-127) x (1 + 2772894/2^23)
Floating point decimal value = -1 x 2^9 x 1.3305547
Floating point decimal value = -681.244
Conversion (floating point decimal to binary)
Value = -681.244
Mantissa = (|Value|/2^x - 1) x 2^23, where 2^x is the closest power of 2 less than the value.
Mantissa = (|-681.244|/2^9 - 1) x 2^23
Mantissa = (681.244/512 - 1) x 2^23
Mantissa = (1.3305547 - 1) x 2^23
Mantissa = 0.3305547 x 2^23
Mantissa = 2772894 = 0101010 01001111 10011110 (this is bits 22-0)
Exponent = 127 + x, where 2^x is the closest power of 2 less than the value.
Exponent = 127 + 9 = 136 = 10001000 (this is bits 30-23)
Sign Bit = 1 because it's a negative number.
Binary value = 1 10001000 01010100100111110011110 |_|________|________________________|
Send this value over Modbus to your float variable in the AKD Basic program.
AKD “Float” Parameters
This does not apply to AKD parameters that have 3 decimal places, such as VL.FB, that are documented as "float" parameters. In this case, the AKD firmware converts the value to an integer prior to sending the data over Modbus. The master receives the data as an integer. Then you only need to divide by 1000 to get the proper value.