Considerably better rpmDOT (rpm/s) calculation. Faster and more accurate

This commit is contained in:
Josh Stewart 2017-01-25 11:10:12 +11:00
parent ad825c2051
commit 17cc712326
4 changed files with 18 additions and 6 deletions

View File

@ -152,7 +152,7 @@ struct statuses {
unsigned long TPSlast_time; //The time the previous TPS sample was taken unsigned long TPSlast_time; //The time the previous TPS sample was taken
byte tpsADC; //0-255 byte representation of the TPS byte tpsADC; //0-255 byte representation of the TPS
byte tpsDOT; byte tpsDOT;
int rpmDOT; volatile int rpmDOT;
byte VE; byte VE;
byte O2; byte O2;
byte O2_2; byte O2_2;

View File

@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "math.h" #include "math.h"
#include "corrections.h" #include "corrections.h"
#include "timers.h" #include "timers.h"
//#include "display.h" //#include "display.h"
#include "decoders.h" #include "decoders.h"
#include "idle.h" #include "idle.h"
#include "auxiliaries.h" #include "auxiliaries.h"
@ -806,10 +806,8 @@ void loop()
unsigned long timeToLastTooth = (currentLoopTime - toothLastToothTime); unsigned long timeToLastTooth = (currentLoopTime - toothLastToothTime);
if ( (timeToLastTooth < MAX_STALL_TIME) || (toothLastToothTime > currentLoopTime) ) //Check how long ago the last tooth was seen compared to now. If it was more than half a second ago then the engine is probably stopped. toothLastToothTime can be greater than currentLoopTime if a pulse occurs between getting the lastest time and doing the comparison if ( (timeToLastTooth < MAX_STALL_TIME) || (toothLastToothTime > currentLoopTime) ) //Check how long ago the last tooth was seen compared to now. If it was more than half a second ago then the engine is probably stopped. toothLastToothTime can be greater than currentLoopTime if a pulse occurs between getting the lastest time and doing the comparison
{ {
int lastRPM = currentStatus.RPM; //Need to record this for rpmDOT calculation
currentStatus.RPM = currentStatus.longRPM = getRPM(); //Long RPM is included here currentStatus.RPM = currentStatus.longRPM = getRPM(); //Long RPM is included here
if(fuelPumpOn == false) { digitalWrite(pinFuelPump, HIGH); fuelPumpOn = true; } //Check if the fuel pump is on and turn it on if it isn't. if(fuelPumpOn == false) { digitalWrite(pinFuelPump, HIGH); fuelPumpOn = true; } //Check if the fuel pump is on and turn it on if it isn't.
currentStatus.rpmDOT = ldiv(1000000, (currentLoopTime - previousLoopTime)).quot * (currentStatus.RPM - lastRPM); //This is the RPM per second that the engine has accelerated/decelleratedin the last loop
} }
else else
{ {
@ -846,7 +844,7 @@ void loop()
{ {
readTPS(); readTPS();
//Check for launching (clutch) can be done around here too //Check for launching/flat shift (clutch) can be done around here too
previousClutchTrigger = clutchTrigger; previousClutchTrigger = clutchTrigger;
if(configPage3.launchHiLo) { clutchTrigger = digitalRead(pinLaunch); } if(configPage3.launchHiLo) { clutchTrigger = digitalRead(pinLaunch); }
else { clutchTrigger = !digitalRead(pinLaunch); } else { clutchTrigger = !digitalRead(pinLaunch); }

View File

@ -19,10 +19,12 @@ Hence we will preload the timer with 131 cycles to leave 125 until overflow (1ms
#ifndef TIMERS_H #ifndef TIMERS_H
#define TIMERS_H #define TIMERS_H
volatile int loop100ms;
volatile int loop250ms; volatile int loop250ms;
volatile int loopSec; volatile int loopSec;
volatile unsigned int dwellLimit_uS; volatile unsigned int dwellLimit_uS;
volatile uint16_t lastRPM_100ms; //Need to record this for rpmDOT calculation
#if defined (CORE_TEENSY) #if defined (CORE_TEENSY)
IntervalTimer lowResTimer; IntervalTimer lowResTimer;

View File

@ -40,6 +40,7 @@ void initialiseTimers()
#endif #endif
dwellLimit_uS = (1000 * configPage2.dwellLimit); dwellLimit_uS = (1000 * configPage2.dwellLimit);
lastRPM_100ms = 0;
} }
@ -53,10 +54,11 @@ void oneMSInterval() //Most ARM chips can simply call a function
{ {
//Increment Loop Counters //Increment Loop Counters
loop100ms++;
loop250ms++; loop250ms++;
loopSec++; loopSec++;
unsigned long targetOverdwellTime; unsigned long targetOverdwellTime;
//Overdwell check //Overdwell check
targetOverdwellTime = micros() - dwellLimit_uS; //Set a target time in the past that all coil charging must have begun after. If the coil charge began before this time, it's been running too long targetOverdwellTime = micros() - dwellLimit_uS; //Set a target time in the past that all coil charging must have begun after. If the coil charge began before this time, it's been running too long
@ -67,6 +69,16 @@ unsigned long targetOverdwellTime;
if(ignitionSchedule3.Status == RUNNING) { if(ignitionSchedule3.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil3Charge(); } } if(ignitionSchedule3.Status == RUNNING) { if(ignitionSchedule3.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil3Charge(); } }
if(ignitionSchedule4.Status == RUNNING) { if(ignitionSchedule4.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil4Charge(); } } if(ignitionSchedule4.Status == RUNNING) { if(ignitionSchedule4.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil4Charge(); } }
if(ignitionSchedule5.Status == RUNNING) { if(ignitionSchedule5.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil5Charge(); } } if(ignitionSchedule5.Status == RUNNING) { if(ignitionSchedule5.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil5Charge(); } }
//Loop executed every 100ms loop
//Anything inside this if statement will run every 100ms.
if (loop100ms == 100)
{
loop100ms = 0; //Reset counter
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
}
//Loop executed every 250ms loop (1ms x 250 = 250ms) //Loop executed every 250ms loop (1ms x 250 = 250ms)
//Anything inside this if statement will run every 250ms. //Anything inside this if statement will run every 250ms.