coreVarsGenerator.c File Reference

#include "inc/freeEMS.h"
#include "inc/commsCore.h"
#include "inc/coreVarsGenerator.h"

Include dependency graph for coreVarsGenerator.c:

Go to the source code of this file.

Defines

#define COREVARSGENERATOR_C

Functions

void generateCoreVars ()


Define Documentation

#define COREVARSGENERATOR_C

Definition at line 24 of file coreVarsGenerator.c.


Function Documentation

void generateCoreVars ( void   ) 

Definition at line 30 of file coreVarsGenerator.c.

References ADCArray::AAP, CoreVar::AAP, AAP_NOT_CONFIGURED_CODE, fixedConfig1::AAPMinimum, fixedConfig1::AAPRange, ADC_DIVISIONS, ADCArrays, bootTimeAAP, boundedTPSADC, ADCArray::BRV, CoreVar::BRV, BRV_NOT_CONFIGURED_CODE, fixedConfig1::BRVMinimum, fixedConfig1::BRVRange, ADCArray::CHT, CoreVar::CHT, CHT_NOT_CONFIGURED_CODE, CHTTransferTable, CORE_VARS_LENGTH, CoreVars, CoreVar::DDRPM, CoreVar::DRPM, ADCArray::EGO, CoreVar::EGO, ADCArray::EGO2, CoreVar::EGO2, EGO2_NOT_CONFIGURED_CODE, EGO_NOT_CONFIGURED_CODE, fixedConfig1::EGOMinimum, fixedConfig1::EGORange, FALSE, fixedConfigs1, freezingPoint, halfThrottle, ADCArray::IAP, CoreVar::IAP, ADCArray::IAT, CoreVar::IAT, IAT_NOT_CONFIGURED_CODE, IATTransferTable, ADCArray::MAF, CoreVar::MAF, MAFTransferTable, ADCArray::MAP, CoreVar::MAP, MAP_NOT_CONFIGURED_CODE, fixedConfig1::MAPMinimum, fixedConfig1::MAPRange, ADCArray::MAT, CoreVar::MAT, MAT_NOT_CONFIGURED_CODE, fixedConfig1::presetAAP, fixedConfig1::presetBRV, fixedConfig1::presetCHT, fixedConfig1::presetEGO, fixedConfig1::presetEGO2, fixedConfig1::presetIAT, fixedConfig1::presetMAP, fixedConfig1::presetMAT, fixedConfig1::presetTPS, roomTemperature, CoreVar::RPM, RPM, runningTemperature, runningVoltage, seaLevelKPa, sendErrorIfClear(), stoichiometricLambda, ADCArray::TPS, CoreVar::TPS, TPS_NOT_CONFIGURED_CODE, TPS_RANGE_MAX, TPSADCRange, fixedConfig1::TPSClosedMAP, TPSMAPRange, fixedConfig1::TPSMaximumADC, fixedConfig1::TPSMinimumADC, fixedConfig1::TPSOpenMAP, and TRUE.

Referenced by main().

00030                        {
00031         /*&&&&&&&& Calculate and obtain the basic variables with which we will perform the calculations &&&&&&&&*/
00032 
00033 
00034         /* Pre calculate things used in multiple places */
00035 
00036         /* Bound the TPS ADC reading and shift it to start at zero */
00037         unsigned short unboundedTPSADC = ADCArrays->TPS;
00038         if(unboundedTPSADC > fixedConfigs1.TPSMaximumADC){
00039                 boundedTPSADC = TPSADCRange;
00040         }else if(unboundedTPSADC > fixedConfigs1.TPSMinimumADC){ // force secondary config to be used... TODO remove this
00041                 boundedTPSADC = unboundedTPSADC - fixedConfigs1.TPSMinimumADC;
00042         }else{
00043                 boundedTPSADC = 0;
00044         }
00045 
00046 
00047         /* Get BRV from ADC using transfer variables (all installations need this) */
00048         unsigned short localBRV;
00049         if(TRUE){ /* If BRV connected  */
00050                 localBRV = (((unsigned long)ADCArrays->BRV * fixedConfigs1.BRVRange) / ADC_DIVISIONS) + fixedConfigs1.BRVMinimum;
00051         }else if(FALSE){ /* Configured to be fixed value */
00052                 /* Get the preferred BRV figure from configuration settings */
00053                 localBRV = fixedConfigs1.presetBRV;
00054         }else{ /* Fail safe if config is broken */
00055                 /* Default to normal alternator charging voltage 14.4V */
00056                 localBRV = runningVoltage;
00057                 /* If anyone is listening, let them know something is wrong */
00058                 sendErrorIfClear(BRV_NOT_CONFIGURED_CODE);
00059         }
00060 
00061 
00062         unsigned short localCHT;
00063         /* Get CHT from ADC using the transfer table (all installations need this) */
00064         if(TRUE){ /* If CHT connected  */
00065                 localCHT = CHTTransferTable[ADCArrays->CHT];
00066         }else if(FALSE){ /* Configured to be read From ADC as dashpot */
00067                 /* Transfer the ADC reading to an engine temperature in a reasonable way */
00068                 localCHT = (ADCArrays->CHT * 10) + freezingPoint; /* 0 ADC = 0C = 273.15K = 27315, 1023 ADC = 102.3C = 375.45K = 37545 */
00069         }else if(FALSE){ /* Configured to be fixed value */
00070                 /* Get the preferred CHT figure from configuration settings */
00071                 localCHT = fixedConfigs1.presetCHT;
00072         }else{ /* Fail safe if config is broken */
00073                 /* Default to normal running temperature of 85C/358K */
00074                 localCHT = runningTemperature;
00075                 /* If anyone is listening, let them know something is wrong */
00076                 sendErrorIfClear(CHT_NOT_CONFIGURED_CODE);
00077         }
00078 
00079 
00080         unsigned short localIAT;
00081         /* Get IAT from ADC using the transfer table (all installations need this) */
00082         if(TRUE){ /* If IAT connected  */
00083                 localIAT = IATTransferTable[ADCArrays->IAT];
00084         }else if(FALSE){ /* Configured to be read From ADC as dashpot */
00085                 /* Transfer the ADC reading to an air temperature in a reasonable way */
00086                 localIAT = (ADCArrays->IAT * 10) + 27315; /* 0 ADC = 0C = 273.15K = 27315, 1023 ADC = 102.3C = 375.45K = 37545 */
00087         }else if(FALSE){ /* Configured to be fixed value */
00088                 /* Get the preferred IAT figure from configuration settings */
00089                 localIAT = fixedConfigs1.presetIAT;
00090         }else{ /* Fail safe if config is broken */
00091                 /* Default to normal air temperature of 20C/293K */
00092                 localIAT = roomTemperature;
00093                 /* If anyone is listening, let them know something is wrong */
00094                 sendErrorIfClear(IAT_NOT_CONFIGURED_CODE);
00095         }
00096 
00097 
00098         unsigned short localMAT;
00099         /* Determine the MAT reading for future calculations */
00100         if(TRUE){ /* If MAT sensor is connected */
00101                 /* Get MAT from ADC using same transfer table as IAT (too much space to waste on having two) */
00102                 localMAT = IATTransferTable[ADCArrays->MAT];
00103         }else if(FALSE){ /* Configured to be fixed value */
00104                 /* Get the preferred MAT figure from configuration settings */
00105                 localMAT = fixedConfigs1.presetMAT;
00106         }else{ /* Fail safe if config is broken */
00107                 /* If not, default to same value as IAT */
00108                 localMAT = localIAT;
00109                 /* If anyone is listening, let them know something is wrong */
00110                 sendErrorIfClear(MAT_NOT_CONFIGURED_CODE);
00111         }
00112 
00113 
00114         unsigned short localMAP;
00115         unsigned short localIAP;
00116         /* Determine the MAP pressure to use for future calculations */
00117         if(TRUE){ /* If MAP sensor is connected */
00118                 /* get MAP from ADC using transfer variables */
00119                 localMAP = (((unsigned long)ADCArrays->MAP * fixedConfigs1.MAPRange) / ADC_DIVISIONS) + fixedConfigs1.MAPMinimum;
00120                 if(TRUE){ /* If Intercooler boost sensor connected */
00121                         /* Get IAP from ADC using the same transfer variables as they both need to read the same range */
00122                         localIAP = (((unsigned long)ADCArrays->IAP * fixedConfigs1.MAPRange) / ADC_DIVISIONS) + fixedConfigs1.MAPMinimum;
00123                 }
00124         }else if(FALSE){ /* Configured for MAP to imitate TPS signal */
00125                 /* Get MAP from TPS via conversion */
00126                 localMAP = (((unsigned long)boundedTPSADC * TPSMAPRange) / TPSADCRange) + fixedConfigs1.TPSClosedMAP;
00127         }else if(FALSE){ /* Configured for dash potentiometer on ADC */
00128                 /* Get MAP from ADC via conversion to internal kPa figure where 1023ADC = 655kPa */
00129                 localMAP = ADCArrays->MAP << 6;
00130                 if(TRUE){ /* If Intercooler boost sensor enabled */
00131                         /* Get IAP from ADC via conversion to internal kPa figure where 1023ADC = 655kPa */
00132                         localIAP = ADCArrays->IAP << 6;
00133                 }
00134         }else if(FALSE){ /* Configured for fixed MAP from config */
00135                 /* Get the preferred MAP figure from configuration settings */
00136                 localMAP = fixedConfigs1.presetMAP;
00137         }else{ /* Fail safe if config is broken */
00138                 /* Default to zero to nulify all other calcs and effectively cut fuel */
00139                 localMAP = 0;
00140                 /* If anyone is listening, let them know something is wrong */
00141                 sendErrorIfClear(MAP_NOT_CONFIGURED_CODE); // or maybe queue it?
00142         }
00143 
00144 
00145         /* Determine MAF variable if required */
00146         unsigned short localMAF = 0; // Default to zero as it is not required for anything except main PW calcs optionally
00147         if(TRUE){
00148                 localMAF = MAFTransferTable[ADCArrays->MAF];
00149         }
00150 
00151         unsigned short localAAP;
00152         /* Determine the Atmospheric pressure to use for future calculations */
00153         if(TRUE){ /* Configured for second sensor to read AAP */
00154                 /* get AAP from ADC using separate vars to allow 115kPa sensor etc to be used */
00155                 localAAP = (((unsigned long)ADCArrays->AAP * fixedConfigs1.AAPRange) / ADC_DIVISIONS) + fixedConfigs1.AAPMinimum;
00156         }else if(FALSE){ /* Configured for dash potentiometer on ADC */
00157                 /* Get AAP from ADC via conversion to internal kPa figure where 1023ADC = 102.3kPa */
00158                 localAAP = ADCArrays->AAP * 10;
00159         }else if(FALSE){ /* Configured for fixed AAP reading from pre start */
00160                 /* Get the AAP reading as saved during startup */
00161                 localAAP = bootTimeAAP; /* This is populated pre start up */
00162         }else if(FALSE){ /* Configured for fixed AAP from config */
00163                 /* Get the preferred AAP figure from configuration settings */
00164                 localAAP = fixedConfigs1.presetAAP;
00165         }else{ /* Fail safe if config is broken */
00166                 /* Default to sea level */
00167                 localAAP = seaLevelKPa; /* 100kPa */
00168                 /* If anyone is listening, let them know something is wrong */
00169                 sendErrorIfClear(AAP_NOT_CONFIGURED_CODE); // or maybe queue it?
00170         }
00171 
00172 
00173         unsigned short localEGO;
00174         /* Get main Lambda reading */
00175         if(TRUE){ /* If WBO2-1 is connected */
00176                 /* Get EGO from ADCs using transfer variables */
00177                 localEGO = (((unsigned long)ADCArrays->EGO * fixedConfigs1.EGORange) / ADC_DIVISIONS) + fixedConfigs1.EGOMinimum;
00178         }else if(FALSE){ /* Configured for fixed EGO from config */
00179                 /* Get the preferred EGO figure from configuration settings */
00180                 localEGO = fixedConfigs1.presetEGO;
00181         }else{ /* Default value if not connected incase other things are misconfigured */
00182                 /* Default to stoichiometric */
00183                 localEGO = stoichiometricLambda; /* EGO / 32768 = Lambda */
00184                 /* If anyone is listening, let them know something is wrong */
00185                 sendErrorIfClear(EGO_NOT_CONFIGURED_CODE); // or maybe queue it?
00186         }
00187 
00188 
00189         unsigned short localEGO2;
00190         /* Get second Lambda reading */
00191         if(TRUE){ /* If WBO2-2 is connected */
00192                 /* Get EGO2 from ADCs using same transfer variables as EGO */
00193                 localEGO2 = (((unsigned long)ADCArrays->EGO2 * fixedConfigs1.EGORange) / ADC_DIVISIONS) + fixedConfigs1.EGOMinimum;
00194         }else if(FALSE){ /* Configured for fixed EGO2 from config */
00195                 /* Get the preferred EGO2 figure from configuration settings */
00196                 localEGO2 = fixedConfigs1.presetEGO2;
00197         }else{ /* Default value if not connected incase other things are misconfigured */
00198                 /* Default to stoichiometric */
00199                 localEGO2 = stoichiometricLambda;
00200                 /* If anyone is listening, let them know something is wrong */
00201                 sendErrorIfClear(EGO2_NOT_CONFIGURED_CODE); // or maybe queue it?
00202         }
00203 
00204 
00205         unsigned short localTPS;
00206         /* Get TPS percentage */
00207         if(TRUE){ /* If TPS is connected */
00208                 /* Get TPS from ADC no need to add TPS min as we know it is zero by definition */
00209                 localTPS = ((unsigned long)boundedTPSADC * TPS_RANGE_MAX) / TPSADCRange;
00210         }else if(FALSE){ /* Configured for TPS to imitate MAP signal */
00211                 /* Get TPS from MAP via conversion */
00212                 /* Box MAP signal down */
00213                 if(localTPS > fixedConfigs1.TPSOpenMAP){ /* Greater than ~95kPa */
00214                         localTPS = TPS_RANGE_MAX; /* 64000/640 = 100% */
00215                 }else if(localTPS < fixedConfigs1.TPSClosedMAP){ /* Less than ~30kPa */
00216                         localTPS = 0;
00217                 }else{ /* Scale MAP range to TPS range */
00218                         localTPS = localMAP - fixedConfigs1.TPSClosedMAP;
00219                 }
00220                 // get TPS from MAP no need to add TPS min as we know it is zero by definition
00221                 localTPS = ((unsigned long)localTPS * TPS_RANGE_MAX) / (fixedConfigs1.TPSOpenMAP - fixedConfigs1.TPSClosedMAP);
00222         }else if(FALSE){ /* Configured for dash potentiometer on ADC */
00223                 /* Get TPS from ADC as shown : 1023 ADC = 100%, 0 ADC = 0% */
00224                 localTPS = ((unsigned long)ADCArrays->TPS * TPS_RANGE_MAX) / ADC_DIVISIONS;
00225         }else if(FALSE){ /* Configured for fixed TPS from config */
00226                 /* Get the preferred TPS figure from configuration settings */
00227                 localTPS = fixedConfigs1.presetTPS;
00228         }else{ /* Fail safe if config is broken */
00229                 /* Default to 50% to not trigger any WOT or CT conditions */
00230                 localTPS = halfThrottle;
00231                 /* If anyone is listening, let them know something is wrong */
00232                 sendErrorIfClear(TPS_NOT_CONFIGURED_CODE); // or maybe queue it?
00233         }
00234 
00235 
00236         /* Get RPM by locking out ISRs for a second and grabbing the Tooth logging data */
00237         //atomic start
00238         // copy rpm data
00239         //atomic end
00240 
00241         // Calculate RPM and delta RPM and delta delta RPM from data recorded
00242         CoreVars->RPM = *RPM; // temporary!!
00243         unsigned short localDRPM = 0;
00244         unsigned short localDDRPM = 0;
00245 
00246 
00247         /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
00248 
00249 
00250 
00251 
00252         /*&&&&&&&&&&&&&&&&&&&&&&&&&&&& Average the variables as per the configuration &&&&&&&&&&&&&&&&&&&&&&&&&&*/
00253         /* Strictly speaking only the primary variables need to be averaged. After that, the derived ones are   */
00254         /* already averaged in a way. However, there may be some advantage to some short term averaging on the  */
00255         /* derived ones also, so it is something to look into later.                                                                                    */
00256 
00257         // TODO average them here
00258 
00259 //                      newVal var word        ' the value from the ADC
00260 //                      smoothed var word    ' a nicely smoothed result
00261 //
00262 //                      if newval > smoothed then
00263 //                              smoothed = smoothed + (newval - smoothed)/alpha
00264 //                      else
00265 //                              smoothed = smoothed - (smoothed - newval)/alpha
00266 //                      endif
00267 
00268         // from : http://www.tigoe.net/pcomp/code/category/code/arduinowiring/41
00269 
00270         // for now just copy them in.
00271         CoreVars->IAT = localIAT;
00272         CoreVars->CHT = localCHT;
00273         CoreVars->TPS = localTPS;
00274         CoreVars->EGO = localEGO;
00275         CoreVars->BRV = localBRV;
00276         CoreVars->MAP = localMAP;
00277         CoreVars->AAP = localAAP;
00278         CoreVars->MAT = localMAT;
00279 
00280         CoreVars->EGO2 = localEGO2;
00281         CoreVars->IAP = localIAP;
00282         CoreVars->MAF = localMAF;
00283         CoreVars->DRPM = localDRPM;
00284         CoreVars->DDRPM = localDDRPM;
00285 
00286         // later...
00287         unsigned short i;
00288         for(i=0;i<CORE_VARS_LENGTH;i++){ // TODO
00289                 /* Perform averaging on all primary variables as per the configuration array */
00290                 // get old value(s)
00291                 // process new and old to produce result based on config array value */
00292                 // assign result to old value holder
00293         } // TODO
00294 
00295         /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
00296 }

Here is the call graph for this function:


Generated on Mon Dec 22 21:29:36 2008 for freeems by  doxygen 1.5.2