Considerably better rpmDOT (rpm/s) calculation. Faster and more accurate
This commit is contained in:
parent
ad825c2051
commit
17cc712326
|
@ -152,7 +152,7 @@ struct statuses {
|
|||
unsigned long TPSlast_time; //The time the previous TPS sample was taken
|
||||
byte tpsADC; //0-255 byte representation of the TPS
|
||||
byte tpsDOT;
|
||||
int rpmDOT;
|
||||
volatile int rpmDOT;
|
||||
byte VE;
|
||||
byte O2;
|
||||
byte O2_2;
|
||||
|
|
|
@ -31,7 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "math.h"
|
||||
#include "corrections.h"
|
||||
#include "timers.h"
|
||||
//#include "display.h"
|
||||
//#include "display.h"
|
||||
#include "decoders.h"
|
||||
#include "idle.h"
|
||||
#include "auxiliaries.h"
|
||||
|
@ -806,10 +806,8 @@ void loop()
|
|||
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
|
||||
{
|
||||
int lastRPM = currentStatus.RPM; //Need to record this for rpmDOT calculation
|
||||
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.
|
||||
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
|
||||
{
|
||||
|
@ -846,7 +844,7 @@ void loop()
|
|||
{
|
||||
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;
|
||||
if(configPage3.launchHiLo) { clutchTrigger = digitalRead(pinLaunch); }
|
||||
else { clutchTrigger = !digitalRead(pinLaunch); }
|
||||
|
|
2
timers.h
2
timers.h
|
@ -19,10 +19,12 @@ Hence we will preload the timer with 131 cycles to leave 125 until overflow (1ms
|
|||
#ifndef TIMERS_H
|
||||
#define TIMERS_H
|
||||
|
||||
volatile int loop100ms;
|
||||
volatile int loop250ms;
|
||||
volatile int loopSec;
|
||||
|
||||
volatile unsigned int dwellLimit_uS;
|
||||
volatile uint16_t lastRPM_100ms; //Need to record this for rpmDOT calculation
|
||||
|
||||
#if defined (CORE_TEENSY)
|
||||
IntervalTimer lowResTimer;
|
||||
|
|
14
timers.ino
14
timers.ino
|
@ -40,6 +40,7 @@ void initialiseTimers()
|
|||
#endif
|
||||
|
||||
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
|
||||
loop100ms++;
|
||||
loop250ms++;
|
||||
loopSec++;
|
||||
|
||||
unsigned long targetOverdwellTime;
|
||||
unsigned long targetOverdwellTime;
|
||||
|
||||
//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
|
||||
|
@ -67,6 +69,16 @@ unsigned long targetOverdwellTime;
|
|||
if(ignitionSchedule3.Status == RUNNING) { if(ignitionSchedule3.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil3Charge(); } }
|
||||
if(ignitionSchedule4.Status == RUNNING) { if(ignitionSchedule4.startTime < targetOverdwellTime && configPage2.useDwellLim) { endCoil4Charge(); } }
|
||||
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)
|
||||
//Anything inside this if statement will run every 250ms.
|
||||
|
|
Loading…
Reference in New Issue