From 7c15b2657c6c6bf1cf151aedb4ecb6680f72f13a Mon Sep 17 00:00:00 2001 From: VitorBoss Date: Fri, 4 Aug 2017 16:12:16 -0300 Subject: [PATCH] Fix last merge --- speeduino/comms.ino | 4 ++-- speeduino/decoders.ino | 39 ++++++++++++++++++++++++++++----------- speeduino/sensors.h | 4 ++-- speeduino/sensors.ino | 7 +++++-- speeduino/timers.ino | 2 -- speeduino/updates.ino | 20 +++++++++++++++++++- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/speeduino/comms.ino b/speeduino/comms.ino index 04d82ed2..bcee111d 100644 --- a/speeduino/comms.ino +++ b/speeduino/comms.ino @@ -80,12 +80,12 @@ void command() break; case 'S': // send code version - Serial.print("Speeduino 2017.07-dev"); + Serial.print("Speeduino 2017.07"); currentStatus.secl = 0; //This is required in TS3 due to its stricter timings break; case 'Q': // send code version - Serial.print("speeduino 201707-dev"); + Serial.print("speeduino 201707"); break; case 'V': // send VE table and constants in binary diff --git a/speeduino/decoders.ino b/speeduino/decoders.ino index ad683954..07713590 100644 --- a/speeduino/decoders.ino +++ b/speeduino/decoders.ino @@ -88,14 +88,18 @@ It takes an argument of the full (COMPLETE) number of teeth per revolution. For static inline int crankingGetRPM(byte totalTeeth) { uint16_t tempRPM = 0; - if( (toothLastToothTime > 0) && (toothLastMinusOneToothTime > 0) ) + if( currentStatus.startRevolutions >= 2 ) { - noInterrupts(); - revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth; - interrupts(); - tempRPM = (US_IN_MINUTE / revolutionTime); - if( tempRPM >= MAX_RPM ) { tempRPM = currentStatus.RPM; } //Sanity check. This can prevent spiking caused by noise on individual teeth. The new RPM should never be above 4x the cranking setting value (Remembering that this function is only called is the current RPM is less than the cranking setting) + if( (toothLastToothTime > 0) && (toothLastMinusOneToothTime > 0) ) + { + noInterrupts(); + revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth; + interrupts(); + tempRPM = (US_IN_MINUTE / revolutionTime); + if( tempRPM >= MAX_RPM ) { tempRPM = currentStatus.RPM; } //Sanity check. This can prevent spiking caused by noise on individual teeth. The new RPM should never be above 4x the cranking setting value (Remembering that this function is only called is the current RPM is less than the cranking setting) + } } + return tempRPM; } @@ -152,6 +156,8 @@ void triggerPri_missingTooth() if ( (curGap > targetGap) || (toothCurrentCount > triggerActualTeeth) ) { if(toothCurrentCount < (triggerActualTeeth) && (currentStatus.hasSync == true) ) { currentStatus.hasSync = false; } //This occurs when we're at tooth #1, but haven't seen all the other teeth. This indicates a signal issue so we flag lost sync so this will attempt to resync on the next revolution. + //This is to handle a special case on startup where sync can be obtained and the system immediately thinks the revs have jumped: + //else if (currentStatus.hasSync == false && toothCurrentCount < checkSyncToothCount ) { triggerFilterTime = 0; } else { toothCurrentCount = 1; @@ -804,7 +810,7 @@ uint16_t getRPM_4G63() //Because these signals aren't even (Alternating 110 and 70 degrees), this needs a special function if(currentStatus.hasSync == true) { - if( currentStatus.RPM < (unsigned int)(configPage2.crankRPM * 100) ) + if( currentStatus.RPM < ((unsigned int)configPage2.crankRPM * 100) ) { int tempToothAngle; unsigned long toothTime; @@ -817,6 +823,8 @@ uint16_t getRPM_4G63() interrupts(); toothTime = toothTime * 36; tempRPM = ((unsigned long)tempToothAngle * 6000000UL) / toothTime; + revolutionTime = (10UL * toothTime) / tempToothAngle; + } } else { tempRPM = stdGetRPM(); } @@ -1090,7 +1098,7 @@ void triggerPri_Audi135() { curTime = micros(); curGap = curTime - toothSystemLastToothTime; - if ( curGap > triggerFilterTime ) + if ( (curGap > triggerFilterTime) || (currentStatus.startRevolutions == 0) ) { toothSystemCount++; @@ -1859,7 +1867,7 @@ void triggerPri_Subaru67() toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; - if ( (currentStatus.hasSync == false) || configPage2.useResync) + if ( (currentStatus.hasSync == false) || configPage2.useResync || (currentStatus.startRevolutions == 0) ) { //Sync is determined by counting the number of cam teeth that have passed between the crank teeth switch(secondaryToothCount) @@ -1929,7 +1937,15 @@ void triggerSec_Subaru67() uint16_t getRPM_Subaru67() { //if(currentStatus.RPM < configPage2.crankRPM) { return crankingGetRPM(configPage2.triggerTeeth); } - return stdGetRPM(); + + uint16_t tempRPM = 0; + if(currentStatus.startRevolutions > 0) + { + //As the tooth count is over 720 degrees, we need to double the RPM value and halve the revolution time + tempRPM = stdGetRPM() << 1; + revolutionTime = revolutionTime >> 1; //Revolution time has to be divided by 2 as otherwise it would be over 720 degrees (triggerActualTeeth = nCylinders) + } + return tempRPM; } int getCrankAngle_Subaru67(int timePerDegree) @@ -2005,7 +2021,7 @@ void triggerPri_Daihatsu() curTime = micros(); curGap = curTime - toothLastToothTime; - //if ( curGap >= triggerFilterTime ) + //if ( curGap >= triggerFilterTime || (currentStatus.startRevolutions == 0 ) { toothSystemCount++; @@ -2127,3 +2143,4 @@ void triggerSetEndTeeth_Daihatsu() { } + diff --git a/speeduino/sensors.h b/speeduino/sensors.h index c8294a2f..24245d04 100644 --- a/speeduino/sensors.h +++ b/speeduino/sensors.h @@ -39,7 +39,6 @@ byte MAPcurRev; //Tracks which revolution we're sampling on void instanteneousMAPReading(); void readMAP(); -void readBaro(); void flexPulse(); #if defined(ANALOG_ISR) @@ -105,4 +104,5 @@ ISR(ADC_vect) } #endif -#endif // SENSORS_H +#endif // SENSORS_H + diff --git a/speeduino/sensors.ino b/speeduino/sensors.ino index ce41fd0c..7aedbb08 100644 --- a/speeduino/sensors.ino +++ b/speeduino/sensors.ino @@ -61,7 +61,9 @@ void instanteneousMAPReading() if( (tempReading >= VALID_MAP_MAX) || (tempReading <= VALID_MAP_MIN) ) { mapErrorCount += 1; } else { mapErrorCount = 0; } - currentStatus.mapADC = ADC_FILTER(tempReading, ADCFILTER_MAP, currentStatus.mapADC); //Very weak filter + //During startup a call is made here to get the baro reading. In this case, we can't apply the ADC filter + if(initialisationComplete == true) { currentStatus.mapADC = ADC_FILTER(tempReading, ADCFILTER_MAP, currentStatus.mapADC); } //Very weak filter + else { currentStatus.mapADC = tempReading; } //Baro reading (No filter) currentStatus.MAP = fastMap10Bit(currentStatus.mapADC, configPage1.mapMin, configPage1.mapMax); //Get the current MAP value if(currentStatus.MAP < 0) { currentStatus.MAP = 0; } //Sanity check @@ -219,7 +221,7 @@ void readBaro() currentStatus.baroADC = ADC_FILTER(tempReading, ADCFILTER_BARO, currentStatus.baroADC); //Very weak filter - currentStatus.baro = fastMap1023toX(currentStatus.baroADC, configPage1.mapMax); //Get the current MAP value + currentStatus.baro = fastMap10Bit(currentStatus.baroADC, configPage1.mapMin, configPage1.mapMax); //Get the current MAP value } } @@ -262,3 +264,4 @@ void flexPulse() { ++flexCounter; } + diff --git a/speeduino/timers.ino b/speeduino/timers.ino index fd3f8225..76095a7e 100644 --- a/speeduino/timers.ino +++ b/speeduino/timers.ino @@ -47,7 +47,6 @@ void initialiseTimers() Timer4.resume(); //Start Timer #endif - pinMode(LED_BUILTIN, OUTPUT); //pinMode(13, OUTPUT); dwellLimit_uS = (1000 * configPage2.dwellLimit); lastRPM_100ms = 0; } @@ -101,7 +100,6 @@ void oneMSInterval() //Most ARM chips can simply call a function { loop100ms = 0; //Reset counter BIT_SET(TIMER_mask, BIT_TIMER_10HZ); - digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); currentStatus.rpmDOT = (currentStatus.RPM - lastRPM_100ms) * 10; //This is the RPM per second that the engine has accelerated/decelleratedin the last loop lastRPM_100ms = currentStatus.RPM; //Record the current RPM for next calc diff --git a/speeduino/updates.ino b/speeduino/updates.ino index 96ddee79..a184b99e 100644 --- a/speeduino/updates.ino +++ b/speeduino/updates.ino @@ -8,7 +8,7 @@ void doUpdates() { - #define CURRENT_DATA_VERSION 4 + #define CURRENT_DATA_VERSION 5 //May 2017 firmware introduced a -40 offset on the ignition table. Update that table to +40 if(EEPROM.read(EEPROM_DATA_VERSION) == 2) @@ -36,6 +36,23 @@ void doUpdates() writeConfig(); EEPROM.write(EEPROM_DATA_VERSION, 4); } + //July 2017 adds a cranking enrichment curve in place of the single value. This converts that single value to the curve + if(EEPROM.read(EEPROM_DATA_VERSION) == 4) + { + //Some default values for the bins (Doesn't matter too much here as the values against them will all be identical) + configPage11.crankingEnrichBins[0] = 0; + configPage11.crankingEnrichBins[1] = 40; + configPage11.crankingEnrichBins[2] = 70; + configPage11.crankingEnrichBins[3] = 100; + + configPage11.crankingEnrichValues[0] = 100 + configPage1.crankingPct; + configPage11.crankingEnrichValues[1] = 100 + configPage1.crankingPct; + configPage11.crankingEnrichValues[2] = 100 + configPage1.crankingPct; + configPage11.crankingEnrichValues[3] = 100 + configPage1.crankingPct; + + writeConfig(); + EEPROM.write(EEPROM_DATA_VERSION, 5); + } //Final check is always for 255 and 0 (Brand new arduino) if( (EEPROM.read(EEPROM_DATA_VERSION) == 0) || (EEPROM.read(EEPROM_DATA_VERSION) == 255) ) @@ -45,3 +62,4 @@ void doUpdates() } } +