FreeEMS  0.2.0-SNAPSHOT-282-g9efc524
Macros | Functions
derivedVarsGenerator.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define EXTERN   extern

Functions

void generateDerivedVars (void) FPAGE_FE
 Use core variables to lookup and calculate the derived variables.

Detailed Description

Definition in file derivedVarsGenerator.h.

Macro Definition Documentation

#define EXTERN   extern

Definition at line 48 of file derivedVarsGenerator.h.

Function Documentation

void generateDerivedVars ( void  )

Use core variables to lookup and calculate the derived variables.

This function uses the core variables to lookup and calculate further second order variables such as load, VE, Lamdda, Transient fuel correction, engine temperature enrichment, Injector dead time, etc.

Todo:
TODO make generic!!!!

Definition at line 52 of file derivedVarsGenerator.c.

References CoreVar::AAP, DerivedVar::Advance, fixedConfig2::algorithmSettings, ANGLE_FACTOR, CoreVar::BRV, CoreVar::CHT, CoreVars, DerivedVars, CoreVar::DRPM, DerivedVar::Dwell, DWELL_FIXED, DWELL_RPM, algorithmSetting::dwellFixedPeriod, algorithmSetting::dwellType, DerivedVar::ETE, FALSE, fixedConfigs2, DerivedVar::IDT, IgnitionAdvanceTableMainLocationID, KPA, DerivedVar::Lambda, LambdaTableLocationID, LOAD_AAP, LOAD_TPS, DerivedVar::LoadMain, algorithmSetting::loadType, lookupMainTable(), lookupTwoDTableUS(), CoreVar::MAP, CoreVar::RPM, DerivedVar::TFCTotal, ticks_per_degree_multiplier, CoreVar::TPS, and TRUE.

Referenced by main().

{
/* Determine load based on options */
if(!(fixedConfigs2.algorithmSettings.loadType)){ /* Use MAP as load */
}else if(fixedConfigs2.algorithmSettings.loadType == LOAD_TPS){ /* Use TPS as load */
}else if(fixedConfigs2.algorithmSettings.loadType == LOAD_AAP){ /* Use AAP corrected MAP as load */
DerivedVars->LoadMain = ((unsigned long)CoreVars->MAP * CoreVars->AAP) / KPA(100);
// TODO add maf calc load option here
}else{ /* Default to MAP, but throw error */
}
/* Look up target Lambda with RPM and Load */
/* Look up injector dead time with battery voltage */
DerivedVars->IDT = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.injectorDeadTimeTable, CoreVars->BRV);
DerivedVars->Dwell = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.dwellDesiredVersusVoltageTable, CoreVars->BRV);
DerivedVars->Dwell = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.dwellVersusRPMTable, CoreVars->RPM);
}else{
}
DerivedVars->Advance = (unsigned short)(tempAdvance / 1024); // This calculation will change when the timing tables get shrunk to a more reasonable 8 bit size with appropriate scaling
// Move this magic number to an appropriate place and/or refactor timing calcs/values/etc
/// @todo TODO make generic!!!!
// to go generic we need:
// angle between ignition events (if have tpd) (or total angle and number of events)
// max % dwell
// minimum spark time
// a setting to choose which behaviour (don't limit/% dwell limit/min spark time/other?)
#if CONFIG == HOTEL_ID
/// @bug hack for hyundai! 135 = 3/4 of 180 = one cycle...
unsigned long threeQuartersOfAvailableTime = ((unsigned long)CoreVars->DRPM * 135 * ANGLE_FACTOR) / ticks_per_degree_multiplier;
if(DerivedVars->Dwell > threeQuartersOfAvailableTime){
DerivedVars->Dwell = threeQuartersOfAvailableTime;
}
#endif
/* Look up the engine temperature enrichment percentage with temperature */
DerivedVars->ETE = lookupTwoDTableUS((twoDTableUS*)&TablesA.SmallTablesA.engineTempEnrichmentTablePercent, CoreVars->CHT);
/* TODO The above needs some careful thought put into it around different loads and correction effects. */
/* Calculate the Transient Fuel Correction */
if(TRUE /*WWTFC*/){ /* Do ONLY WW correction if enabled */
// Do ww stuff, maybe pre done via RTC/RTI for consistent period?
DerivedVars->TFCTotal = 0; /* TODO replace with real code */
}else if(FALSE /*STDTFC*/){ /* Do any combination of standard approximate methods */
/* Initialse the variable as a base */
/* Based on the rate of change of MAP and some history/taper time */
if(FALSE /*MAPTFC*/){
// Do MAP based
}
/* Based on the rate of change of TPS and some history/taper time */
if(FALSE /*TPSTFC*/){
// Do TPS based
}
/* Based on the rate of change of RPM and some history/taper time */
if(FALSE /*RPMTFC*/){
// Do RPM based
}
}else{ /* Default to no correction */
/* Don't throw error as correction may not be required */
}
}

Here is the call graph for this function:

Here is the caller graph for this function: