Friday, November 16, 2012

Avionics Bending: X-Plane Float to BCD ARINC 429 Label Conversion Example

Two postings ago I showed you how I convert the floating point numbers that I receive from the x-plane SDK into ARINC 429 compatible BNRs. Today I will show you with and example how I convert the numbers into Binary Coded Decimals (BCD).

For this blog posting I will used the Distance-To-Go in Miles indicator that I have on the SFENA HSI that I have been working on for the last two weeks. Let's say we are traveling from the Seattle-Tacoma International Airport to the San Francisco International Airport. The distance with the aircraft still on the ground in Seattle is about 590.5 NM.

A BCD in ARINC 429 can encode 5 digits, and here is the format description for a generic BCD label:

BCD Word Format (No Discretes), ARINC Specification 429 Part1, p. 78
The label used for the Distance-To-Go is ARINC 429 Label 001, and, as you have probably seen in some of my previous postings, the HSI has one decimal. So the distance of 590.5 can be encoded with the 5 BCDs available. As a matter of fact, the SFENA HSI has no way of displaying a distance-to-go further than 999.9 NM. Here is how BCD encoding works:

from: Wikipedia, Binary-coded decimal

So, let's encode the BCD characters for our example of 590.5 NM.

BCD Character 1: 0000   (this is the leading zero)
BCD Character 2: 0101   5
BCD Character 3: 1001   9
BCD Character 4: 0000   0
BCD Character 5: 0101   5

When we place the BCDs into the 32bit ARINC 429 word they look as follows:

P   SM   Data                  SD   Label
0 | 00 | 0000101100100000101 | 00 | 00000001

The total number of bits set in the example above is odd (7) ... so, no parity bit for odd-parity is required. The ARINC 429 word transmitted for distance-to-go label 001 is therefore 0x01641401. What is interesting in an ARINC 429 general format BCD word is that that the BCD on the MSB side of the data payload is only 3 bit wide ... hence the largest number it can encode is 7 ... therefore, for a distance-to-go instrument that can show 4 digits on the left side of the decimal point the further distance to go would be 7999.9 NM (assuming at least one decimal).

Below is a code snipped that shows Float to BCD encoding for the ARINC 429 to UDP conversion module:

1:  /*  
2:   * Convert an Integer to ARINC 429 BCD format with 4 digits output. If a decimal  
3:   * number are to be displayed in BCD encoding, the input number has to be  
4:   * multiplied by 10 to encode the digits to the right of the decimal point. This  
5:   * function performs full 4 bit BCD encoding and  will not work for certain  
6:   * ARINC 429 words such as the BCD encoding for the ATC Transponer code.   
7:   *  
8:   * numberDigtis - number of BCDs to the left of the decimal  
9:   * numberDecimal - number of BCDs to the right of the decimal  
10:   */  
11:  unsigned int float2BCD4 ( float value, int numberDigits, int numberDecimal ) {  
12:    /* BCD Conversion */  
13:    unsigned int bcdField = 0x00;  
14:    int work   = 0;  
15:    char digit   = 0x00;  
16:    int bcdDigits = 0;  
17:    if ( numberDecimal ) {  
18:      work = (int) (value*pow(10,numberDecimal));  
19:    } else {  
20:      work = (int) value;  
21:    }  
22:    do {  
23:      digit = work%10;  
24:      bcdField |= (digit&0x0F)<<(bcdDigits*4);  
25:      work /= 10;  
26:      bcdDigits++;  
27:    } while ( bcdDigits != (numberDigits+numberDecimal) );  
28:    /* ARINC 429 Adjustment */  
29:    bcdField = (bcdField<<2) & 0x1FFFFC;  
30:    return( bcdField );  
31:  } // end integer2BCD4  

1 comment:

  1. I think it’s impossible for me to convert the floating point numbers from the x-plane SDK into ARINC 429, good thing there are manuals found online!

    ReplyDelete