3

In reference to one interface control document, I found difficulty in understanding this concept. There is one parameter having LSB of 0.0625 and MSB of 2048 that should be transmitted from one piece of equipment to another. It's range is 0 to 2400.

This should be transmitted using only one word. That is 2 bytes.

Now the problem is: I understood this as that parameter is being measured by one measurement system with a resolution of 0.0625. Since it is decimal number how can we transmit this continuous range parameter using 2 bytes which are purely integers (unsigned range for 2 bytes is 0 to 65535)?

That parameter is speed, which is being measured by an INS-GPS avionics system and is being transmitted to the CPU using only 2 bytes.

How should I understand this?

How can we represent a continuous decimal parameter as a discrete integer parameter?

Kyle A
  • 164
  • 7
Ajay shifu
  • 59
  • 1
  • 4
  • 2
    What? Can you try to rewrite this so it's understandable? – whatsisname Jan 26 '18 at 17:40
  • What are LSB and MSB in your case? Are you sure your word is 2 bytes? What devices? Provide more context please. – Martin Maat Jan 26 '18 at 19:54
  • 2
    Downvoters, please note there’s plenty of context here if you’ve seen Fixed Point Numbers in embeddes dev before. – RubberDuck Jan 26 '18 at 23:05
  • Im really sorry I'll clarify now. – Ajay shifu Jan 27 '18 at 03:35
  • Ins-gps is one unit which measures ground speed with a resolution of 0.0625. and its range is 0 to 2400. it is being transmitted by ins-gps to CPU using 1553 bus. In this transmission, one word(2 bytes) is used for ground speed parameter. Also it is unsigned numeric. So the unsigned integer range we can represent is 0 to 65535. Since my ground speed is 0 to 2400 continuous range (means 0.4 also , 12.456 ). Literally infinite numbers in between 0 to 2400. So my doubt is how do we represent (0 to 2400) continuous range data in (0 to 65535) integer range. – Ajay shifu Jan 27 '18 at 03:44
  • 3
    Note: being personally unfamiliar with this domain is *not* a good reason to downvote or vote to close this question as "unclear what you're asking." – Karl Bielefeldt Jan 27 '18 at 17:20
  • 1
    @KarlBielefeldt: The problem is not the domain, it's the way the OP is interpreting the domain. – Robert Harvey Jan 27 '18 at 17:35
  • 1
    @Ãjay: Technically, your range isn't continuous; it's discontinuous with a resolution of 0.0625. – Robert Harvey Jan 27 '18 at 17:41

2 Answers2

11

TL;DR:

The following function will do the conversion from physical value to 16-bit code:

short valueToCode(double value) {
    return round(16.0 * value);
}

Long explanation

An unsigned 16-bit value has 16 bits (of course), the leftmost one called the MSB (most significant bit), and the rightmost is the LSB (least significant bit).

Read as normal integers, a 1-bit in the LSB position accounts for a value 1, and a 1-bit in MSB position gives 32768.

In your case, the 16-bit number is meant to represent numbers with fractional part, one LSB standing for 0.0625 (= 1/16), and the MSB for 2048 (= 32768/16). That's consistent, meaning that you always get the fractional number by dividing the 16-bit code by 16. Or, if you want to find the code that most closely matches some desired fractional value, multiply that by 16, and take the closest integer.

Some examples (giving the value you want to achieve, the code that most closely gives that value, and the effective value):

Desired       Code (dec + bin)          Resulting Value
    0.0625      1 = 0000000000000001       0.0625  (the LSB case)
    0.1         2 = 0000000000000010       0.125
    1.0        16 = 0000000000010000       1.0
   20.5       328 = 0000000101001000      20.5
 2048.0     32768 = 1000000000000000    2048.0    (the MSB case)
Ralf Kleberhoff
  • 5,891
  • 15
  • 19
9

That’s poorly written documentation. They’re assuming that you know they’re using a Fixed Point number format.

LSB 0.0625 and MSB 2048

This would have been more easily understood if it was written as powers of 2.

0.0625 == 2-4

2048 == 211

So, you end up with a fixed point number in the following format.

MSB —> LSB

| 211 | 210 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | . | 2-1 | 2-2 | 2-3 | 2-4 |

Or

000000000000.0000

For detailed information see this Introduction to Fixed Point Number Format

RubberDuck
  • 8,911
  • 5
  • 35
  • 44