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