Add a loops per second benchmarking channel for logging

This commit is contained in:
Josh Stewart 2014-02-18 17:08:55 +11:00
parent f8fe318d43
commit 93b315f4eb
5 changed files with 19 additions and 8 deletions

View File

@ -80,7 +80,8 @@ This function returns the current values of a fixed group of variables
*/
void sendValues(int length)
{
byte response[24];
byte packetSize = 25;
byte response[packetSize];
response[0] = currentStatus.runSecs; //rtc.sec;
response[1] = currentStatus.squirt; //Squirt Bitfield
@ -106,8 +107,9 @@ void sendValues(int length)
response[21] = 0x00; //Will be TPS DOT
response[22] = currentStatus.advance;
response[23] = currentStatus.TPS; // TPS (0% to 100%)
response[24] = currentStatus.loopsPerSecond / 10; // How fast the system is running (Main loops per second divided by 10)
Serial.write(response, (size_t)24);
Serial.write(response, (size_t)packetSize);
Serial.flush();
return;
}

View File

@ -45,6 +45,7 @@ struct statuses {
byte engine;
unsigned long PW; //In uS
byte runSecs;
unsigned int loopsPerSecond;
//Helpful bitwise operations:
//Useful reference: http://playground.arduino.cc/Code/BitMath

View File

@ -718,7 +718,7 @@ help = helpEnrichments, "Enrichments Help"
ochGetCommand = "A"
ochBlockSize = 24
ochBlockSize = 25
secl = scalar, U08, 0, "sec", 1.000, 0.000
squirt = scalar, U08, 1, "bits", 1.000, 0.000
@ -752,6 +752,7 @@ help = helpEnrichments, "Enrichments Help"
TPSdot = scalar, U08, 21, "%/s", 1.000, 0.000
advance = scalar, U08, 22, "deg", 1.000, 0.000
tps = scalar, U08, 23, "%", 1.000, 0.000
loopsPerSecond10 = scalar, U08, 24, "loops", 1.000, 0.000
; Computed output channels. See "megatuneExamples.ini" for all the
; pre-defined variables, search for "???" and you'll see them.
@ -763,6 +764,7 @@ help = helpEnrichments, "Enrichments Help"
mat = { tempCvt(table(matADC, "matfactor.inc")-40) } ; Manifold temperature in user units.
rpm = { rpm100*100 } ; True RPM.
time = { timeNow } ; "timeNow" is a parameterless built-in function.
loopsPerSecond = { loopsPerSecond10*10 } ; True number of mainloops per second
afrtarget = { 0 }
#include "lambdaSensors.ini"

View File

@ -67,7 +67,7 @@ byte coilHIGH = HIGH;
byte coilLOW = LOW;
struct statuses currentStatus;
int loopCount;
int mainLoopCount;
unsigned long secCounter; //The next time to increment 'runSecs' counter.
void setup()
@ -152,7 +152,7 @@ void setup()
cbi(ADCSRA,ADPS0);
#endif
loopCount = 0;
mainLoopCount = 0;
//Setup other relevant pins
pinMode(pinMAP, INPUT);
@ -167,15 +167,14 @@ void setup()
void loop()
{
loopCount++;
mainLoopCount++;
//Check for any requets from serial
if (loopCount == 50) //Only check the serial buffer (And hence process serial commands) once every x loops (50 Is more than fast enough for TunerStudio)
if ((mainLoopCount & 63) == 1) //Only check the serial buffer (And hence process serial commands) once every 64 loops (64 Is more than fast enough for TunerStudio). This function is equivalent to ((loopCount % 64) == 1) but is considerably faster due to not using the mod or division operations
{
if (Serial.available() > 0)
{
command();
}
loopCount = 0;
}
/*

View File

@ -35,12 +35,19 @@ ISR(TIMER2_OVF_vect)
{
loopSec = 0; //Reset counter.
//**************************************************************************************************************************************************
//This updates the runSecs variable
//If the engine is running or cranking, we need ot update the run time counter.
if (((currentStatus.engine & ENGINE_RUN) || (currentStatus.engine & ENGINE_CRANK)))
{ //NOTE - There is a potential for a ~1sec gap between engine crank starting and ths runSec number being incremented. This may delay ASE!
if (currentStatus.runSecs <= 254) //Ensure we cap out at 255 and don't overflow. (which would reset ASE)
{ currentStatus.runSecs++; } //Increment our run counter by 1 second.
}
//**************************************************************************************************************************************************
//This records the number of main loops the system has completed in the last second
currentStatus.loopsPerSecond = mainLoopCount;
mainLoopCount = 0;
//**************************************************************************************************************************************************
//Reset Timer2 to trigger in another ~10ms
TCNT2 = 99; //Preload timer2 with 100 cycles, leaving 156 till overflow.