diff --git a/comms.ino b/comms.ino index 34599928..62f69d4c 100644 --- a/comms.ino +++ b/comms.ino @@ -201,7 +201,7 @@ void sendValues(int length) response[1] = currentStatus.squirt; //Squirt Bitfield response[2] = currentStatus.engine; //Engine Status Bitfield response[3] = (byte)(divu100(currentStatus.dwell)); //Dwell in ms * 10 - response[4] = currentStatus.MAP; //map + response[4] = (byte)(currentStatus.MAP >> 1); //map value is divided by 2 response[5] = (byte)(currentStatus.IAT + CALIBRATION_TEMPERATURE_OFFSET); //mat response[6] = (byte)(currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //Coolant ADC response[7] = currentStatus.tpsADC; //TPS (Raw 0-255) diff --git a/decoders.h b/decoders.h index fe1d163e..da140441 100644 --- a/decoders.h +++ b/decoders.h @@ -13,6 +13,7 @@ volatile unsigned long toothOneTime = 0; //The time (micros()) that tooth 1 last volatile unsigned long toothOneMinusOneTime = 0; //The 2nd to last time (micros()) that tooth 1 last triggered volatile unsigned int toothHistory[TOOTH_LOG_BUFFER]; volatile unsigned int toothHistoryIndex = 0; +volatile long toothDeltaV; //Represents the change in time taken between the last 2 teeth compared to the previous 2. Positive value represents accleration, negative = deccleration volatile byte secondaryToothCount; //Used for identifying the current secondary (Usually cam) tooth for patterns with multiple secondary teeth volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that the last tooth was registered (Cam input) @@ -20,10 +21,10 @@ volatile unsigned long secondaryLastToothTime = 0; //The time (micros()) that th volatile int triggerActualTeeth; volatile unsigned long triggerFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) unsigned int triggerSecFilterTime; // The shortest time (in uS) that pulses will be accepted (Used for debounce filtering) for the secondary input -unsigned int triggerToothAngle; //The number of crank degrees that elapse per tooth +int triggerToothAngle; //The number of crank degrees that elapse per tooth unsigned long revolutionTime; //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that) -unsigned int toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style +int toothAngles[24]; //An array for storing fixed tooth angles. Currently sized at 24 for the GM 24X decoder, but may grow later if there are other decoders that use this style //Used for identifying long and short pulses on the 4G63 (And possibly other) trigger patterns #define LONG 0; diff --git a/decoders.ino b/decoders.ino index 6c84cc6e..7d9ec04a 100644 --- a/decoders.ino +++ b/decoders.ino @@ -43,6 +43,20 @@ inline int stdGetRPM() return (US_IN_MINUTE / revolutionTime); //Calc RPM based on last full revolution time (Faster as /) } +/* +This is a special case of RPM measure that is based on the time between the last 2 teeth rather than the time of the last full revolution +This gives much more volatile reading, but is quite useful during cranking, particularly on low resolution patterns. +It can only be used on patterns where the teeth are evently spaced +It takes an argument of the full (COMPLETE) number of teeth per revolution. For a missing tooth wheel, this is the number if the tooth had NOT been missing (Eg 36-1 = 36) +*/ +inline int crankingGetRPM(byte totalTeeth) +{ + noInterrupts(); + revolutionTime = (toothLastToothTime - toothLastMinusOneToothTime) * totalTeeth; + interrupts(); + return (US_IN_MINUTE / revolutionTime); +} + /* Name: Missing tooth wheel Desc: A multi-tooth wheel with one of more 'missing' teeth. The first tooth after the missing one is considered number 1 and isthe basis for the trigger angle @@ -82,6 +96,7 @@ void triggerPri_missingTooth() startRevolutions++; //Counter } + toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -139,11 +154,13 @@ void triggerPri_DualWheel() toothOneMinusOneTime = toothOneTime; toothOneTime = curTime; startRevolutions++; //Counter - if ((startRevolutions & 63) == 1) { currentStatus.hasSync = false; } //Every 64 revolutions, force a resync with the cam + currentStatus.hasSync = true; + //if ((startRevolutions & 63) == 1) { currentStatus.hasSync = false; } //Every 64 revolutions, force a resync with the cam } addToothLogEntry(curGap); + toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -183,8 +200,10 @@ int getCrankAngle_DualWheel(int timePerDegree) int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. crankAngle += ( (micros() - tempToothLastToothTime) / timePerDegree); //Estimate the number of degrees travelled since the last tooth - + + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > 360) { crankAngle -= 360; } + if (crankAngle < 0) { crankAngle += 360; } return crankAngle; } @@ -219,14 +238,16 @@ void triggerPri_BasicDistributor() else { toothCurrentCount++; } //Increment the tooth counter addToothLogEntry(curGap); - + + toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime -toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } void triggerSec_BasicDistributor() { return; } //Not required int getRPM_BasicDistributor() { - return stdGetRPM(); + if(currentStatus.RPM < configPage2.crankRPM) { crankingGetRPM((configPage1.nCylinders >> 1)); } + else { return stdGetRPM(); } } int getCrankAngle_BasicDistributor(int timePerDegree) { @@ -241,7 +262,9 @@ int getCrankAngle_BasicDistributor(int timePerDegree) int crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + configPage2.triggerAngle; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > 360) { crankAngle -= 360; } + if (crankAngle < 0) { crankAngle += 360; } return crankAngle; } @@ -280,9 +303,11 @@ void triggerPri_GM7X() toothCurrentCount = 3; currentStatus.hasSync = true; startRevolutions++; //Counter + return; //We return here so that the tooth times below don't get set (The magical 3rd tooth should not be considered for any calculations that use those times) } } + toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -306,7 +331,7 @@ int getCrankAngle_GM7X(int timePerDegree) int crankAngle; if( tempToothCurrentCount < 3 ) { - crankAngle = (tempToothCurrentCount - 1) * 60 + 42; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. + crankAngle = (tempToothCurrentCount - 1) * triggerToothAngle + 42; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. } else if( tempToothCurrentCount == 3 ) { @@ -314,7 +339,7 @@ int getCrankAngle_GM7X(int timePerDegree) } else { - crankAngle = (tempToothCurrentCount - 2) * 60 + 42; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. + crankAngle = (tempToothCurrentCount - 2) * triggerToothAngle + 42; //Number of teeth that have passed since tooth 1, multiplied by the angle each tooth represents, plus the angle that tooth 1 is ATDC. This gives accuracy only to the nearest tooth. } crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth @@ -374,6 +399,7 @@ void triggerPri_4G63() addToothLogEntry(curGap); + toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration toothLastMinusOneToothTime = toothLastToothTime; toothLastToothTime = curTime; } @@ -401,14 +427,12 @@ void triggerSec_4G63() int getRPM_4G63() { - noInterrupts(); - revolutionTime = (toothOneTime - toothOneMinusOneTime); //The time in uS that one revolution would take at current speed (The time tooth 1 was last seen, minus the time it was seen prior to that) - interrupts(); - //triggerFilterTime = revolutionTime >> 5; PROBLEMATIC!!! - return ldiv(US_IN_MINUTE, revolutionTime).quot; //Calc RPM based on last full revolution time (uses ldiv rather than div as US_IN_MINUTE is a long) + if(currentStatus.RPM < configPage2.crankRPM) { crankingGetRPM(2); } + else { return stdGetRPM(); } } -int getCrankAngle_4G63(int timePerDegree) + int getCrankAngle_4G63(int timePerDegree) { + if(!currentStatus.hasSync) { return 0;} //This is the current angle ATDC the engine is at. This is the last known position based on what tooth was last 'seen'. It is only accurate to the resolution of the trigger wheel (Eg 36-1 is 10 degrees) unsigned long tempToothLastToothTime; int tempToothCurrentCount; @@ -420,6 +444,7 @@ int getCrankAngle_4G63(int timePerDegree) int crankAngle = toothAngles[(tempToothCurrentCount - 1)] + configPage2.triggerAngle; //Perform a lookup of the fixed toothAngles array to find what the angle of the last tooth passed was. crankAngle += ldiv( (micros() - tempToothLastToothTime), timePerDegree).quot; //Estimate the number of degrees travelled since the last tooth + if (crankAngle >= 720) { crankAngle -= 720; } if (crankAngle > 360) { crankAngle -= 360; } if (crankAngle < 0) { crankAngle += 360; } @@ -435,7 +460,7 @@ Provided that the cam signal is used, this decoder simply counts the teeth and t */ void triggerSetup_24X() { - triggerToothAngle = 180; //The number of degrees that passes from tooth to tooth (primary) + triggerToothAngle = 15; //The number of degrees that passes from tooth to tooth (primary) toothAngles[0] = 12; toothAngles[1] = 18; toothAngles[2] = 33; @@ -526,7 +551,7 @@ http://speeduino.com/forum/download/file.php?id=205 */ void triggerSetup_Jeep2000() { - triggerToothAngle = 180; //The number of degrees that passes from tooth to tooth (primary) + triggerToothAngle = 0; //The number of degrees that passes from tooth to tooth (primary) toothAngles[0] = 174; toothAngles[1] = 194; toothAngles[2] = 214; @@ -562,9 +587,11 @@ void triggerPri_Jeep2000() toothCurrentCount++; //Increment the tooth counter } - addToothLogEntry(curGap); + addToothLogEntry(curGap); - toothLastToothTime = curTime; + toothDeltaV = (toothLastToothTime - toothLastMinusOneToothTime) - (curTime - toothLastToothTime); //Positive value = accleration, Negative = decceleration + toothLastMinusOneToothTime = toothLastToothTime; + toothLastToothTime = curTime; } void triggerSec_Jeep2000() { diff --git a/reference/Speeduino base tune.msq b/reference/Speeduino base tune.msq index 3861a632..66f5e11b 100644 --- a/reference/Speeduino base tune.msq +++ b/reference/Speeduino base tune.msq @@ -1,7 +1,7 @@ - - + + "0" @@ -17,14 +17,14 @@ 0.0 - 212.0 - 199.0 - 173.0 - 156.0 + 100.0 + 100.0 + 100.0 + 100.0 148.0 145.0 140.0 - 133.0 + 126.0 112.0 100.0 @@ -43,40 +43,40 @@ - 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 - 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 - 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 - 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 39.0 - 39.0 39.0 39.0 39.0 39.0 42.0 44.0 45.0 46.0 47.0 46.0 45.0 44.0 43.0 42.0 41.0 - 39.0 39.0 40.0 46.0 50.0 53.0 54.0 55.0 55.0 56.0 55.0 54.0 52.0 51.0 50.0 48.0 - 39.0 44.0 52.0 57.0 60.0 62.0 64.0 64.0 65.0 65.0 64.0 62.0 61.0 59.0 58.0 56.0 - 40.0 56.0 64.0 68.0 70.0 72.0 73.0 74.0 74.0 74.0 72.0 71.0 69.0 67.0 66.0 64.0 - 53.0 68.0 75.0 78.0 80.0 81.0 82.0 83.0 83.0 83.0 81.0 79.0 77.0 75.0 73.0 72.0 - 66.0 79.0 85.0 88.0 89.0 91.0 91.0 92.0 92.0 92.0 90.0 88.0 86.0 83.0 81.0 79.0 - 79.0 90.0 95.0 97.0 98.0 100.0 100.0 101.0 101.0 100.0 99.0 96.0 94.0 92.0 89.0 87.0 - 91.0 101.0 104.0 106.0 108.0 109.0 109.0 110.0 110.0 109.0 107.0 105.0 102.0 100.0 97.0 95.0 - 113.0 120.0 123.0 125.0 126.0 127.0 127.0 128.0 128.0 127.0 125.0 122.0 119.0 116.0 113.0 110.0 - 123.0 130.0 132.0 134.0 135.0 136.0 136.0 137.0 137.0 136.0 134.0 130.0 127.0 124.0 121.0 118.0 - 134.0 139.0 141.0 143.0 143.0 144.0 145.0 146.0 146.0 145.0 142.0 139.0 135.0 132.0 129.0 126.0 - 143.0 148.0 150.0 151.0 152.0 153.0 154.0 154.0 155.0 154.0 151.0 147.0 144.0 140.0 137.0 133.0 + 23.0 23.0 23.0 24.0 22.0 21.0 19.0 18.0 17.0 15.0 15.0 15.0 15.0 15.0 15.0 15.0 + 24.0 24.0 24.0 25.0 23.0 22.0 20.0 19.0 18.0 16.0 15.0 15.0 15.0 15.0 15.0 15.0 + 24.0 25.0 26.0 27.0 26.0 24.0 23.0 21.0 20.0 18.0 17.0 16.0 15.0 15.0 15.0 15.0 + 26.0 28.0 29.0 30.0 29.0 27.0 26.0 24.0 23.0 21.0 20.0 18.0 17.0 16.0 16.0 16.0 + 27.0 32.0 34.0 36.0 32.0 30.0 29.0 27.0 26.0 24.0 23.0 21.0 20.0 19.0 19.0 19.0 + 31.0 37.0 39.0 39.0 36.0 34.0 32.0 30.0 29.0 27.0 26.0 24.0 23.0 21.0 21.0 22.0 + 35.0 37.0 39.0 39.0 40.0 38.0 36.0 34.0 32.0 31.0 29.0 28.0 26.0 24.0 24.0 24.0 + 41.0 42.0 43.0 42.0 43.0 41.0 40.0 38.0 36.0 34.0 32.0 31.0 29.0 27.0 26.0 27.0 + 45.0 46.0 46.0 46.0 45.0 43.0 41.0 40.0 38.0 36.0 34.0 32.0 31.0 29.0 29.0 29.0 + 45.0 46.0 46.0 46.0 46.0 44.0 42.0 40.0 38.0 36.0 34.0 33.0 31.0 31.0 32.0 32.0 + 45.0 46.0 46.0 46.0 48.0 45.0 43.0 41.0 40.0 38.0 36.0 34.0 33.0 34.0 34.0 34.0 + 45.0 46.0 46.0 46.0 48.0 45.0 43.0 41.0 40.0 38.0 36.0 36.0 36.0 37.0 37.0 37.0 + 50.0 46.0 46.0 46.0 48.0 48.0 45.0 43.0 41.0 40.0 40.0 41.0 41.0 42.0 42.0 42.0 + 50.0 45.0 45.0 46.0 48.0 48.0 47.0 45.0 43.0 43.0 43.0 43.0 44.0 44.0 44.0 44.0 + 50.0 45.0 45.0 46.0 48.0 48.0 48.0 46.0 45.0 45.0 45.0 46.0 46.0 47.0 47.0 47.0 + 60.0 45.0 45.0 46.0 48.0 48.0 48.0 48.0 47.0 48.0 48.0 48.0 48.0 48.0 48.0 48.0 500.0 700.0 900.0 - 1100.0 - 1300.0 - 1600.0 - 1900.0 - 2200.0 - 2500.0 - 3300.0 - 4100.0 - 4900.0 + 1500.0 + 2100.0 + 2900.0 + 3800.0 + 4700.0 + 5500.0 5700.0 + 5900.0 + 6100.0 + 6300.0 6500.0 - 6800.0 - 7000.0 + 6600.0 + 6600.0 15.0 @@ -100,21 +100,21 @@ 5.0 2.0 -4.0 +2.0 50.0 - 212.0 - 199.0 - 173.0 - 156.0 - 148.0 - 145.0 - 140.0 - 133.0 - 112.0 100.0 + 100.0 + 100.0 + 100.0 + 148.0 + 135.0 + 128.0 + 126.0 + 112.0 + 104.0 -20.0 +5.0 "Speeduino v0.4" 0.0 3.2 @@ -129,15 +129,15 @@ "RPM" "RPM" "RPM" -4.3 +13.2 2.0 -"Simultaneous" +"Alternating" 1.0 355.0 355.0 355.0 355.0 -"250 kPa" +"Cycle Average" "Four-stroke" "Port" "4" @@ -149,34 +149,34 @@ "Speed Density" "Off" "Bank" -4.0 +5.0 85.0 4200.0 0.0 0.0 -36.0 -215.0 +43.0 +227.0 10.0 260.0 - 21.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 35.0 36.0 37.0 38.0 38.0 39.0 40.0 - 21.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 35.0 36.0 37.0 38.0 38.0 39.0 40.0 - 21.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 35.0 36.0 37.0 38.0 38.0 39.0 40.0 - 21.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 34.0 36.0 37.0 37.0 37.0 38.0 39.0 - 20.0 23.0 23.0 23.0 24.0 28.0 31.0 32.0 34.0 34.0 36.0 37.0 37.0 37.0 38.0 39.0 - 20.0 23.0 23.0 23.0 24.0 28.0 31.0 32.0 33.0 34.0 35.0 36.0 36.0 36.0 37.0 38.0 - 19.0 20.0 22.0 23.0 24.0 27.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 36.0 37.0 38.0 - 19.0 20.0 21.0 23.0 24.0 26.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 35.0 36.0 37.0 - 19.0 20.0 21.0 23.0 24.0 25.0 28.0 30.0 31.0 32.0 33.0 34.0 34.0 34.0 35.0 35.0 - 19.0 20.0 21.0 23.0 24.0 25.0 28.0 29.0 30.0 31.0 32.0 33.0 33.0 33.0 34.0 34.0 - 19.0 20.0 21.0 23.0 24.0 25.0 28.0 29.0 30.0 31.0 31.0 32.0 32.0 32.0 33.0 33.0 - 19.0 20.0 22.0 23.0 24.0 25.0 28.0 29.0 30.0 30.0 31.0 31.0 31.0 31.0 32.0 32.0 - 19.0 20.0 22.0 23.0 24.0 25.0 28.0 29.0 29.0 29.0 30.0 30.0 30.0 30.0 31.0 31.0 - 20.0 21.0 22.0 23.0 24.0 25.0 28.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 30.0 30.0 - 21.0 22.0 22.0 23.0 24.0 25.0 28.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 - 22.0 22.0 22.0 23.0 24.0 25.0 27.0 28.0 28.0 28.0 28.0 28.0 28.0 28.0 28.0 28.0 + 17.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 35.0 36.0 37.0 38.0 38.0 39.0 40.0 + 17.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 35.0 36.0 37.0 38.0 38.0 39.0 40.0 + 17.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 35.0 36.0 37.0 38.0 38.0 39.0 40.0 + 17.0 22.0 23.0 24.0 25.0 28.0 31.0 33.0 34.0 34.0 36.0 37.0 37.0 37.0 38.0 39.0 + 16.0 15.0 15.0 23.0 24.0 28.0 31.0 32.0 34.0 34.0 36.0 37.0 37.0 37.0 38.0 39.0 + 16.0 15.0 15.0 23.0 24.0 28.0 31.0 32.0 33.0 34.0 35.0 36.0 36.0 36.0 37.0 38.0 + 15.0 20.0 22.0 23.0 24.0 27.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 36.0 37.0 38.0 + 15.0 20.0 21.0 23.0 24.0 26.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 35.0 36.0 37.0 + 15.0 20.0 21.0 23.0 24.0 25.0 28.0 30.0 31.0 32.0 33.0 34.0 34.0 34.0 35.0 35.0 + 15.0 20.0 21.0 23.0 24.0 25.0 28.0 29.0 30.0 31.0 32.0 33.0 33.0 33.0 34.0 34.0 + 15.0 20.0 21.0 23.0 24.0 25.0 28.0 29.0 30.0 31.0 31.0 32.0 32.0 32.0 33.0 33.0 + 15.0 20.0 22.0 23.0 24.0 25.0 28.0 29.0 30.0 30.0 31.0 31.0 31.0 31.0 32.0 32.0 + 15.0 20.0 22.0 23.0 24.0 25.0 28.0 29.0 29.0 29.0 30.0 30.0 30.0 30.0 31.0 31.0 + 16.0 21.0 22.0 23.0 24.0 25.0 28.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 30.0 30.0 + 17.0 22.0 22.0 23.0 24.0 25.0 28.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 29.0 + 18.0 22.0 22.0 23.0 24.0 25.0 27.0 28.0 28.0 28.0 28.0 28.0 28.0 28.0 28.0 28.0 500.0 @@ -216,7 +216,10 @@ -250.0 +25500.0 +25500.0 +25500.0 +0.0 0.0 5.0 10.0 @@ -230,14 +233,15 @@ 3200.0 -20.535 38.0 -3.0 +1.0 "Dwell control" "On" +"Wasted Spark" 6.0 3.0 24.0 1.0 -600.0 +300.0 90.0 7500.0 20.0 @@ -269,13 +273,14 @@ 10.0 - 106.0 - 105.0 + 142.0 + 124.0 + 111.0 100.0 - 100.0 - 91.0 + 93.0 85.0 +25500.0 @@ -334,23 +339,14 @@ -0.0 -0.0 -4000.0 800.0 2300.0 6500.0 3200.0 3500.0 3800.0 -100.0 -24300.0 -4500.0 -3000.0 -6000.0 -100.0 -"PID" -"Disabled" +"No correction" +"Narrow Band" "Off" "Off" 100.0 @@ -369,19 +365,19 @@ 20.0 6.9 - 9.4 - 12.1 + 9.3 + 11.9 13.9 - 16.9 + 16.8 20.3 - 110.0 - 106.0 - 100.0 - 99.0 + 142.0 + 119.0 100.0 100.0 + 98.0 + 90.0 -40.0 @@ -407,10 +403,22 @@ 30.0 300.0 -120.0 +486.0 +"1" +"No" +"No" +0.0 +0.0 +4000.0 +255.0 "One" +19900.0 +10000.0 +2000.0 +0.0 +19800.0 0.0 0.0 @@ -424,64 +432,64 @@ 0.0 - 369.0 - 327.0 - 291.0 - 246.0 - 213.0 - 168.0 - 123.0 - 87.0 - 45.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 0.0 + 0.0 + 7.0 + 11.0 + 16.0 + 19.0 + 24.0 + 29.0 + 34.0 + 38.0 43.0 - 39.0 - 33.0 - 31.0 - 27.0 - 20.0 - 9.0 - 0.0 - 0.0 - 0.0 - -38.0 - -19.0 + 108.0 + 81.0 + 52.0 + 28.0 + 14.0 1.0 - 16.0 - 32.0 - 55.0 - 56.0 - 64.0 - 71.0 - 77.0 + -12.0 + -21.0 + -31.0 + -37.0 - 123.0 - 579.0 - 390.0 - 300.0 + 0.0 + 0.0 + 0.0 + 0.0 27.0 31.0 - 44.0 + 42.0 59.0 - -28.0 - 6.0 - 44.0 - 73.0 + 127.0 + 85.0 + 39.0 + -13.0 "None" -"3" -20.0 -240.0 -4.0 +"1" +-40.0 +0.0 +0.0 "No" "No" "No" @@ -490,73 +498,72 @@ "No" "No" "No" -77.0 -2.0 +-40.0 +-40.0 - 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 - 11.0 10.0 6.0 6.0 6.0 6.0 7.0 7.0 - 24.0 22.0 20.0 18.0 18.0 18.0 19.0 20.0 - 32.0 30.0 29.0 28.0 27.0 27.0 27.0 29.0 - 39.0 39.0 38.0 38.0 37.0 37.0 36.0 36.0 - 46.0 47.0 47.0 46.0 46.0 45.0 45.0 43.0 - 56.0 56.0 56.0 55.0 55.0 55.0 55.0 56.0 - 68.0 68.0 69.0 69.0 69.0 69.0 69.0 69.0 + 23.0 23.0 23.0 24.0 22.0 21.0 19.0 18.0 + 17.0 15.0 15.0 15.0 15.0 15.0 15.0 15.0 + 24.0 24.0 24.0 25.0 23.0 22.0 20.0 19.0 + 18.0 16.0 15.0 15.0 15.0 15.0 15.0 15.0 + 24.0 25.0 26.0 27.0 26.0 24.0 23.0 21.0 + 20.0 18.0 17.0 16.0 15.0 15.0 15.0 15.0 + 26.0 28.0 29.0 30.0 29.0 27.0 26.0 24.0 + 23.0 21.0 20.0 18.0 17.0 16.0 16.0 16.0 - 1000.0 - 2000.0 + 2700.0 + 3300.0 + 3500.0 + 3600.0 + 3200.0 3000.0 - 3800.0 - 4500.0 - 5300.0 - 6000.0 - 6800.0 + 2900.0 + 2700.0 - 0.0 10.0 - 20.0 - 40.0 + 25.0 + 35.0 50.0 - 60.0 + 65.0 80.0 + 90.0 100.0 - 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 - 11.0 10.0 6.0 6.0 6.0 6.0 7.0 7.0 - 24.0 22.0 20.0 18.0 18.0 18.0 19.0 20.0 - 32.0 30.0 29.0 28.0 27.0 27.0 27.0 29.0 - 39.0 39.0 38.0 38.0 37.0 37.0 36.0 36.0 - 46.0 47.0 47.0 46.0 46.0 45.0 45.0 43.0 - 56.0 56.0 56.0 55.0 55.0 55.0 55.0 56.0 - 68.0 68.0 69.0 69.0 69.0 69.0 69.0 69.0 + 31.0 38.0 40.0 39.0 36.0 34.0 32.0 30.0 + 29.0 27.0 26.0 24.0 23.0 21.0 21.0 22.0 + 35.0 38.0 40.0 39.0 40.0 38.0 36.0 34.0 + 32.0 31.0 29.0 28.0 26.0 24.0 24.0 24.0 + 41.0 43.0 44.0 42.0 43.0 41.0 40.0 38.0 + 36.0 34.0 32.0 31.0 29.0 27.0 26.0 27.0 + 45.0 46.0 46.0 46.0 45.0 43.0 41.0 40.0 + 99.0 98.0 99.0 98.0 31.0 29.0 29.0 29.0 - 1000.0 - 2000.0 - 3000.0 - 3800.0 4500.0 - 5300.0 - 6000.0 - 6800.0 + 4600.0 + 4600.0 + 4600.0 + 4600.0 + 4400.0 + 4200.0 + 4000.0 - 0.0 10.0 - 20.0 - 40.0 + 25.0 + 35.0 50.0 - 60.0 + 65.0 80.0 + 90.0 100.0 - diff --git a/speeduino.ino b/speeduino.ino index 903246c3..e2f9d633 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -336,7 +336,7 @@ void setup() if(configPage2.TrigEdge == 0) { attachInterrupt(triggerInterrupt, trigger, RISING); } // Attach the crank trigger wheel interrupt (Hall sensor drags to ground when triggering) else { attachInterrupt(triggerInterrupt, trigger, FALLING); } // Primary trigger connects to - attachInterrupt(triggerInterrupt2, triggerSec_Jeep2000, RISING); + attachInterrupt(triggerInterrupt2, triggerSec_Jeep2000, CHANGE); break; default: @@ -726,7 +726,17 @@ void loop() int tempStartAngle; //How fast are we going? Need to know how long (uS) it will take to get from one tooth to the next. We then use that to estimate how far we are between the last tooth and the next one - timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) + //We use a 1st Deriv accleration prediction, but only when there is an even spacing between primary sensor teeth + //Any decoder that has uneven spacing has its triggerToothAngle set to 0 + if(triggerToothAngle > 0) + { + long toothAccel = toothDeltaV / triggerToothAngle; //An amount represengint the current acceleration or decceleration of the crank in degrees per uS per uS + timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot + (toothAccel * (micros() - toothLastToothTime)); //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) + } + else + { + timePerDegree = ldiv( 166666L, currentStatus.RPM ).quot; //There is a small amount of rounding in this calculation, however it is less than 0.001 of a uS (Faster as ldiv than / ) + } //Check that the duty cycle of the chosen pulsewidth isn't too high. This is disabled at cranking if( !BIT_CHECK(currentStatus.engine, BIT_ENGINE_CRANK) ) @@ -739,9 +749,8 @@ void loop() //*********************************************************************************************** //BEGIN INJECTION TIMING //Determine next firing angles - //1 int PWdivTimerPerDegree = div(currentStatus.PW, timePerDegree).quot; //How many crank degrees the calculated PW will take at the current speed - injector1StartAngle = configPage1.inj1Ang - ( PWdivTimerPerDegree ); //This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. I am using 355 as the point at which the injector MUST be closed by. See http://www.extraefi.co.uk/sequential_fuel.html for more detail + injector1StartAngle = configPage1.inj1Ang - ( PWdivTimerPerDegree ); //This is a little primitive, but is based on the idea that all fuel needs to be delivered before the inlet valve opens. See http://www.extraefi.co.uk/sequential_fuel.html for more detail if(injector1StartAngle < 0) {injector1StartAngle += 360;} //Repeat the above for each cylinder switch (configPage1.nCylinders) @@ -820,7 +829,7 @@ void loop() break; //4 cylinders case 4: - ignition2StartAngle = channel2IgnDegrees + 360 - currentStatus.advance - dwellAngle; //(div((configPage2.dwellRun*100), timePerDegree).quot )); + ignition2StartAngle = channel2IgnDegrees + 360 - currentStatus.advance - dwellAngle; if(ignition2StartAngle > 360) {ignition2StartAngle -= 360;} if(ignition2StartAngle < 0) {ignition2StartAngle += 360;} break; @@ -946,9 +955,13 @@ void loop() crankAngle = getCrankAngle(timePerDegree); //Refresh with the latest crank angle if(ignitionOn && (currentStatus.RPM < ((unsigned int)(configPage2.HardRevLim) * 100) )) { - //if ( (ignition1StartAngle > crankAngle) && ign1LastRev != startRevolutions) if ( (ignition1StartAngle > crankAngle) && ign1LastRev != startRevolutions) + //if (ign1LastRev != startRevolutions) { + unsigned long ignition1StartTime; + if(ignition1StartAngle > crankAngle) { ignition1StartTime = ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree); } + else { ignition1StartTime = ((unsigned long)(360 - crankAngle + ignition1StartAngle) * (unsigned long)timePerDegree); } + setIgnitionSchedule1(ign1StartFunction, ((unsigned long)(ignition1StartAngle - crankAngle) * (unsigned long)timePerDegree), currentStatus.dwell, @@ -961,7 +974,12 @@ void loop() tempStartAngle = ignition2StartAngle - channel2IgnDegrees; if ( tempStartAngle < 0) { tempStartAngle += 360; } if ( (tempStartAngle > tempCrankAngle) && ign2LastRev != startRevolutions) + //if ( ign2LastRev != startRevolutions ) { + unsigned long ignition2StartTime; + if(tempStartAngle > tempCrankAngle) { ignition2StartTime = ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree); } + else { ignition2StartTime = ((unsigned long)(360 - tempCrankAngle + tempStartAngle) * (unsigned long)timePerDegree); } + setIgnitionSchedule2(ign2StartFunction, ((unsigned long)(tempStartAngle - tempCrankAngle) * (unsigned long)timePerDegree), currentStatus.dwell,