Wednesday, November 14, 2012

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

Still busy working on the SFENA HSI integration with x-plane. I thought it could perhaps be interesting to you to see how I convert a label from the x-plane floating point output to the ARINC 429 format. For the example I will use a BNR formatted ARINC 429 word.

Taking Magnetic Heading Information from X-Plane to ARINC 429 Label 320

The magnetic heading information computed by Austin's x-plane software can be exported via the XSquawkBox SDK as a floating point number. On Apple OSX, a floating point number is a 4 byte (32 bit) number using standard floating point based real number approximation. So, strictly speaking, the SDK exported magnetic heading information from x-plane has a lot more resolution than the SFENA HSI requires to rotate the magnetic heading card to the right spot.

The SDK will output an approximate heading of 060º as a floating point number of about 60.000001 which is what I will continue to use for the remainder of this posting.  Lets look at the ARINC 429 word next.

The ARINC 429 Label 320 for Magnetic Heading has the following format:

BNR Word Format (No Discretes), ARINC Specification 429 Part1, p. 78
The be more exact, the Magnetic heading is expressed in units of DEG/180 and typically has either 15 or 10 significant bits in the data field. Hence, giving it a resolution of either 2^15 or 2^10 or 32768 and 1024 respectively. The SFENA HSI uses a resolution of what I think are 18 bit ... which is quite high.

The value of 60º as computed by x-plane now needs to be converted into the basic ARINC 429 information. I do so by applying a compensation factor in order to keep the computational load down on the machine. Here are the steps:

1. Apply the correction factor for the bit depth and angular encoding. That correction factor is:

DEGFACTOR = 0.000686644

         HDGXPLANE
HDGBNR = ----------------
        DEGFACTOR

The value for HDGBNR after this step is 0x20000.

2. Adding the SSM and the Parity

The BNR requires adding the SSM of '11' in bit locations 31 and 30. As well as computing the parity across the 31 remaining bits of the ARINC 429 word. So here it is in bits:

Empty ARINC Label 320
P   SM   Data                 SD   Label
0 | 00 | 100000000000000000 | 00 | 11010000
add 0x20000
0 | 00 | 100001000100000000 | 00 | 11010000
set the SM to 11
0 | 11 | 100000000000000000 | 00 | 11010000
compute the parity (there are 6 bits set so it requires a bit to make odd parity)
1 | 11 | 100000000000000000 | 00 | 11010000

The data portion of the ARINC 429 word now has the value of 0xE80000. Tomorrow I will walk through the conversion of a floating point number from x-plane to an ARINC 429 compatible BCD. Below are some code snippets:
1:  /*  
2:   * Convert a floating point Degree number to a BNR without format  
3:   * correction.  
4:   */  
5:  unsigned int floatDEG2BNR ( float value ) {  
6:    unsigned int work = 0;  
7:    value = ( value / DEGFACTOR);  
8:    work = 0x600000 | ( (int) value )<<2;  
9:    return( work );  
10:  } // End floatDEG2BNR  
Not the most elegant parity computation below, however, the label and data section of the unassembled word are in different structure pieces:
1:  /*  
2:   * Compute odd partity and set MSB of the ARINC429 word as the odd parity bit  
3:   */  
4:  void parityOdd( unsigned int *value, unsigned int *label ) {  
5:    unsigned int x;  
6:    unsigned int parity = 0;  
7:    for (x=0;x<8;x++)  
8:      if ( *label & 0x1<<x )  
9:        parity++;  
10:    for (x=0;x<23;x++) {  
11:      if ( *value & 0x1<<x )  
12:        parity++;  
13:    }  
14:    if ( ((parity & 0x1) == 0) )  
15:      *value |= 0x800000;  
16:  } // End parityOdd  

No comments:

Post a Comment