New MAP calculation method (More accurate and allows negative calibration values)

This commit is contained in:
Josh Stewart 2017-07-27 12:47:59 +10:00
parent b42d0069ab
commit 3db9dc99fd
5 changed files with 17 additions and 6 deletions

View File

@ -226,7 +226,7 @@ page = 2
boostMaxDuty = scalar, U08, 43, "%", 1.0, 0.0, 0.0, 100.0, 0
tpsMin = scalar, U08, 44, "ADC", 1.0, 0.0, 0.0, 255.0, 0
tpsMax = scalar, U08, 45, "ADC", 1.0, 0.0, 0.0, 255.0, 0
mapMin = scalar, U08, 46, "kpa", 1.0, 0.0, 0.0, 255.0, 0
mapMin = scalar, S08, 46, "kpa", 1.0, 0.0, -100, 127.0, 0
mapMax = scalar, U16, 47, "kpa", 1.0, 0.0, 0.0, 25500, 0
fpPrime = scalar, U08, 49, "s", 1.0, 0.0, 0.0, 255.0, 0
stoich = scalar, U08, 50, ":1", 0.1, 0.0, 0.0, 25.5, 1

View File

@ -100,6 +100,9 @@
#define SERIAL_BUFFER_THRESHOLD 32 // When the serial buffer is filled to greater than this threshold value, the serial processing operations will be performed more urgently in order to avoid it overflowing. Serial buffer is 64 bytes long, so the threshold is set at half this as a reasonable figure
#define FUEL_PUMP_ON() *pump_pin_port |= (pump_pin_mask)
#define FUEL_PUMP_OFF() *tach_pin_port &= ~(tach_pin_mask)
const byte signature = 20;
//const char signature[] = "speeduino";
@ -154,6 +157,8 @@ volatile byte ign5_pin_mask;
volatile byte *tach_pin_port;
volatile byte tach_pin_mask;
volatile byte *pump_pin_port;
volatile byte pump_pin_mask;
volatile byte *triggerPri_pin_port;
volatile byte triggerPri_pin_mask;
@ -326,7 +331,7 @@ struct config1 {
byte boostMaxDuty;
byte tpsMin;
byte tpsMax;
byte mapMin;
int8_t mapMin; //Must be signed
uint16_t mapMax;
byte fpPrime; //Time (In seconds) that the fuel pump should be primed for on power up
byte stoich;

View File

@ -19,6 +19,8 @@ int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max)
//int fastMap1023toX(unsigned long x, int in_min, int in_max, int out_min, int out_max)
//removed ununsed variables, in_min and out_min is aways 0, in_max is aways 1023
#define fastMap1023toX(x, out_max) ( ((unsigned long)x * out_max) >> 10)
//This is a new version that allows for out_min
#define fastMap10Bit(x, out_min, out_max) ( ( ((unsigned long)x * (out_max-out_min)) >> 10 ) + out_min)
/*
The following are all fast versions of specific divisions

View File

@ -63,8 +63,8 @@ void instanteneousMAPReading()
currentStatus.mapADC = ADC_FILTER(tempReading, ADCFILTER_MAP, currentStatus.mapADC); //Very weak filter
currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value
currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage1.mapMin, configPage1.mapMax); //Get the current MAP value
if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check
}
@ -108,7 +108,8 @@ void readMAP()
if( (MAPrunningValue != 0) && (MAPcount != 0) )
{
currentStatus.mapADC = ldiv(MAPrunningValue, MAPcount).quot;
currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value
currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage1.mapMin, configPage1.mapMax); //Get the current MAP value
if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check
MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count
MAPrunningValue = 0;
MAPcount = 0;
@ -142,7 +143,8 @@ void readMAP()
{
//Reaching here means that the last cylce has completed and the MAP value should be calculated
currentStatus.mapADC = MAPrunningValue;
currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value
currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage1.mapMin, configPage1.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
}

View File

@ -501,6 +501,8 @@ void setPinMapping(byte boardID)
tach_pin_port = portOutputRegister(digitalPinToPort(pinTachOut));
tach_pin_mask = digitalPinToBitMask(pinTachOut);
pump_pin_port = portOutputRegister(digitalPinToPort(pinFuelPump));
pump_pin_mask = digitalPinToBitMask(pinFuelPump);
//And for inputs
#if defined(CORE_STM32)