/***************************************************************************/ /***************************************************************************/ /***************************************************************************/ /******* *******/ /******* D H C - 8 S e r i e s 4 0 0 *******/ /******* *******/ /******* F U E L Q U A N T I T Y G A G I N G S Y S T E M *******/ /******* *******/ /***************************************************************************/ /***************************************************************************/ /***************************************************************************/ /* */ /* Program Name : DHC-8 Fuel Quantity Gaging System (FQGS) */ /* Source File Name : comp.c */ /* CPC : Computations */ /* Engineer : Katherine Monroe */ /* Criticality Level : */ /* Contents : fqc_compute_ssms */ /* fqc_compute_mass */ /* fqc_compute_imbalance */ /* */ /* */ /* Description : This CPC performs the computations to obtain the */ /* fuel quantity. */ /* */ /* */ /* Contents of this document are propriety information, property of: */ /* PARKER HANNIFIN CORPORATION */ /* GULL ELECTRONIC SYSTEMS DIVISION */ /* SMITHTOWN, NEW YORK 11787 */ /* Any attempt to copy or use the contents of this document in any manner */ /* whatsoever without express written consent of the owner is prohibited. */ /***************************************************************************/ /***************************************************************************/ /***************************************************************************/ #pragma EJECT /***************************************************************************/ /* Revision History */ /***************************************************************************/ /* */ /* Date Rev Engineer Description */ /* ------ --- -------- ------------------------------------------------ */ /* */ /* */ /***************************************************************************/ #pragma EJECT #pragma DEBUG #pragma LARGE #pragma NOAM #pragma OBJECTEXTEND //#pragma SRC #define EXTRN extern // declare all global variables external #define MAIN_FILE 0 #include "c:\c51\inc\reg51.h" #include "asicaddr.h" #include "defines.h" #include "typedefs.h" #include "globals.h" #include "prototyp.h" #include "fai.h" /* Module level literals */ #define MAX_FUEL_QTY 7000 #define MAX_ERROR_FUEL_QTY 7200 #define TEN_PERCENT_MAX_FUEL_QTY 700 #define MAX_TOTAL_FUEL_LBS 14000 #define MAX_TOTAL_FUEL_KGS 6350 /* Module level variables */ xdata uchar comp_error_found[2]; #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : fqc_compute_ssms */ /* Description : This unit determines the ssm bits for the ARINC message. */ /* */ /***************************************************************************/ void fqc_compute_ssms(void) { /******************/ /* Local Literals */ /******************/ xdata uint probe_group_statuses; /* contains failure status of the */ /* probe */ xdata uchar i; /* loop counter variable */ /***************************************/ /* During startup transmit SSM as NCD */ /* while fuel quantity is zero. */ /***************************************/ if ((RESET == g_acq_startup_complete_flag) && (0x0000 == g_own_fuel_qty)) { g_fuel_qty[OWN_QTY_ENTRY].ssm = SSM_NO_COMPUTED_DATA; g_fuel_qty[OTHERS_QTY_ENTRY].ssm = SSM_NO_COMPUTED_DATA; g_own_total_fuel_qty_ssm = SSM_NO_COMPUTED_DATA; g_own_system_status_ssm = SSM_NO_COMPUTED_DATA; g_own_tu_status_ssm = SSM_NO_COMPUTED_DATA; g_others_tu_status_ssm = SSM_NO_COMPUTED_DATA; g_tank_failure[MY_SIDE] = RESET; //variable used to display dashes on indicator } else { MAX_QTY_TEST: /***************************************/ /* Default the SSM to normal operation */ /***************************************/ g_fuel_qty[OWN_QTY_ENTRY].ssm = SSM_NORMAL_OPERATION; g_own_total_fuel_qty_ssm = SSM_NORMAL_OPERATION; g_tank_failure[MY_SIDE] = RESET; /*******************************************************/ /* If the computed fuel quantity is above the maximum */ /* allowed limit, set the SSM to indicate a failure */ /* warning and set the fuel quantity to zero otherwise */ /* transmit computed fuel quantity via ARINC. */ /*******************************************************/ if (g_own_fuel_qty > MAX_FUEL_QTY) { if (g_own_fuel_qty > MAX_ERROR_FUEL_QTY) { g_own_fuel_qty = 0; g_fuel_qty[OWN_QTY_ENTRY].ssm = SSM_FAILURE_WARNING; g_fuel_qty[OWN_QTY_ENTRY].lbs = 0; /* ARINC */ g_fuel_qty[OWN_QTY_ENTRY].kgs = 0; /* ARINC */ g_own_total_fuel_qty_lbs = 0; g_own_total_fuel_qty_kgs = 0; g_own_total_fuel_qty_ssm = SSM_NO_COMPUTED_DATA; } /* end if */ else { g_fuel_qty[OWN_QTY_ENTRY].lbs = ((g_own_fuel_qty + 5)/ 10) * 10; // ARINC g_fuel_qty[OWN_QTY_ENTRY].kgs = (uint) ((float) g_own_fuel_qty / 2.205); g_fuel_qty[OWN_QTY_ENTRY].kgs = ((g_fuel_qty[OWN_QTY_ENTRY].kgs + 5)/10) * 10; } } /*******************************************************/ /* If any of the acquired data indicated a continuous */ /* failure condition, the fuel quantity has been set to*/ /* zero and the SSM must indicate failure warning. */ /*******************************************************/ if ((comp_error_found[0] == TRUE) || (comp_error_found[1] == TRUE)) { g_fuel_qty[OWN_QTY_ENTRY].ssm = SSM_FAILURE_WARNING; g_own_total_fuel_qty_ssm = SSM_NO_COMPUTED_DATA; } /*******************************************************/ /* If probe or low level sensor failures are detected, */ /* then set the SSM bits to indicate a failure warning */ /* and set the fuel quantity to zero. */ /*******************************************************/ probe_group_statuses = 0; for (i=PROBE_1_FAULT_GROUP; i<= PROBE_8_9_FAULT_GROUP; i++) probe_group_statuses |= fai_status_reporter (i); probe_group_statuses |= fai_status_reporter (HI_Z_FAULT_GROUP); if (probe_group_statuses & HARD_FAILURE) { /* check for any failure */ g_fuel_qty[OWN_QTY_ENTRY].ssm = SSM_FAILURE_WARNING; g_own_fuel_qty = 0; g_own_total_fuel_qty_lbs = 0; g_own_total_fuel_qty_kgs = 0; g_own_total_fuel_qty_ssm = SSM_NO_COMPUTED_DATA; g_tank_failure[MY_SIDE] = SET; /* display dashes for my side on indicator */ /*******************************************************/ /* Added so that repeater data and ARINC data will go */ /* to zero. */ /*******************************************************/ g_pdm_fuel_qty[OWN_QTY_ENTRY] = 0; /* repeater */ g_pdm_fuel_qty[TOTAL_QTY_ENTRY] = g_pdm_fuel_qty[OTHERS_QTY_ENTRY]; g_fuel_qty[OWN_QTY_ENTRY].lbs = 0; /* ARINC */ g_fuel_qty[OWN_QTY_ENTRY].kgs = 0; /* ARINC */ } /* end if */ } } /* end fqc_compute_ssms */ #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : fqc_compute_mass */ /* Description : This unit computes mass. */ /* */ /***************************************************************************/ void fqc_compute_mass(void) { #define FILTER_FACTOR 4 #define KGS_MODE 1 /* Calculated below for each receiver */ //#define WX 8042 // lbs // (908.67gal * 6.71lbs/gal * 1024us) // ---------------------------------- // (274.93pf * 1.117 * 8 * .316MEG) // // 908.67gal = Total volume of the wing (tank) // 274.93pf = Ceff of all the tank units combined // 1 + 1.117 = Fuel density // 1024 us = Excitation time period // /* Calculated below for each receiver */ //#define W_OFF 910 // (908.67gal * 6.71lbs/gal * 45.85pf) // ------------------------------------ // (274.93pf * 1.117) // 45.85pf = Cdry (empty cap value) // empty lbs offset (4/6 changed from 52) // empty lbs offset (6/5 changed from 601) // empty lbs offset (6/6 changed from 523) #define VT 8939.2 // (.34/5 * 8192)*16 // .34 = Forward voltage drop in the diode of the tank unit #define TEN_SECONDS 5 // PR 037 added the following 3 lines. #define CHANGE_SLOPE 0.940 // 0.940 in kgs and lbs #define CHANGE_OFFSET 191.84 // 87.0 in kgs (87.0*2.205 = 191.835) #define CHANGE_LEVEL 3197 // 1450 in kgs (1450*2.205 = 3197.25) #define LBS_TEST_DATA 2500 #define KGS_TEST_DATA 1130 code uint WX[2] = {8126,8126}; //See formula above //changed from 8038 on 9/29/97 according to R.Orbell calculations, memo RO-M-0997-1515 code uint W_OFF[2] = {479,431}; //See formula above static xdata uchar local_fail_cnt; static xdata uchar test_count; static xdata uchar count[2]; xdata uchar rec_channel; xdata float numerator1; xdata float denominator1; xdata float denominator2; xdata uint local_fuel_qty; xdata int computed_fuel_qty[2]; for (rec_channel = 0; rec_channel < NUMBER_OF_RECEIVERS; rec_channel++) { /*******************************************************/ /* If any of the acquired data indicated a continuous */ /* failure condition, the fuel quantity must be set to */ /* zero and the SSM must indicate failure warning. */ /*******************************************************/ if ((INVALID_LONG == g_probe_lls[rec_channel].filtered_vref_vgnd) || (INVALID_LONG == g_probe_lls[rec_channel].filtered_probe_offset) || (INVALID_LONG == g_probe_lls[rec_channel].filtered_slope_hi_low) || (INVALID_LONG == g_probe_lls[rec_channel].filtered_gain_offset) || (G_MAX_ACQ_ERROR == g_acq_sampling_error_cnt)) { if (g_acq_startup_complete_flag == TRUE) { count[rec_channel]++; if (count[rec_channel] >= 2) { /*********************************************/ /* Only set flag after acquisition startup */ /* process has completed, otherwise SSM will */ /* be set to Failure Warning incorrectly. */ /* Wait for 2 counts before setting flag. */ /*********************************************/ comp_error_found[rec_channel] = TRUE; count[rec_channel]=0; } else computed_fuel_qty[rec_channel] = 0; } else computed_fuel_qty[rec_channel] = 0; } else { comp_error_found[rec_channel] = FALSE; /***********************************************************************/ /* w= 7937/4 * filtered_vp_voff * filtered_vref_vgnd) */ /* ---------------------------------------------- */ /* filtered_vth_vtl * filtered_vref_vgnd - vt * filtered_gain_offset */ /***********************************************************************/ numerator1 = ((float)(WX[rec_channel]/FILTER_FACTOR) * (float)(g_probe_lls[rec_channel].filtered_probe_offset)); numerator1 *= ((float)(g_probe_lls[rec_channel].filtered_vref_vgnd)); denominator1 =((float)(g_probe_lls[rec_channel].filtered_slope_hi_low) * (float)(g_probe_lls[rec_channel].filtered_vref_vgnd) ); denominator2 =(VT * (float)(g_probe_lls[rec_channel].filtered_gain_offset)); denominator1 -= denominator2; numerator1 = numerator1 / denominator1; if (VALID_FLOAT(numerator1)) { computed_fuel_qty[rec_channel] = ((int)(numerator1)) - W_OFF[rec_channel]; FUEL_QTY: /***********************************************/ /* PR037 added code to reduce the slope of */ /* the computed fuel qty line above 1450 kgs. */ /***********************************************/ /*if (computed_fuel_qty[rec_channel] > CHANGE_LEVEL) { // 1450 kgs /* computed_fuel_qty[rec_channel] = (int)((float)computed_fuel_qty[rec_channel]*CHANGE_SLOPE + CHANGE_OFFSET); } */ if (computed_fuel_qty[rec_channel] < 0) // test for negative qty computed_fuel_qty[rec_channel] = 0; HIGH_FUEL_QTY1: local_fail_cnt = 0; } else { fai_pass_fail_logger(FLOATING_PT_MATH_TEST_ID, FAIL); if (local_fail_cnt < G_MAX_ACQ_ERROR ) local_fail_cnt++; else computed_fuel_qty[rec_channel] = 0; } } } if ((comp_error_found[0] == TRUE) || (comp_error_found[1] == TRUE)) g_own_fuel_qty = 0; else g_own_fuel_qty = computed_fuel_qty[0] + computed_fuel_qty[1]; HIGH_FUEL_QTY: /*********************************************/ /* If computed fuel quantity is out of range */ /* then set local quantity to maximum other- */ /* wise set the quantity to the computed fuel*/ /* quantity. */ /*********************************************/ if (g_own_fuel_qty > MAX_FUEL_QTY) { if (g_own_fuel_qty < MAX_ERROR_FUEL_QTY) local_fuel_qty = MAX_FUEL_QTY; else local_fuel_qty = 0; } else { local_fuel_qty = g_own_fuel_qty; } /*********************************************/ /* Scale own fuel quantity to 10 lbs. */ /* Must truncate under 10% and round up above*/ /*********************************************/ /* Convert own fuel quantity to kilograms and*/ /* scale to 10 kilograms. */ /*********************************************/ if (local_fuel_qty < TEN_PERCENT_MAX_FUEL_QTY) { g_fuel_qty[OWN_QTY_ENTRY].lbs = (local_fuel_qty/ 10) * 10; // ARINC g_fuel_qty[OWN_QTY_ENTRY].kgs = (uint) ((float) local_fuel_qty / 2.205); g_fuel_qty[OWN_QTY_ENTRY].kgs = (g_fuel_qty[OWN_QTY_ENTRY].kgs/10) * 10; } /* end if */ else { g_fuel_qty[OWN_QTY_ENTRY].lbs = ((local_fuel_qty + 5)/ 10) * 10; // ARINC g_fuel_qty[OWN_QTY_ENTRY].kgs = (uint) ((float) local_fuel_qty / 2.205); g_fuel_qty[OWN_QTY_ENTRY].kgs = ((g_fuel_qty[OWN_QTY_ENTRY].kgs + 5)/10) * 10; } /* end else */ g_pdm_fuel_qty[OWN_QTY_ENTRY] = g_fuel_qty[OWN_QTY_ENTRY].lbs; /* repeater */ /*********************************************/ /* Scale others fuel quantity to 10 lbs for */ /* repeater display. */ /*************************************************/ /* Convert others fuel quantity to kilograms and */ /* scale to 10 kilograms. */ /*************************************************/ if (g_others_fuel_qty < TEN_PERCENT_MAX_FUEL_QTY) { g_fuel_qty[OTHERS_QTY_ENTRY].lbs = (g_others_fuel_qty / 10) * 10; /* round down */ g_fuel_qty[OTHERS_QTY_ENTRY].kgs = (uint) ((float) g_others_fuel_qty / 2.205); g_fuel_qty[OTHERS_QTY_ENTRY].kgs = (g_fuel_qty[OTHERS_QTY_ENTRY].kgs/10) * 10; } /* end if */ else { g_fuel_qty[OTHERS_QTY_ENTRY].lbs = ((g_others_fuel_qty + 5)/ 10) * 10; /* round up */ g_fuel_qty[OTHERS_QTY_ENTRY].kgs = (uint) ((float) g_others_fuel_qty / 2.205); g_fuel_qty[OTHERS_QTY_ENTRY].kgs = ((g_fuel_qty[OTHERS_QTY_ENTRY].kgs + 5)/10) * 10; } /* end else */ g_pdm_fuel_qty[OTHERS_QTY_ENTRY] = g_fuel_qty[OTHERS_QTY_ENTRY].lbs; /* for repeater */ /*********************************************/ /* If in kilograms mode then output kgs data */ /* to the repeater. */ /*********************************************/ if (g_own_lbs_kgs_mode == KGS_MODE) { g_pdm_fuel_qty[OWN_QTY_ENTRY] = g_fuel_qty[OWN_QTY_ENTRY].kgs ; g_pdm_fuel_qty[OTHERS_QTY_ENTRY] = g_fuel_qty[OTHERS_QTY_ENTRY].kgs ; } g_pdm_fuel_qty[TOTAL_QTY_ENTRY] = g_pdm_fuel_qty[OWN_QTY_ENTRY] + g_pdm_fuel_qty[OTHERS_QTY_ENTRY]; g_own_total_fuel_qty_kgs = g_fuel_qty[OWN_QTY_ENTRY].kgs + g_fuel_qty[OTHERS_QTY_ENTRY].kgs; g_own_total_fuel_qty_lbs = g_fuel_qty[OWN_QTY_ENTRY].lbs + g_fuel_qty[OTHERS_QTY_ENTRY].lbs; /*********************************************/ /* Perform system test only if requested */ /*********************************************/ if (SYSTEM_TEST_ENABLED == g_sys_test_req) { test_count++; // initialized to zero on powerup. /*********************************************/ /* Setup for output of canned data via ARINC.*/ /*********************************************/ g_fuel_qty[OWN_QTY_ENTRY].lbs = LBS_TEST_DATA; // ARINC lbs g_fuel_qty[OWN_QTY_ENTRY].kgs = KGS_TEST_DATA; // ARINC kgs g_fuel_qty[OTHERS_QTY_ENTRY].lbs = LBS_TEST_DATA; // ARINC lbs g_fuel_qty[OTHERS_QTY_ENTRY].kgs = KGS_TEST_DATA; // ARINC kgs if (test_count == TEN_SECONDS) { g_sys_test_req = SYSTEM_TEST_DISABLED; test_count= 0; } } /************************************/ /* Compute total for ARINC output. */ /************************************/ g_own_total_fuel_qty_lbs = g_fuel_qty[OWN_QTY_ENTRY].lbs + g_fuel_qty[OTHERS_QTY_ENTRY].lbs; g_own_total_fuel_qty_kgs = g_fuel_qty[OWN_QTY_ENTRY].kgs + g_fuel_qty[OTHERS_QTY_ENTRY].kgs; if (g_own_lbs_kgs_mode == KGS_MODE) { if (g_pdm_fuel_qty[TOTAL_QTY_ENTRY] > MAX_TOTAL_FUEL_KGS) g_pdm_fuel_qty[TOTAL_QTY_ENTRY] = g_own_total_fuel_qty_kgs = MAX_TOTAL_FUEL_KGS; } else { if (g_pdm_fuel_qty[TOTAL_QTY_ENTRY] > MAX_TOTAL_FUEL_LBS) { g_pdm_fuel_qty[TOTAL_QTY_ENTRY] = g_own_total_fuel_qty_lbs = MAX_TOTAL_FUEL_LBS; } } /*********************************************/ /* Call procedure to compute the imbalance */ /*********************************************/ fqc_compute_imbalance(); /********************/ /* Set the ssm bits */ /********************/ fqc_compute_ssms (); } #pragma EJECT /***************************************************************************/ /* */ /* Unit Name : fqc_compute_imbalance */ /* Description : This unit determines whether the imbalance is present or */ /* : not. */ /***************************************************************************/ void fqc_compute_imbalance(void) { #define THIRTY_SECONDS 15 xdata uint fuel_qty_difference; static xdata uchar up_counter, down_counter; /**************************************************/ /* Find out the difference between left and right */ /* tank quantities. */ /**************************************************/ if (g_pdm_fuel_qty[OWN_QTY_ENTRY] >= g_pdm_fuel_qty[OTHERS_QTY_ENTRY] ) fuel_qty_difference = g_pdm_fuel_qty[OWN_QTY_ENTRY] - g_pdm_fuel_qty[OTHERS_QTY_ENTRY]; else fuel_qty_difference = g_pdm_fuel_qty[OTHERS_QTY_ENTRY] - g_pdm_fuel_qty[OWN_QTY_ENTRY]; /**************************************************/ /* If the difference between left and right */ /* tank quantities is > 270 kg or 600 lb for 30 */ /* sec, declare the imbalance. */ /**************************************************/ if (g_own_lbs_kgs_mode) { if (fuel_qty_difference > 270 ) { up_counter++; if (up_counter == THIRTY_SECONDS) { g_own_sys_imb = SET; up_counter = RESET; } } else up_counter = RESET; } else { if (fuel_qty_difference > 600 ) { up_counter++; if (up_counter == THIRTY_SECONDS) { g_own_sys_imb = SET; up_counter = RESET; } } else up_counter = RESET; } /******************************************************/ /* If the difference between left and right */ /* tank quantities is < 270 kg or 500 lb for 30 */ /* sec while imbalance is active, reset the imbalance.*/ /******************************************************/ if (g_own_sys_imb == SET) { if (g_own_lbs_kgs_mode) { if (fuel_qty_difference < 220 ) { down_counter++; if (down_counter == THIRTY_SECONDS) { g_own_sys_imb = RESET; down_counter = RESET; } } else down_counter = RESET; } else { if (fuel_qty_difference < 500 ) { down_counter++; if (down_counter == THIRTY_SECONDS) { g_own_sys_imb = RESET; down_counter = RESET; } } else down_counter = RESET; } } /**************************************************/ /* If the tank failures are active, reset the */ /* imbalance */ /**************************************************/ if ((g_tank_failure[MY_SIDE] == SET) || (g_tank_failure[OTHER_SIDE] == SET)) { up_counter = RESET; down_counter = RESET; g_own_sys_imb = RESET; } }