Skip to content

Commit

Permalink
Flag an error if an invalid MAP reading is calculated
Browse files Browse the repository at this point in the history
  • Loading branch information
noisymime committed May 22, 2020
1 parent 24260d1 commit 326405a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
6 changes: 6 additions & 0 deletions speeduino/errors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ byte getNextError()
currentError.errorNum = currentErrorNum;
currentError.errorID = errorCodes[currentErrorNum];
}
else
{
currentError.errorNum = 0;
currentError.errorID = 0;
}


return *(byte*)&currentError; //Ugly, but this forces the cast of the currentError struct to a byte.
}
1 change: 1 addition & 0 deletions speeduino/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ byte cltErrorCount = 0;

static inline void instanteneousMAPReading() __attribute__((always_inline));
static inline void readMAP() __attribute__((always_inline));
static inline void validateMAP();
void initialiseADC();
void readTPS(bool=true); //Allows the option to override the use of the filter
void readO2_2();
Expand Down
34 changes: 31 additions & 3 deletions speeduino/sensors.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ A full copy of the license may be found in the projects root directory
#include "storage.h"
#include "comms.h"
#include "idle.h"
#include "errors.h"
#include "corrections.h"

void initialiseADC()
Expand Down Expand Up @@ -119,6 +120,32 @@ void initialiseADC()

}

static inline void validateMAP()
{
//Error checks
if(currentStatus.MAP < VALID_MAP_MIN)
{
currentStatus.MAP = ERR_DEFAULT_MAP_LOW;
mapErrorCount += 1;
setError(ERR_MAP_LOW);
}
else if(currentStatus.MAP > VALID_MAP_MAX)
{
currentStatus.MAP = ERR_DEFAULT_MAP_HIGH;
mapErrorCount += 1;
setError(ERR_MAP_HIGH);
}
else
{
if(errorCount > 0)
{
clearError(ERR_MAP_HIGH);
clearError(ERR_MAP_LOW);
}
mapErrorCount = 0;
}
}

static inline void instanteneousMAPReading()
{
//Update the calculation times and last value. These are used by the MAP based Accel enrich
Expand Down Expand Up @@ -209,7 +236,7 @@ static inline void readMAP()

currentStatus.mapADC = ldiv(MAPrunningValue, MAPcount).quot;
currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage2.mapMin, configPage2.mapMax); //Get the current MAP value
if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check
validateMAP();

//If EMAP is enabled, the process is identical to the above
if(configPage6.useEMAP == true)
Expand Down Expand Up @@ -260,9 +287,10 @@ static inline void readMAP()

currentStatus.mapADC = MAPrunningValue;
currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage2.mapMin, configPage2.mapMax); //Get the current MAP value
if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check
MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count
MAPrunningValue = 1023; //Reset the latest value so the next reading will always be lower

validateMAP();
}
}
else { instanteneousMAPReading(); }
Expand Down Expand Up @@ -303,7 +331,7 @@ static inline void readMAP()

currentStatus.mapADC = ldiv(MAPrunningValue, MAPcount).quot;
currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage2.mapMin, configPage2.mapMax); //Get the current MAP value
if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check
validateMAP();
}
else { instanteneousMAPReading(); }

Expand Down

0 comments on commit 326405a

Please sign in to comment.