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]
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
;env_default = teensy35
;env_default = LaunchPad_tm4c1294ncpdt
;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 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

View File

@ -42,6 +42,7 @@ void initialiseADC()
BIT_CLEAR(ADCSRA,ADPS1);
BIT_CLEAR(ADCSRA,ADPS0);
#endif
MAPcurRev = 0;
#endif
}
@ -74,7 +75,7 @@ void readMAP()
case 1:
//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.
{
@ -96,6 +97,10 @@ void readMAP()
else
{
//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.MAP = fastMap1023toX(currentStatus.mapADC, configPage1.mapMax); //Get the current MAP value
MAPcurRev = currentStatus.startRevolutions; //Reset the current rev count
@ -215,4 +220,3 @@ void flexPulse()
{
++flexCounter;
}