Sanity checks on the average MAP calculation

This commit is contained in:
Josh Stewart 2017-02-09 14:17:20 +11:00
parent 74137338e5
commit 7db51bd416
3 changed files with 40 additions and 35 deletions

View File

@ -39,7 +39,8 @@ build_flags = -fpermissive
[platformio] [platformio]
src_dir=speeduino src_dir=speeduino
env_default = megaatmega2560, teensy35 env_default = megaatmega2560
;The following lines are for testing / experimentation only. Comment the line above to try them out ;The following lines are for testing / experimentation only. Comment the line above to try them out
;env_default = teensy35
;env_default = LaunchPad_tm4c1294ncpdt ;env_default = LaunchPad_tm4c1294ncpdt
;env_default = genericSTM32F103RB ;env_default = genericSTM32F103RB

View File

@ -21,7 +21,7 @@ volatile int AnChannel[15];
unsigned long MAPrunningValue; //Used for tracking either the total of all MAP readings in this cycle (Event average) or the lowest value detected in this cycle (event minimum) unsigned long MAPrunningValue; //Used for tracking either the total of all MAP readings in this cycle (Event average) or the lowest value detected in this cycle (event minimum)
unsigned int MAPcount; //Number of samples taken in the current MAP cycle unsigned int MAPcount; //Number of samples taken in the current MAP cycle
byte MAPcurRev = 0; //Tracks which revolution we're sampling on byte MAPcurRev; //Tracks which revolution we're sampling on
/* /*
* Simple low pass IIR filter macro for the analog inputs * Simple low pass IIR filter macro for the analog inputs

View File

@ -42,6 +42,7 @@ void initialiseADC()
BIT_CLEAR(ADCSRA,ADPS1); BIT_CLEAR(ADCSRA,ADPS1);
BIT_CLEAR(ADCSRA,ADPS0); BIT_CLEAR(ADCSRA,ADPS0);
#endif #endif
MAPcurRev = 0;
#endif #endif
} }
@ -74,7 +75,7 @@ void readMAP()
case 1: case 1:
//Average of a cycle //Average of a cycle
if (currentStatus.RPM < 1) { instanteneousMAPReading(); return; } //If the engine isn't running, fall back to instantaneous reads if (currentStatus.RPM < 1 || !currentStatus.hasSync) { instanteneousMAPReading(); return; } //If the engine isn't running, fall back to instantaneous reads
if( (MAPcurRev == currentStatus.startRevolutions) || (MAPcurRev == currentStatus.startRevolutions+1) ) //2 revolutions are looked at for 4 stroke. 2 stroke not currently catered for. if( (MAPcurRev == currentStatus.startRevolutions) || (MAPcurRev == currentStatus.startRevolutions+1) ) //2 revolutions are looked at for 4 stroke. 2 stroke not currently catered for.
{ {
@ -96,6 +97,10 @@ void readMAP()
else else
{ {
//Reaching here means that the last cylce has completed and the MAP value should be calculated //Reaching here means that the last cylce has completed and the MAP value should be calculated
//Sanity check
if (MAPrunningValue == 0 || MAPcount == 0) { instanteneousMAPReading(); return; }
currentStatus.mapADC = ldiv(MAPrunningValue, MAPcount).quot; currentStatus.mapADC = ldiv(MAPrunningValue, MAPcount).quot;
currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value currentStatus.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value
MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count
@ -215,4 +220,3 @@ void flexPulse()
{ {
++flexCounter; ++flexCounter;
} }