00001 /* Copyright 2008 Fred Cooke 00002 00003 This file is part of the FreeEMS project. 00004 00005 FreeEMS software is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 FreeEMS software is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00017 00018 We ask that if you make any changes to this file you email them upstream to 00019 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00020 00021 Thank you for choosing FreeEMS to run your engine! */ 00022 00023 00035 #define DERIVEDVARSGENERATOR_C 00036 #include "inc/freeEMS.h" 00037 #include "inc/commsCore.h" 00038 #include "inc/tableLookup.h" 00039 #include "inc/derivedVarsGenerator.h" 00040 00041 00050 void generateDerivedVars(){ 00051 /*&&&&&&&&&&&&&&&&&&&& Use basic variables to lookup and calculate derived variables &&&&&&&&&&&&&&&&&&&*/ 00052 00053 00054 /* Determine load based on options */ 00055 if(TRUE){ /* Use MAP as load */ 00056 DerivedVars->LoadMain = CoreVars->MAP; 00057 }else if(FALSE){ /* Use TPS as load */ 00058 DerivedVars->LoadMain = CoreVars->TPS; 00059 }else if(FALSE){ /* Use AAP corrected MAP as load */ 00060 DerivedVars->LoadMain = ((unsigned long)CoreVars->MAP * CoreVars->AAP) / seaLevelKPa; 00061 }else{ /* Default to MAP, but throw error */ 00062 DerivedVars->LoadMain = CoreVars->MAP; 00063 /* If anyone is listening, let them know something is wrong */ 00064 sendErrorIfClear(LOAD_NOT_CONFIGURED_CODE); // or maybe queue it? 00065 } 00066 00067 00068 /* Look up VE with RPM and Load */ 00069 DerivedVars->VEMain = lookupPagedMainTableCellValue((mainTable*)&TablesA.VETableMain, CoreVars->RPM, DerivedVars->LoadMain, currentFuelRPage); 00070 00071 00072 /* Look up target Lambda with RPM and Load */ 00073 DerivedVars->Lambda = lookupPagedMainTableCellValue((mainTable*)&TablesD.LambdaTable, CoreVars->RPM, DerivedVars->LoadMain, currentFuelRPage); 00074 00075 00076 /* Look up injector dead time with battery voltage */ 00077 DerivedVars->IDT = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.injectorDeadTimeTable, CoreVars->BRV); 00078 00079 00080 /* Calculate the engine temperature enrichment */ 00081 // unsigned short localETEPercentage = lookupTwoDTableUS(&engineTempEnrichmentTable, CoreVars.CHT); 00082 // DerivedVars->ETE = ((unsigned long)finalMasterTotalEndPW * localETEPercentage) / oneHundredPercentETE; 00083 /* TODO The above needs some careful thought put into it around different loads and correction effects. */ 00084 00085 00086 /* Calculate the Transient Fuel Correction */ 00087 if(TRUE /*WWTFC*/){ /* Do ONLY WW correction if enabled */ 00088 // Do ww stuff, maybe pre done via RTC/RTI for consistent period? 00089 DerivedVars->TFCTotal = 0; /* TODO replace with real code */ 00090 }else if(FALSE /*STDTFC*/){ /* Do any combination of standard approximate methods */ 00091 /* Initialse the variable as a base */ 00092 DerivedVars->TFCTotal = 0; 00093 /* Based on the rate of change of MAP and some history/taper time */ 00094 if(FALSE /*MAPTFC*/){ 00095 // Do MAP based 00096 DerivedVars->TFCTotal += 0; 00097 } 00098 00099 /* Based on the rate of change of TPS and some history/taper time */ 00100 if(FALSE /*TPSTFC*/){ 00101 // Do TPS based 00102 DerivedVars->TFCTotal += 0; 00103 } 00104 00105 /* Based on the rate of change of RPM and some history/taper time */ 00106 if(FALSE /*RPMTFC*/){ 00107 // Do RPM based 00108 DerivedVars->TFCTotal += 0; 00109 } 00110 }else{ /* Default to no correction */ 00111 DerivedVars->TFCTotal = 0; 00112 /* Don't throw error as correction may not be required */ 00113 } 00114 00115 00116 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ 00117 }