Skip to content

Commit d3efb79

Browse files
MarkusMarkus
Markus
authored and
Markus
committed
accidentally fuelInjection logic
1 parent 96bf6e3 commit d3efb79

File tree

8 files changed

+72
-13
lines changed

8 files changed

+72
-13
lines changed

main/include/maps.h

+19
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,25 @@ static const int oilSensorMap[23][2] PROGMEM {
4343
{ 10000, -10 },
4444
{ 15700, -20 }};
4545

46+
//Fueling map for injectionControl
47+
static const int injectionMap[14][12] PROGMEM {
48+
{999, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, //load & lambda combined
49+
//-----------------------------------------------------------------------
50+
{ 0, 23, 28, 33, 33, 38, 56, 86, 96, 96, 20, 10 },
51+
{ 1000, 23, 28, 33, 33, 38, 56, 86, 96, 96, 20, 10 },
52+
{ 1500, 23, 28, 33, 33, 38, 56, 86, 96, 96, 20, 10 },
53+
{ 2000, 23, 28, 33, 33, 38, 56, 86, 96, 96, 20, 10 },
54+
{ 2500, 20, 25, 30, 30, 35, 53, 83, 93, 93, 20, 10 },
55+
{ 3000, 15, 20, 25, 25, 30, 53, 80, 90, 90, 20, 10 },
56+
{ 3500, 10, 15, 20, 20, 28, 53, 80, 85, 85, 20, 10 },
57+
{ 4000, 10, 15, 20, 20, 28, 53, 80, 85, 85, 20, 10 },
58+
{ 4500, 10, 15, 20, 20, 27, 53, 80, 85, 85, 20, 10 },
59+
{ 5000, 10, 15, 20, 20, 27, 53, 80, 85, 85, 20, 10 },
60+
{ 5500, 9, 15, 20, 20, 27, 53, 80, 85, 85, 20, 10 },
61+
{ 6000, 9, 15, 20, 20, 27, 53, 80, 85, 85, 20, 10 },
62+
{ 6500, 9, 15, 20, 20, 27, 53, 80, 85, 85, 20, 10 }};
63+
//RPM
64+
4665
//Automatic mode autoGear map
4766
static const int gearMap[14][12] PROGMEM {
4867
{255, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, //throttle position %

main/include/pins.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define TEENSY // we're running this on TEENSY
1313

1414

15-
#define y3 16 // FMT3, orange<->brown/red // DOUT3
15+
#define y3 16 // FMT3, orange<->brown/red // DOUT3, I need to use 16 as testing instead of 36.
1616
#define y4 35 // orange <-> brown/grey // DOUT2
1717
#define y5 8 //ex 14, orange <-> brown/black // DOUT1
1818
#define mpc 38 // red <-> brown/pink // DOUT5 // FMT3
@@ -25,6 +25,8 @@
2525
#define hornPin 12 // Horn
2626
#define SPIcs 10
2727
// END OUTPUT PINS
28+
#define injectionPin 36 // should be 16.
29+
2830

2931
// INPUT PINS
3032
// Stick input
@@ -59,3 +61,6 @@
5961
#define batteryPin A21 // car battery monitor
6062
#define refPin A22 // sensor voltage ref ?
6163
//#define refPin A13 // using this in exhaustTempPin for now.
64+
65+
#define exhaustTemperatureCS 9
66+
#define displayCS 10

main/include/sensors.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
struct SensorVals
44
{
5-
int curOilTemp, curExTemp, curBoost, curExPres, curAtfTemp, curRPM, curBoostLim, curEvalGear, curBattery, fuelUsed, fuelUsedAvg;
5+
int curOilTemp, curExTemp, curBoost, curExPres, curAtfTemp, curRPM, curBoostLim, curEvalGear, curBattery, fuelUsed, fuelUsedAvg, curLambda;
66
byte curTps, curLoad, curSpeed;
77
float curSlip, curRatio, curPresDiff;
88
};
@@ -18,6 +18,7 @@ int speedRead();
1818
int tpsRead();
1919
void tpsInit(int action);
2020
int rpmRead();
21+
int lambdaRead();
2122
int boostRead();
2223
int exhaustPressureRead();
2324
int exhaustTempRead();

main/input.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,9 @@ void polltrans(Task *me)
298298
if (tpsSensor)
299299
{
300300
shiftDelay = readPercentualMap(shiftTimeMap, spcPercentVal, sensor.curAtfTemp);
301-
} else {
301+
}
302+
else
303+
{
302304
shiftDelay = 800;
303305
}
304306
shiftDuration = millis() - shiftStartTime;
@@ -551,6 +553,25 @@ int adaptSPC(int mapId, int xVal, int yVal)
551553
return current;
552554
}
553555

556+
void injectionControl(Task *me)
557+
{
558+
struct SensorVals sensor = readSensors();
559+
int fuelRequire = sensor.curLoad / sensor.curLambda; // eg. 100% load / 100% lambda = 1x fueling, 100% load / 10% lambda = 10x fueling
560+
int fuelAmount = readMap(injectionMap, fuelRequire, sensor.curRPM);
561+
fuelAmount = fuelAmount * 2.55;
562+
analogWrite(injectionPin, fuelAmount);
563+
564+
if (debugEnabled)
565+
{
566+
Serial.print("Fueling quantity with load/lambda: ")
567+
Serial.print(sensor.curLoad);
568+
Serial.print("/");
569+
Serial.print(sensor.curLambda);
570+
Serial.print(" is ");
571+
Serial.print(fuelAmount);
572+
}
573+
}
574+
554575
void radioControl()
555576
{
556577
static byte readData;

main/main.ino

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Task pollFuelControl(1000, fuelControl); // 1000ms for fuel pump control
4949
Task pollBoostControl(100, boostControl); // 100ms for boost control*/
5050
Task pollFaultMon(10, faultMon); // 10ms Fault monitor
5151
Task pollSerialWatch(100, serialWatch);
52+
#ifdef ECU
53+
Task pollInjectionControl(100, injectionControl);
54+
#endif
5255

5356
void setup()
5457
{
@@ -192,4 +195,7 @@ void setup()
192195
SoftTimer.add(&pollFuelControl);
193196
SoftTimer.add(&pollBoostControl);
194197
SoftTimer.add(&pollSerialWatch);
198+
#ifdef ECU
199+
SoftTimer.add(&pollInjectionControl);
200+
#endif
195201
}

main/sensors.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ int rpmRead()
286286
return rpmRevs;
287287
}
288288

289+
int lambdaRead() {
290+
// placeholder, most likely analogread if there is enough resolution
291+
292+
return 100;
293+
294+
}
289295
int oilRead()
290296
{
291297
// wip
@@ -482,8 +488,7 @@ int exhaustTempRead()
482488
static double exhaustTemp = 0;
483489
if (exhaustTempSensor)
484490
{
485-
486-
exhaustTemp = kTC.readInternal();
491+
exhaustTemp = kTC.readInternal();
487492
}
488493
return exhaustTemp;
489494
}
@@ -521,5 +526,6 @@ struct SensorVals readSensors()
521526
sensor.curEvalGear = evalGearVal;
522527
sensor.fuelUsed = fuelUsed;
523528
sensor.fuelUsedAvg = fuelUsedAvg;
529+
sensor.curLambda = lambdaRead();
524530
return sensor;
525531
}

main/serial_config.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,23 @@ void initConfig()
148148
for (int i = 0; i < sizeof features / sizeof features[0]; i++)
149149
{
150150
asset = features[i] * 10;
151-
byte configVal = EEPROM.read(asset);
152-
setFeatures(features[i], configVal);
151+
byte featureVal;
152+
EEPROM.get(asset, featureVal);
153+
setFeatures(features[i], featureVal);
153154
}
154155
for (int i = 0; i < sizeof config / sizeof config[0]; i++)
155156
{
156157
asset = config[i] * 10;
157-
int configVal = EEPROM.read(asset);
158+
int configVal;
159+
EEPROM.get(asset, configVal);
158160
setConfig(config[i], configVal);
159161
}
160162
for (int i = 0; i < sizeof configF / sizeof configF[0]; i++)
161163
{
162164
asset = configF[i] * 10;
163-
float configVal;
164-
EEPROM.get(asset, configVal);
165-
setConfigFloat(configF[i], configVal);
165+
float configFVal;
166+
EEPROM.get(asset, configFVal);
167+
setConfigFloat(configF[i], configFVal);
166168
}
167169
}
168170
}

main/ui.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,10 @@ void updateSpeedo()
420420
// Display update
421421
void updateDisplay(Task *me)
422422
{
423-
424423
u8g2.clearBuffer();
425424
draw(wantedGear);
426425
u8g2.sendBuffer();
427-
426+
428427
if (w124rpm)
429428
{
430429
rpmMeterUpdate();

0 commit comments

Comments
 (0)