Initial (mostly untested) live baro reading

This commit is contained in:
Josh Stewart 2017-07-17 17:06:14 +10:00
parent 905a8642ff
commit 9d2e938a4d
6 changed files with 62 additions and 20 deletions

View File

@ -370,7 +370,7 @@ page = 6
egoType = bits , U08, 0, [2:3], "Disabled", "Narrow Band", "Wide Band", "INVALID" ; egoOption
boostEnabled= bits, U08, 0, [4:4], "Off", "On"
vvtEnabled = bits, U08, 0, [5:5], "Off", "On"
boostCutType= bits, U08, 0, [6:7], "Off", "Spark Only", "Fuel Only","Both"
boostCutType= bits, U08, 0, [6:7], "Off", "Spark Only", "Fuel Only","Both"
egoKP = scalar, U08, 1, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte)
egoKI = scalar, U08, 2, "%", 1.0, 0.0, 0.0, 200.0, 0 ; * ( 1 byte)
@ -389,7 +389,7 @@ page = 6
egoRPM = scalar, U08, 11, "rpm", 100, 0.0, 100, 25500, 0
egoTPSMax = scalar, U08, 12, "%", 1, 0, 0, 120, 0
vvtPin = bits , U08, 13, [0:5], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
unused6-13e = bits, U08, 13, [6:6], "ONE", "INVALID"
useExtBaro = bits, U08, 13, [6:6], "No", "Yes"
unused6-13f = bits, U08, 13, [7:7], "ONE", "INVALID"
boostPin = bits, U08, 14, [0:5], "Board Default", "INVALID", "INVALID", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
unused6-14e = bits, U08, 14, [6:6], "ONE", "INVALID"
@ -429,9 +429,8 @@ page = 6
lnchPullRes = bits, U08, 60, [0:1], "Float" , "Pullup", "INVALID", "INVALID"
fuelTrimEnabled= bits, U08, 60, [2:2], "No", "Yes"
flatSEnable = bits, U08, 60, [3:3], "No", "Yes"
; Baro Sensor
useExtBaro = bits, U08, 60, [4:4], "No", "Yes"
baroPin = bits, U08, 60, [5:7], "ONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
; Baro Sensor pin
baroPin = bits, U08, 60, [4:7], "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A8", "A10", "A11", "A12", "A13", "A14", "A15"
; Flat shift
flatSSoftWin = scalar, U08, 61, "rpm", 100, 0.0, 100, 25500, 0
@ -723,6 +722,8 @@ page = 10
requiresPowerCycle = iacCLmaxDuty
requiresPowerCycle = boostMinDuty
requiresPowerCycle = boostMaxDuty
requiresPowerCycle = useExtBaro
requiresPowerCycle = baroPin
defaultValue = pinLayout, 1
defaultValue = TrigPattern, 0
@ -1398,7 +1399,7 @@ menuDialog = main
field = "#Baro Sensor"
field = "Use external Baro sensor", useExtBaro
field = "Analog pin to use for ext. Baro sensor", baroPin
field = "Analog pin to use for ext. Baro sensor", baroPin, { useExtBaro }
dialog = boostSettings, "Boost Control"

View File

@ -181,8 +181,9 @@ struct statuses {
uint16_t RPM;
long longRPM;
int mapADC;
int baroADC;
long MAP; //Has to be a long for PID calcs (Boost control)
byte baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running
byte baro; //Barometric pressure is simply the inital MAP reading, taken before the engine is running. Alternatively, can be taken from an external sensor
byte TPS; //The current TPS reading (0% - 100%)
byte TPSlast; //The previous TPS reading
unsigned long TPS_time; //The time the TPS sample was taken
@ -432,7 +433,8 @@ struct config3 {
byte egoRPM; //RPM must be above this for closed loop to function
byte egoTPSMax; //TPS must be below this for closed loop to function
byte vvtPin : 6;
byte unused6_13 : 2;
byte useExtBaro : 1;
byte unused6_13f : 1;
byte boostPin : 6;
byte unused6_14 : 2;
byte voltageCorrectionBins[6]; //X axis bins for voltage correction tables
@ -465,7 +467,7 @@ struct config3 {
byte lnchPullRes : 2;
byte fuelTrimEnabled : 1;
byte flatSEnable : 1;
byte unused60 : 4;
byte baroPin : 4;
byte flatSSoftWin;
byte flatSRetard;
byte flatSArm;
@ -620,6 +622,7 @@ byte pinStepperEnable; //Turning the DRV8825 driver on/off
byte pinLaunch;
byte pinIgnBypass; //The pin used for an ignition bypass (Optional)
byte pinFlex; //Pin with the flex sensor attached
byte pinBaro; //Pin that an external barometric pressure sensor is attached to (If used)
// global variables // from speeduino.ino
extern struct statuses currentStatus; // from speeduino.ino

View File

@ -12,6 +12,7 @@
#define ADCFILTER_O2 128
#define ADCFILTER_BAT 128
#define ADCFILTER_MAP 20 //This is only used on Instantaneous MAP readings and is intentionally very weak to allow for faster response
#define ADCFILTER_BARO 64
#define BARO_MIN 87
#define BARO_MAX 108

View File

@ -202,6 +202,25 @@ void readIAT()
currentStatus.IAT = iatCalibrationTable[currentStatus.iatADC] - CALIBRATION_TEMPERATURE_OFFSET;
}
void readBaro()
{
if ( configPage3.useExtBaro != 0 )
{
int tempReading;
// readings
#if defined(ANALOG_ISR_MAP)
tempReading = AnChannel[pinBaro-A0];
#else
tempReading = analogRead(pinBaro);
tempReading = analogRead(pinBaro);
#endif
currentStatus.baroADC = ADC_FILTER(tempReading, ADCFILTER_BARO, currentStatus.baroADC); //Very weak filter
currentStatus.baro = fastMap1023toX(currentStatus.baroADC, configPage1.mapMax); //Get the current MAP value
}
}
void readO2()
{
unsigned int tempReading;

View File

@ -228,22 +228,31 @@ void setup()
//Lookup the current MAP reading for barometric pressure
readMAP();
/*
* The highest sea-level pressure on Earth occurs in Siberia, where the Siberian High often attains a sea-level pressure above 105 kPa;
* with record highs close to 108.5 kPa.
* The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 87 kPa;
*/
if ((currentStatus.MAP >= BARO_MIN) && (currentStatus.MAP <= BARO_MAX)) //Check if engine isn't running
//barometric reading can be taken from either an external sensor if enabled, or simply by using the initial MAP value
if ( configPage3.useExtBaro != 0 )
{
currentStatus.baro = currentStatus.MAP;
readBaro();
EEPROM.update(EEPROM_LAST_BARO, currentStatus.baro);
}
else
{
//Attempt to use the last known good baro reading from EEPROM
if ((EEPROM.read(EEPROM_LAST_BARO) >= BARO_MIN) && (EEPROM.read(EEPROM_LAST_BARO) <= BARO_MAX)) //Make sure it's not invalid (Possible on first run etc)
{ currentStatus.baro = EEPROM.read(EEPROM_LAST_BARO); } //last baro correction
else { currentStatus.baro = 100; } //Final fall back position.
/*
* The highest sea-level pressure on Earth occurs in Siberia, where the Siberian High often attains a sea-level pressure above 105 kPa;
* with record highs close to 108.5 kPa.
* The lowest measurable sea-level pressure is found at the centers of tropical cyclones and tornadoes, with a record low of 87 kPa;
*/
if ((currentStatus.MAP >= BARO_MIN) && (currentStatus.MAP <= BARO_MAX)) //Check if engine isn't running
{
currentStatus.baro = currentStatus.MAP;
EEPROM.update(EEPROM_LAST_BARO, currentStatus.baro);
}
else
{
//Attempt to use the last known good baro reading from EEPROM
if ((EEPROM.read(EEPROM_LAST_BARO) >= BARO_MIN) && (EEPROM.read(EEPROM_LAST_BARO) <= BARO_MAX)) //Make sure it's not invalid (Possible on first run etc)
{ currentStatus.baro = EEPROM.read(EEPROM_LAST_BARO); } //last baro correction
else { currentStatus.baro = 100; } //Final fall back position.
}
}
//Perform all initialisations
@ -1077,6 +1086,12 @@ void loop()
vvtControl();
idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient.
}
if ((mainLoopCount & 1023) == 1) //Every 1024 loops
{
//Approx. once per second
readBaro();
}
if(configPage4.iacAlgorithm == IAC_ALGORITHM_STEP_OL || configPage4.iacAlgorithm == IAC_ALGORITHM_STEP_CL) { idleControl(); } //Run idlecontrol every loop for stepper idle.
//Always check for sync

View File

@ -452,6 +452,7 @@ void setPinMapping(byte boardID)
if ( (configPage4.fanPin != 0) && (configPage4.fanPin < BOARD_NR_GPIO_PINS) ) { pinFan = configPage4.fanPin; }
if ( (configPage3.boostPin != 0) && (configPage3.boostPin < BOARD_NR_GPIO_PINS) ) { pinBoost = configPage3.boostPin; }
if ( (configPage3.vvtPin != 0) && (configPage3.vvtPin < BOARD_NR_GPIO_PINS) ) { pinVVT_1 = configPage3.vvtPin; }
if ( (configPage3.useExtBaro != 0) ) { pinBaro = configPage3.baroPin + A0; }
//Finally, set the relevant pin modes for outputs
pinMode(pinCoil1, OUTPUT);
@ -510,6 +511,7 @@ void setPinMapping(byte boardID)
pinMode(pinIAT, INPUT_ANALOG);
pinMode(pinCLT, INPUT_ANALOG);
pinMode(pinBat, INPUT_ANALOG);
pinMode(pinBaro, INPUT_ANALOG);
#else
pinMode(pinMAP, INPUT);
pinMode(pinO2, INPUT);
@ -518,6 +520,7 @@ void setPinMapping(byte boardID)
pinMode(pinIAT, INPUT);
pinMode(pinCLT, INPUT);
pinMode(pinBat, INPUT);
pinMode(pinBaro, INPUT);
#endif
pinMode(pinTrigger, INPUT);
pinMode(pinTrigger2, INPUT);