FreeEMS  0.2.0-SNAPSHOT-282-g9efc524
Macros | Functions
derivedVarsGenerator.c File Reference

Generate the derived variables. More...

#include "inc/freeEMS.h"
#include "inc/commsCore.h"
#include "inc/tableLookup.h"
#include "inc/derivedVarsGenerator.h"
#include "inc/locationIDs.h"
#include "inc/decoderInterface.h"
Include dependency graph for derivedVarsGenerator.c:

Go to the source code of this file.

Macros

#define DERIVEDVARSGENERATOR_C

Functions

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

Detailed Description

Generate the derived variables.

Second level variables are derived from the core variables and generated here.

Definition in file derivedVarsGenerator.c.

Macro Definition Documentation

#define DERIVEDVARSGENERATOR_C

Definition at line 37 of file derivedVarsGenerator.c.

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: