Followers 0

# [CS1G-H] Float data to BCD.

## 9 posts in this topic

Hello. I need to replace data that was scaled from an analogic card into a BCD values by data now read from a Modbus card as floating points. First, I need to swap 16bits words from the modbus frame but do i need to swap bytes into each 16bits words to get right float values in the CJ1 ? Then, does CX-Programmer for the CS1 provide a single instruction to convert Float values to BCD values ?

##### Share on other sites
If it's a CS1-H or CS1-D use the FIXD[841] instruction.

##### Share on other sites
BITS N BYTES, The help page of this instruction describes it (in french) as a "Double Floating Point to 16-bit instruction", so a 64 bits Floating point (4 words) to a 16bits binary integer (1 word), so, this is not a conversion to BCD integer. Is it a bad translation ?

##### Share on other sites
Sorry to confuse you. I meant to say the FIX[450] instruction.

##### Share on other sites
Hi, The CS1 has a full range of conversion functions to convert between binary, bcd, and floating point numbers. Also there are functions for both single and double precision numbers (1or 2 words for binary/bcd, 2 or 4 words for floating point (32/64 bit precision)). See CS/CJ Instructions Reference Pt1 CS/CJ Instructions Reference Pt2 CS/CJ Instructions Reference Pt3 Sections 3.12, 3.15, 3.16 for details of the conversion functions. To convert from 32 bit floating to 16 Bit BCD use: FIX (450) - floating to 16 bit binary then use BCD (024) - 16 bit binary to BCD Note: floating point number must be in range of 0-9999 Nibroc

##### Share on other sites
Nibroc, That's right, but it is not what i am looking for. I was looking for a _single_ instruction to do that job and another one to swap 1/2 word in the modbus table i get from Modbus. -- www.fr.freebsd.org

Edited by PdL

##### Share on other sites
PdL, [sWAP instruction] This one swaps bytes into words but i need to swap two consecutives words in an array that contains floating point values. Modbus protocol provides floatting point value that are stored into two 16-bits words in the opposite orde. It s too late now, the code has been already written and uses the basic MOV instructions to do that. -- http://david.marec.free.fr

Use XFER.