FreeEMS  0.2.0-SNAPSHOT-285-g028e24c
Macros | Functions
coreVarsGenerator.c File Reference

Generate and average the core variables. More...

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

Go to the source code of this file.

Macros

#define COREVARSGENERATOR_C

Functions

void generateCoreVars ()
 Calculate and obtain the core variables.

Detailed Description

Generate and average the core variables.

This file contains the function that transfers the raw ADC values to actual physical measurements and averages them.

Definition in file coreVarsGenerator.c.

Macro Definition Documentation

#define COREVARSGENERATOR_C

Definition at line 38 of file coreVarsGenerator.c.

Function Documentation

void generateCoreVars ( void  )

Calculate and obtain the core variables.

Each raw ADC value is converted to a usable measurement via a variety of methods. They are then stored in a struct and used as input to the next phase.

Todo:
TODO average the generated values here

Definition at line 50 of file coreVarsGenerator.c.

References ADCBuffer::AAP, CoreVar::AAP, sensorRange::AAPMinimum, sensorRange::AAPRange, ADC_DIVISIONS, ADCBuffers, ADCBuffer::BRV, sensorSource::BRV, CoreVar::BRV, sensorRange::BRVMinimum, sensorRange::BRVRange, ADCBuffer::CHT, sensorSource::CHT, CoreVar::CHT, CHTTransferTable, CoreVars, DEGREES_C, degreeTicksPerMinute, CoreVar::DRPM, ADCBuffer::EGO, CoreVar::EGO, ADCBuffer::EGO2, CoreVar::EGO2, sensorRange::EGOMinimum, sensorRange::EGORange, fixedConfigs2, ADCBuffer::IAP, CoreVar::IAP, ADCBuffer::IAT, sensorSource::IAT, CoreVar::IAT, IATTransferTable, ADCBuffer::MAF, CoreVar::MAF, MAFTransferTable, ADCBuffer::MAP, CoreVar::MAP, sensorRange::MAPMinimum, sensorRange::MAPRange, ADCBuffer::MAT, CoreVar::MAT, PERCENT, sensorPreset::presetBRV, sensorPreset::presetCHT, sensorPreset::presetIAT, CoreVar::RPM, fixedConfig2::sensorPresets, fixedConfig2::sensorRanges, fixedConfig2::sensorSources, SOURCE_LINEAR, SOURCE_PRESET, ticksPerDegree, ADCBuffer::TPS, CoreVar::TPS, TPSADCRange, sensorRange::TPSMaximumADC, sensorRange::TPSMinimumADC, and VOLTS.

Referenced by main().

{
// Battery Reference Voltage
unsigned short localBRV;
localBRV = (ADCBuffers->BRV * 14) + VOLTS(7.2); // 0 ADC = 7.2V, 1023 ADC = 21.522C
}else{ // Default to normal alternator charging voltage 14.4V
localBRV = VOLTS(14.4);
}
// Coolant/Head Temperature
unsigned short localCHT;
localCHT = (ADCBuffers->CHT * 10) + DEGREES_C(0); // 0 ADC = 0C, 1023 ADC = 102.3C
}else{ // Default to slightly cold and therefore rich: 65C
localCHT = DEGREES_C(65);
}
// Inlet Air Temperature
unsigned short localIAT;
localIAT = (ADCBuffers->IAT * 10) + DEGREES_C(0); // 0 ADC = 0C, 1023 ADC = 102.3C
}else{ // Default to room temperature
localIAT = DEGREES_C(20);
}
// Throttle Position Sensor
/* Bound the TPS ADC reading and shift it to start at zero */
unsigned short unboundedTPSADC = ADCBuffers->TPS;
unsigned short boundedTPSADC;
if(unboundedTPSADC > fixedConfigs2.sensorRanges.TPSMaximumADC){
boundedTPSADC = TPSADCRange;
}else if(unboundedTPSADC > fixedConfigs2.sensorRanges.TPSMinimumADC){
boundedTPSADC = unboundedTPSADC - fixedConfigs2.sensorRanges.TPSMinimumADC;
} else{
boundedTPSADC = 0;
}
}else{ // Reverse slope!
if(unboundedTPSADC > fixedConfigs2.sensorRanges.TPSMinimumADC){
boundedTPSADC = 0;
}else if(unboundedTPSADC > fixedConfigs2.sensorRanges.TPSMaximumADC){
boundedTPSADC = fixedConfigs2.sensorRanges.TPSMinimumADC - unboundedTPSADC;
}else{
boundedTPSADC = TPSADCRange;
}
}
/* Get TPS from ADC no need to add TPS min as we know it is zero by definition */
unsigned short localTPS = ((unsigned long)boundedTPSADC * PERCENT(100)) / TPSADCRange;
// TODO fail safe mode, only if on the ADC rails AND configured to do so
// Default to a low value that will get you home if you are in Alpha-N mode
/* Get RPM by locking out ISRs for a second and grabbing the Tooth logging data */
//atomic start
// copy rpm data
//atomic end
// Calculate RPM and delta RPM and delta delta RPM from data recorded
if(*ticksPerDegree != 0){
}else{
CoreVars->RPM = 0;
}
// unsigned short localDRPM = 0;
// unsigned short localDDRPM = 0;
// TODO This might get done somewhere else, separation of concerns, etc
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&& Average the variables as per the configuration &&&&&&&&&&&&&&&&&&&&&&&&&&*/
/* Strictly speaking only the primary variables need to be averaged. After that, the derived ones are */
/* already averaged in a way. However, there may be some advantage to some short term averaging on the */
/* derived ones also, so it is something to look into later. */
/// @todo TODO average the generated values here
// newVal var word ' the value from the ADC
// smoothed var word ' a nicely smoothed result
//
// if newval > smoothed then
// smoothed = smoothed + (newval - smoothed)/alpha
// else
// smoothed = smoothed - (smoothed - newval)/alpha
// endif
// from : http://www.tigoe.net/pcomp/code/category/code/arduinowiring/41
// for now just copy them in.
CoreVars->BRV = localBRV;
CoreVars->CHT = localCHT;
CoreVars->IAT = localIAT;
CoreVars->TPS = localTPS;
// Not actually used, feed raw values for now TODO migrate these to a SpecialVars struct or similar not included in default datalog
// CoreVars->DRPM = localDRPM;
// CoreVars->DDRPM = localDDRPM;
// CoreVars->DTPS = localDTPS;
}

Here is the caller graph for this function: