2013-07-08 17:43:41 -07:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
2013-07-18 03:36:36 -07:00
|
|
|
const byte ms_version = 20;
|
2014-02-06 01:48:19 -08:00
|
|
|
const byte signature = 20;
|
|
|
|
const byte data_structure_version = 2; //This identifies the data structure when reading / writing.
|
|
|
|
const byte page_size = 128;
|
2013-07-09 17:26:16 -07:00
|
|
|
|
2013-09-19 03:49:28 -07:00
|
|
|
//Handy bitsetting macros
|
|
|
|
#define BIT_SET(a,b) ((a) |= (1<<(b)))
|
|
|
|
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
|
|
|
|
|
2014-01-29 21:28:21 -08:00
|
|
|
//Define masks for engine
|
|
|
|
#define ENGINE_RUN 1 // Engine running
|
|
|
|
#define ENGINE_CRANK 2 // Engine cranking
|
|
|
|
#define ENGINE_ASE 4 // after start enrichment (ASE)
|
|
|
|
#define ENGINE_WARMUP 8 // Engine in warmup
|
|
|
|
#define ENGINE_TPS 16 // in TPS acceleration mode
|
|
|
|
#define ENGINE_ACC 32 // in deceleration mode
|
|
|
|
#define ENGINE_MAP 64 // in MAP acceleration mode
|
|
|
|
#define ENGINE_IDLE 128 // idle on
|
|
|
|
|
2014-01-30 16:49:50 -08:00
|
|
|
//Define masks for Squirt
|
|
|
|
#define SQUIRT_INJ1 1 //inj1 Squirt
|
|
|
|
#define SQUIRT_INJ2 2 //inj2 Squirt
|
|
|
|
#define SQUIRT_SCHSQRT 4 //Scheduled to squirt
|
|
|
|
#define SQUIRT_SQRTING 8 //Squirting
|
|
|
|
#define SQUIRT_INJ2SCHED 16
|
|
|
|
#define SQUIRT_INJ2SQRT 32 //Injector2 (Schedule2)
|
|
|
|
#define SQUIRT_BOOSTCTRLOFF 64 //Squirting Injector 2
|
2014-01-29 21:28:21 -08:00
|
|
|
|
|
|
|
|
2013-07-09 17:26:16 -07:00
|
|
|
//The status struct contains the current values for all 'live' variables
|
2013-07-16 05:29:17 -07:00
|
|
|
//In current version this is 64 bytes
|
2013-07-09 17:26:16 -07:00
|
|
|
struct statuses {
|
|
|
|
volatile boolean hasSync;
|
|
|
|
unsigned int RPM;
|
|
|
|
byte MAP;
|
2014-02-13 14:27:33 -08:00
|
|
|
byte TPS; //The current TPS reading (0% - 100%)
|
|
|
|
byte TPSlast; //The previous TPS reading
|
|
|
|
byte tpsADC; //0-255 byte representation of the TPS
|
2013-07-09 17:26:16 -07:00
|
|
|
byte VE;
|
2013-09-23 05:23:34 -07:00
|
|
|
byte O2;
|
2013-09-24 21:56:38 -07:00
|
|
|
byte advance;
|
2013-09-17 23:45:53 -07:00
|
|
|
volatile byte squirt;
|
2013-08-25 21:11:47 -07:00
|
|
|
byte engine;
|
2013-07-09 17:26:16 -07:00
|
|
|
unsigned long PW; //In uS
|
2014-01-29 21:28:21 -08:00
|
|
|
byte runSecs;
|
2014-02-18 02:05:13 -08:00
|
|
|
volatile unsigned int loopsPerSecond;
|
2013-07-09 17:26:16 -07:00
|
|
|
|
2013-08-25 21:11:47 -07:00
|
|
|
//Helpful bitwise operations:
|
|
|
|
//Useful reference: http://playground.arduino.cc/Code/BitMath
|
|
|
|
// y = (x >> n) & 1; // n=0..15. stores nth bit of x in y. y becomes 0 or 1.
|
|
|
|
// x &= ~(1 << n); // forces nth bit of x to be 0. all other bits left alone.
|
|
|
|
// x |= (1 << n); // forces nth bit of x to be 1. all other bits left alone.
|
|
|
|
|
2013-07-09 17:26:16 -07:00
|
|
|
};
|
2013-07-16 05:29:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
//Page 1 of the config - See the ini file for further reference
|
|
|
|
//This mostly covers off variables that are required for fuel
|
|
|
|
struct config1 {
|
|
|
|
/*
|
|
|
|
byte engineCylinders; 1 // May support more than 1 cyl later. Always will assume 1 injector per cylinder.
|
|
|
|
byte engineInjectorSize; 80 // In cc/min
|
|
|
|
byte engineStoich; 14.7 // Stoichiometric ratio of fuel used
|
|
|
|
byte engineStrokes; 4 //Can be 2 stroke or 4 stroke, any other value will cause problems
|
|
|
|
byte engineDwell; 3000 //The spark dwell time in uS
|
|
|
|
*/
|
|
|
|
|
2013-07-18 03:36:36 -07:00
|
|
|
byte crankCold; //Cold cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking under a certain temp threshold (ms)
|
|
|
|
byte crankHot; //Warm cranking pulsewidth modifier. This is added to the fuel pulsewidth when cranking (ms)
|
|
|
|
byte asePct; //Afterstart enrichment (%)
|
2013-07-16 20:09:18 -07:00
|
|
|
byte aseCount; //Afterstart enrichment cycles. This is the number of ignition cycles that the afterstart enrichment % lasts for
|
|
|
|
byte wueBins[10]; //Warm up enrichment array (10 bytes)
|
2013-09-15 17:18:33 -07:00
|
|
|
byte taeBins[4]; //TPS based acceleration enrichment bin 1 of 4 (ms)
|
2013-07-16 05:29:17 -07:00
|
|
|
byte taeColdA;
|
|
|
|
byte tpsThresh;
|
|
|
|
byte taeTime;
|
|
|
|
byte tdePct;
|
2013-07-18 00:26:24 -07:00
|
|
|
byte egoTemp; //The temperature at which the EGO / O2 sensor values start being used (Degrees)
|
2013-07-16 05:29:17 -07:00
|
|
|
byte egoCount;
|
|
|
|
byte egoDelta;
|
|
|
|
byte egoLimit;
|
|
|
|
byte reqFuel;
|
|
|
|
byte divider;
|
|
|
|
byte alternate;
|
|
|
|
byte injOpen;
|
|
|
|
byte injOCfuel;
|
|
|
|
byte injPwmP;
|
|
|
|
byte injPwmT;
|
|
|
|
byte battFac; //Whether to compensate pulsewidth for battery voltage (ms/v)
|
2014-02-06 01:48:19 -08:00
|
|
|
int rpmk; //2 bytes
|
|
|
|
//36
|
2013-09-16 00:39:24 -07:00
|
|
|
//config1 in ini
|
2013-09-15 17:18:33 -07:00
|
|
|
byte mapType : 2;
|
|
|
|
byte strokes : 1;
|
|
|
|
byte injType : 1;
|
|
|
|
byte nCylinders : 4; //Number of cylinders
|
2013-09-16 00:39:24 -07:00
|
|
|
|
|
|
|
//config2 in ini
|
2013-09-15 17:18:33 -07:00
|
|
|
byte cltType : 2;
|
|
|
|
byte matType : 2;
|
|
|
|
byte nInjectors : 4; //Number of injectors
|
2013-09-16 00:39:24 -07:00
|
|
|
|
2013-09-15 17:18:33 -07:00
|
|
|
|
2013-09-16 00:39:24 -07:00
|
|
|
//config3 in ini
|
2013-09-15 17:18:33 -07:00
|
|
|
byte engineType : 1;
|
|
|
|
byte egoType : 1;
|
|
|
|
byte algorithm : 1; //"Speed Density", "Alpha-N"
|
|
|
|
byte baroCorr : 1;
|
|
|
|
|
2013-07-16 05:29:17 -07:00
|
|
|
byte primePulse;
|
|
|
|
byte egoRPM;
|
|
|
|
byte fastIdleT; //Fast idle temperature
|
|
|
|
byte egoSwitch;
|
|
|
|
byte taeColdM;
|
2014-02-06 01:48:19 -08:00
|
|
|
byte tpsMin;
|
|
|
|
byte tpsMax;
|
2013-09-15 05:39:55 -07:00
|
|
|
byte unused1;
|
2014-02-06 01:48:19 -08:00
|
|
|
|
|
|
|
//48
|
2013-07-16 05:29:17 -07:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
//Page 2 of the config - See the ini file for further reference
|
|
|
|
//This mostly covers off variables that are required for ignition
|
|
|
|
struct config2 {
|
|
|
|
|
2013-07-16 05:31:01 -07:00
|
|
|
byte triggerAngle;
|
2013-07-16 05:29:17 -07:00
|
|
|
byte FixAng;
|
|
|
|
byte Trim;
|
|
|
|
byte CrankAng;
|
|
|
|
byte IgHold;
|
2013-09-26 04:23:22 -07:00
|
|
|
|
|
|
|
byte Trig_plus : 2;
|
|
|
|
byte TrigCrank : 1;
|
|
|
|
byte IgInv : 1;
|
|
|
|
byte oddfire : 4;
|
|
|
|
|
2013-07-16 05:29:17 -07:00
|
|
|
byte IdleAdv;
|
|
|
|
byte IdleAdvTPS;
|
|
|
|
byte IdleAdvRPM;
|
|
|
|
byte IdleAdvCLT;
|
|
|
|
byte IdleDelayTime;
|
|
|
|
byte StgCycles;
|
2013-07-16 05:31:01 -07:00
|
|
|
byte dwellCont; //Fixed duty dwell control
|
|
|
|
byte dwellCrank;
|
|
|
|
byte dwellRun;
|
2013-07-16 05:29:17 -07:00
|
|
|
byte triggerTeeth; //The full count of teeth on the trigger wheel if there were no gaps
|
|
|
|
byte triggerMissingTeeth; //The size of the tooth gap (ie number of missing teeth)
|
2013-09-19 03:49:28 -07:00
|
|
|
byte crankRPM; //RPM below which the engine is considered to be cranking
|
|
|
|
byte floodClear; //TPS value that triggers flood clear mode (No fuel whilst cranking)
|
2014-01-09 22:17:10 -08:00
|
|
|
byte SoftRevLim; //Soft rev limit (RPM/100)
|
|
|
|
byte SoftLimRetard; //Amount soft limit retards (degrees)
|
|
|
|
byte SoftLimMax; //Time the soft limit can run
|
|
|
|
byte HardRevLim; //Hard rev limit (RPM/100)
|
2014-02-17 02:54:28 -08:00
|
|
|
byte taeBins[4]; //TPS based acceleration enrichment bins (%/s)
|
|
|
|
int taeRates[4]; //TPS based acceleration enrichment rates (% to add)
|
|
|
|
byte unused115;
|
|
|
|
byte unused116;
|
|
|
|
byte unused117;
|
|
|
|
byte unused118;
|
|
|
|
byte unused119;
|
|
|
|
byte unused120;
|
|
|
|
byte unused121;
|
|
|
|
byte unused122;
|
|
|
|
byte unused123;
|
|
|
|
byte unused124;
|
|
|
|
byte unused125;
|
|
|
|
byte unused126;
|
|
|
|
byte unused127;
|
|
|
|
|
2013-07-16 05:29:17 -07:00
|
|
|
|
|
|
|
};
|