00001 /* FreeEMS - the open source engine management system 00002 * 00003 * Copyright 2008, 2009, 2010 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 email them upstream to 00021 * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00022 * 00023 * Thank you for choosing FreeEMS to run your engine! 00024 */ 00025 00026 00038 #define DERIVEDVARSGENERATOR_C 00039 #include "inc/freeEMS.h" 00040 #include "inc/commsCore.h" 00041 #include "inc/tableLookup.h" 00042 #include "inc/derivedVarsGenerator.h" 00043 00044 00053 void generateDerivedVars(){ 00054 /*&&&&&&&&&&&&&&&&&&&& Use basic variables to lookup and calculate derived variables &&&&&&&&&&&&&&&&&&&*/ 00055 00056 00057 /* Determine load based on options */ 00058 if(TRUE){ /* Use MAP as load */ 00059 DerivedVars->LoadMain = CoreVars->MAP; 00060 }else if(FALSE){ /* Use TPS as load */ 00061 DerivedVars->LoadMain = CoreVars->TPS; 00062 }else if(FALSE){ /* Use AAP corrected MAP as load */ 00063 DerivedVars->LoadMain = ((unsigned long)CoreVars->MAP * CoreVars->AAP) / seaLevelKPa; 00064 }else{ /* Default to MAP, but throw error */ 00065 DerivedVars->LoadMain = CoreVars->MAP; 00066 /* If anyone is listening, let them know something is wrong */ 00067 sendErrorIfClear(LOAD_NOT_CONFIGURED_CODE); // or maybe queue it? 00068 } 00069 00070 00071 /* Look up VE with RPM and Load */ 00072 DerivedVars->VEMain = lookupPagedMainTableCellValue((mainTable*)&TablesA.VETableMain, CoreVars->RPM, DerivedVars->LoadMain, currentFuelRPage); 00073 00074 00075 /* Look up target Lambda with RPM and Load */ 00076 DerivedVars->Lambda = lookupPagedMainTableCellValue((mainTable*)&TablesD.LambdaTable, CoreVars->RPM, DerivedVars->LoadMain, currentFuelRPage); 00077 00078 00079 /* Look up injector dead time with battery voltage */ 00080 DerivedVars->IDT = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.injectorDeadTimeTable, CoreVars->BRV); 00081 00082 00083 /* Look up the engine temperature enrichment percentage with temperature */ 00084 DerivedVars->ETE = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.engineTempEnrichmentTablePercent, CoreVars->CHT); 00085 /* TODO The above needs some careful thought put into it around different loads and correction effects. */ 00086 00087 00088 /* Calculate the Transient Fuel Correction */ 00089 if(TRUE /*WWTFC*/){ /* Do ONLY WW correction if enabled */ 00090 // Do ww stuff, maybe pre done via RTC/RTI for consistent period? 00091 DerivedVars->TFCTotal = 0; /* TODO replace with real code */ 00092 }else if(FALSE /*STDTFC*/){ /* Do any combination of standard approximate methods */ 00093 /* Initialse the variable as a base */ 00094 DerivedVars->TFCTotal = 0; 00095 /* Based on the rate of change of MAP and some history/taper time */ 00096 if(FALSE /*MAPTFC*/){ 00097 // Do MAP based 00098 DerivedVars->TFCTotal += 0; 00099 } 00100 00101 /* Based on the rate of change of TPS and some history/taper time */ 00102 if(FALSE /*TPSTFC*/){ 00103 // Do TPS based 00104 DerivedVars->TFCTotal += 0; 00105 } 00106 00107 /* Based on the rate of change of RPM and some history/taper time */ 00108 if(FALSE /*RPMTFC*/){ 00109 // Do RPM based 00110 DerivedVars->TFCTotal += 0; 00111 } 00112 }else{ /* Default to no correction */ 00113 DerivedVars->TFCTotal = 0; 00114 /* Don't throw error as correction may not be required */ 00115 } 00116 00117 // debug 00118 00119 LongTime breakout2, breakout4; 00120 // breakout.timeLong = timeBetweenSuccessivePrimaryPulsesBuffer; 00121 breakout2.timeLong = timeBetweenSuccessivePrimaryPulses; 00122 // breakout3.timeLong = lengthOfSecondaryHighPulses; 00123 breakout4.timeLong = lengthOfSecondaryLowPulses; 00124 00125 // DerivedVars->sp1 = Counters.primaryTeethSeen; 00126 // DerivedVars->sp2 = Counters.secondaryTeethSeen; 00127 00128 // DerivedVars->sp3 = breakout4.timeShorts[0]; 00129 DerivedVars->sp1 = breakout4.timeShorts[1]; 00130 00131 // DerivedVars->TFCTotal = *RPMRecord; 00132 00133 // CoreVars->DMAP = breakout3.timeShorts[0]; 00134 // CoreVars->DTPS = breakout3.timeShorts[1]; 00135 00136 CoreVars->DRPM = breakout2.timeShorts[0]; 00137 CoreVars->DDRPM = breakout2.timeShorts[1]; 00138 00139 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ 00140 }