From 3db9dc99fdfc2738049604ccf22c988f0fd13591 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Thu, 27 Jul 2017 12:47:59 +1000 Subject: [PATCH] New MAP calculation method (More accurate and allows negative calibration values) --- reference/speeduino.ini | 2 +- speeduino/globals.h | 7 ++++++- speeduino/maths.ino | 2 ++ speeduino/sensors.ino | 10 ++++++---- speeduino/utils.ino | 2 ++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 58778a7a..12b9f6f2 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -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 diff --git a/speeduino/globals.h b/speeduino/globals.h index bd7ed3dc..1b9f6609 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -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; diff --git a/speeduino/maths.ino b/speeduino/maths.ino index fba41c23..6a1033ec 100644 --- a/speeduino/maths.ino +++ b/speeduino/maths.ino @@ -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 diff --git a/speeduino/sensors.ino b/speeduino/sensors.ino index 96fcec8c..ce41fd0c 100644 --- a/speeduino/sensors.ino +++ b/speeduino/sensors.ino @@ -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 } diff --git a/speeduino/utils.ino b/speeduino/utils.ino index 1cd90aa4..95db98b1 100644 --- a/speeduino/utils.ino +++ b/speeduino/utils.ino @@ -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)