Skip to content

Commit 6db3f6a

Browse files
committed
exhaustpressure sensor support
1 parent 8b4ad17 commit 6db3f6a

File tree

7 files changed

+96
-47
lines changed

7 files changed

+96
-47
lines changed

main/calc.cpp

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#include <Arduino.h>
22
#include <EEPROM.h>
3+
#include "include/pins.h"
34

45
// Macro for sizeof for better support with 2d arrays.
56
#define LEN(arr) ((int)(sizeof(arr) / sizeof(arr)[0]))
67
int lastXval, lastYval;
78
int maxBoostPressure = 700; // Max pressure on boost sensor
89
boolean ShiftDebugEnabled = false;
10+
int initBVoltage = analogRead(boostPin) * 5.0;
11+
int initEVoltage = analogRead(exhaustPresPin) * 5.0;
912

1013
// Calculation helpers
1114

@@ -26,9 +29,17 @@ int readTPSVoltage(int voltage)
2629
int readBoostVoltage(int voltage)
2730
{
2831

29-
int result = map(voltage, 490, 3100, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
32+
int result = map(voltage, initBVoltage, 3100, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
3033
return result;
3134
}
35+
36+
int readExPresVoltage(int voltage)
37+
{
38+
39+
int result = map(voltage, initEVoltage, 5000, 0, 3000); // NXP MPX5700AP (range 0-700kPa)
40+
return result;
41+
}
42+
3243
// Mapping battery voltage to actual voltage
3344
int readBatVoltage(int voltage)
3445
{
@@ -100,6 +111,34 @@ int readTempMap(const int theMap[23][2], int y)
100111
return betweenL1;
101112
}
102113

114+
int readTempMapInverted(const int theMap[14][2], int y)
115+
{
116+
117+
int yidx = 0; // by default near first element
118+
int yelements = 23;
119+
120+
for (int i = 1; i < yelements; i++)
121+
{
122+
int curVal = pgm_read_dword_near(&theMap[i][0]);
123+
124+
if (y <= curVal)
125+
{
126+
yidx = i;
127+
break;
128+
}
129+
}
130+
131+
int curY = pgm_read_dword_near(&theMap[yidx][0]); // valittu Y
132+
int mapValue = pgm_read_dword_near(&theMap[yidx][1]); // valittu X
133+
int prevXMapValue = pgm_read_dword_near(&theMap[yidx - 1][1]); // edellinen X
134+
int prevYMapValue = pgm_read_dword_near(&theMap[yidx - 1][0]); // edellinen Y
135+
136+
float betweenL1 = ((float(curY) - y) / (curY - prevYMapValue)) * (prevXMapValue - mapValue) + mapValue;
137+
// valittu Y - annettu luku = xyz -> (xyz / (valittu Y - edellinen Y)) * (valittu X - edellinen X) + edellinen x
138+
139+
return betweenL1;
140+
}
141+
103142
int readPercentualMap(const int theMap[14][12], int x, int y)
104143
{
105144

main/config.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ boolean adaptive = false;
8181
// Battery monitor
8282
boolean batteryMonitor = true;
8383
// Exhaust pressure sensor
84-
boolean exhaustPresSensor = false;
84+
boolean exhaustPresSensor = true;
8585
// Default power mode
8686
boolean truePower = false;
8787
// torque converter lock

main/include/calc.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
int readTPSVoltage(int voltage);
22
int readBoostVoltage(int voltage);
3+
int readExPresVoltage(int voltage);
34
int readBatVoltage(int voltage);
45
int readMap(const int theMap[14][12], int x, int y);
56
int readTempMap(const int theMap[23][2], int y);
7+
int readTempMapInverted(const int theMap[14][2], int y);
68
int readPercentualMap(const int theMap[14][12], int x, int y);
79
int readGearMap(const int theMap[14][6], int x, int y);
10+
extern int initBVoltage;

main/include/pins.h

+3-8
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,16 @@
3636
// Switches
3737
#define autoSwitch 33 // ex. 22, 0.5kohm <-> yellow <-> grey-pink-grey // DIN5
3838

39-
#ifdef MANUAL
39+
/*#ifdef MANUAL
4040
#define gdownSwitch 23 // ex. 23 <-> NC // DIN6
4141
#define gupSwitch 24 // <-> NC // DIN7
4242
#else
4343
#define fuelInPin 31 // ex. 23 <-> NC // DIN6
4444
#define fuelOutPin 32 // <-> NC // DIN7
45-
#endif
45+
#endif*/
4646

47-
#ifdef ASPC
48-
#define aSpcUpSwitch 32 // ex 18 <-> missing grey? // DIN13
49-
#define aSpcDownSwitch 31 // ex 17 <-> missing grey? // DIN12
50-
#else
51-
#define exhaustPresPin 23
47+
#define exhaustPresPin A9
5248
#define exhaustTempPin 24
53-
#endif
5449

5550
// Car sensor input pins, black
5651
#define tpsPin A3 // voltage div 5/3 <-> black <-> blue-black-blue = 1kohm/1.8kohm div // ANAIN3

main/main.ino

+9-9
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Task pollFaultMon(10, faultMon); // 10ms Fault monitor
5050

5151
void setup()
5252
{
53-
delay(1000);
53+
delay(5000);
5454

5555
// MPC and SPC should have frequency of 1000hz
5656
// TCC should have frequency of 100hz
@@ -115,8 +115,8 @@ void setup()
115115
*portConfigRegister(gupSwitch) = PORT_PCR_MUX(1) | PORT_PCR_PE;
116116
*portConfigRegister(gdownSwitch) = PORT_PCR_MUX(1) | PORT_PCR_PE;
117117
#else*/
118-
pinMode(fuelInPin, INPUT); // Fuel flow meter in
119-
pinMode(fuelOutPin, INPUT); // Fuel flow meter out
118+
// pinMode(fuelInPin, INPUT); // Fuel flow meter in
119+
// pinMode(fuelOutPin, INPUT); // Fuel flow meter out
120120
// *portConfigRegister(fuelInPin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
121121
// *portConfigRegister(fuelOutPin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
122122
//#endif
@@ -135,17 +135,17 @@ void setup()
135135
*portConfigRegister(greenpin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
136136
*portConfigRegister(yellowpin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
137137

138-
#ifdef ASPC
138+
/*#ifdef ASPC
139139
pinMode(aSpcUpSwitch, INPUT);
140140
pinMode(aSpcDownSwitch, INPUT);
141141
*portConfigRegister(aSpcUpSwitch) = PORT_PCR_MUX(1) | PORT_PCR_PE;
142142
*portConfigRegister(aSpcDownSwitch) = PORT_PCR_MUX(1) | PORT_PCR_PE;
143-
#else
143+
#else*/
144144
pinMode(exhaustPresPin, INPUT);
145145
pinMode(exhaustTempPin, INPUT);
146-
*portConfigRegister(exhaustPresPin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
147-
*portConfigRegister(exhaustTempPin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
148-
#endif
146+
// *portConfigRegister(exhaustPresPin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
147+
// *portConfigRegister(exhaustTempPin) = PORT_PCR_MUX(1) | PORT_PCR_PE;
148+
//#endif
149149

150150
// Make sure solenoids are all off.
151151
analogWrite(y3, 255); // 1-2/4-5 Solenoid is pulsed during ignition crank.
@@ -163,7 +163,7 @@ void setup()
163163

164164
digitalWrite(rpmPin, HIGH); // pull-up
165165
digitalWrite(SPIcs, LOW);
166-
166+
167167
attachInterrupt(digitalPinToInterrupt(n2pin), N2SpeedInterrupt, FALLING);
168168
attachInterrupt(digitalPinToInterrupt(n3pin), N3SpeedInterrupt, FALLING);
169169
attachInterrupt(digitalPinToInterrupt(speedPin), vehicleSpeedInterrupt, RISING);

main/sensors.cpp

+32-22
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ void pollsensors(Task *me)
6666
detachInterrupt(rpmPin);
6767
detachInterrupt(speedPin);
6868
//#ifndef MANUAL
69-
detachInterrupt(fuelInPin);
70-
detachInterrupt(fuelOutPin);
69+
// detachInterrupt(fuelInPin);
70+
//detachInterrupt(fuelOutPin);
7171
//#endif
7272
float elapsedTime = millis() - lastSensorTime; // need to have this float in order to get float calculation.
7373

@@ -116,8 +116,8 @@ void pollsensors(Task *me)
116116
rpmPulse = 0;
117117
}
118118

119-
fuelUsed = fuelIn - fuelOut;
120-
fuelUsedAvg = fuelUsedAvg * 5 + fuelUsed / 6;
119+
//fuelUsed = fuelIn - fuelOut;
120+
//fuelUsedAvg = fuelUsedAvg * 5 + fuelUsed / 6;
121121
// fuelIn = 0;
122122
// fuelOut = 0;
123123

@@ -136,8 +136,8 @@ void pollsensors(Task *me)
136136
attachInterrupt(digitalPinToInterrupt(speedPin), vehicleSpeedInterrupt, RISING);
137137
attachInterrupt(digitalPinToInterrupt(rpmPin), rpmInterrupt, RISING);
138138
//#ifndef MANUAL
139-
attachInterrupt(digitalPinToInterrupt(fuelInPin), fuelOutInterrupt, RISING);
140-
attachInterrupt(digitalPinToInterrupt(fuelOutPin), fuelInInterrupt, RISING);
139+
//attachInterrupt(digitalPinToInterrupt(fuelInPin), fuelOutInterrupt, RISING);
140+
//attachInterrupt(digitalPinToInterrupt(fuelOutPin), fuelInInterrupt, RISING);
141141
//#endif
142142
}
143143
}
@@ -302,7 +302,7 @@ a[3] = -9.456539654701360e-07 <- this can be c4
302302
return oilTemp;
303303
*/
304304
//float c1 = 1.689126553357672e-03, c2 = 8.951863613981253e-05, c3 = 2.411208545519697e-05;
305-
float c1 = 1.268318203e-03, c2 = 2.662206632e-04, c3 = 1.217978476e-07;
305+
/* float c1 = 1.268318203e-03, c2 = 2.662206632e-04, c3 = 1.217978476e-07;
306306
float tempRead = analogRead(oilPin);
307307
tempRead = analogRead(oilPin);
308308
float refRead = analogRead(refPin);
@@ -323,17 +323,19 @@ a[3] = -9.456539654701360e-07 <- this can be c4
323323
avgOilTemp = (avgOilTemp * 5 + oilTemp) / 10 +30;
324324
}*/
325325

326-
/*
326+
327327
float tempRead = analogRead(oilPin);
328328
float refRead = analogRead(refPin);
329-
float refTemp = refRead / 1023 * 3.3;
329+
float refTemp = refRead / 1023 * 3.0;
330330
filterOneLowpass2.input(tempRead);
331331

332-
int R2 = 4700 / (1023 / (float)filterOneLowpass.output() - 1.0);
332+
// int R2 = (4700 / (1023 / (float)filterOneLowpass2.output() - 1.0)) + 2050;
333+
int R2 = (4700 / (1023 / tempRead - 1.0)) + 2500;
334+
int oilTemp = readTempMapInverted(oilSensorMap, R2);
333335

334-
*/
336+
335337

336-
return oilTemp;
338+
return tempRead;
337339
}
338340

339341
int boostRead()
@@ -344,9 +346,16 @@ int boostRead()
344346
//reading MAP/boost
345347
float refRead = analogRead(refPin);
346348
float refBoost = refRead / 1023 * 3.3;
347-
float boostVoltage = analogRead(boostPin) * 3.0;
349+
float boostVoltage = analogRead(boostPin) * 5.0;
348350
boostValue = readBoostVoltage(boostVoltage);
349351
avgBoostValue = (avgBoostValue * 5 + boostValue) / 10;
352+
if ( avgBoostValue < 0 ) {
353+
avgBoostValue = 0;
354+
}
355+
else if ( boostValue < -40 )
356+
{
357+
avgBoostValue = 555;
358+
};
350359
}
351360

352361
return avgBoostValue;
@@ -355,16 +364,17 @@ int boostRead()
355364
int exhaustPressureRead()
356365
{
357366
int exhaustPresVal = 0;
367+
float exhaustPresVol = 0;
358368
if (exhaustPresSensor)
359-
{
369+
{
360370
//reading exhaust pressure
361-
float exhaustPresVol = analogRead(exhaustPresPin) * 3.0;
362-
exhaustPresVal = readBoostVoltage(exhaustPresVol);
371+
exhaustPresVol = analogRead(exhaustPresPin) * 5.0;
372+
exhaustPresVal = readExPresVoltage(exhaustPresVol);
363373
avgExhaustPresVal = (avgExhaustPresVal * 5 + exhaustPresVal) / 10;
364-
if (avgExhaustPresVal < 0)
374+
/*if (avgExhaustPresVal < 0)
365375
{
366376
avgExhaustPresVal = 0;
367-
}
377+
}*/
368378
}
369379

370380
return avgExhaustPresVal;
@@ -440,7 +450,7 @@ int atfRead()
440450
float refTemp = refRead / 1023 * 3.3;
441451
filterOneLowpass.input(tempRead);
442452

443-
int R2 = 230 / (refTemp / (float)filterOneLowpass.output() - 1.0);
453+
int R2 = 230 / (1023 / tempRead - 1.0) +300;
444454

445455
if (R2 < 564)
446456
{
@@ -458,8 +468,8 @@ int atfRead()
458468
{
459469
atfTemp = oilRead();
460470
}
461-
atfTemp = atfTemp;
462-
return atfTemp;
471+
atfTemp = atfTemp + 40;
472+
return tempRead;
463473
}
464474

465475
int exhaustTempRead()
@@ -495,7 +505,7 @@ struct SensorVals readSensors()
495505
sensor.curExTemp = exhaustTempRead();
496506
sensor.curBoost = boostRead();
497507
sensor.curExPres = exhaustPressureRead();
498-
sensor.curPresDiff = sensor.curExPres / sensor.curBoost;
508+
sensor.curPresDiff = sensor.curBoost / sensor.curExPres;
499509
sensor.curBoostLim = boostLimitRead(sensor.curOilTemp);
500510
sensor.curTps = tpsRead();
501511
sensor.curRPM = rpmRead();

main/ui.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void draw(int wantedGear)
227227
}
228228
else if (page == 2 && infoDisplay == 0)
229229
{
230-
float boostBar;
230+
/*float boostBar;
231231
u8g2.drawFrame(5, 8, 115, 24);
232232
if (sensor.curBoostLim > 0)
233233
{
@@ -238,19 +238,21 @@ void draw(int wantedGear)
238238
boostBar = sensor.curBoost / config.boostSpring;
239239
}
240240
float boostBox = 100 * boostBar * 115;
241-
u8g2.drawBox(5, 8, boostBox, 24);
241+
u8g2.drawBox(5, 8, boostBox, 24);*/
242242
u8g2.setFont(u8g2_font_fub14_tf);
243243
u8g2.setCursor(20, 28);
244244
u8g2.print(sensor.curBoost);
245-
u8g2.setCursor(60, 28);
245+
u8g2.setCursor(50, 28);
246246
u8g2.print(F(" / "));
247247
u8g2.setCursor(90, 28);
248-
u8g2.print(sensor.curBoostLim);
249-
if (sensor.curBoostLim < 1)
248+
u8g2.print(sensor.curExPres);
249+
u8g2.setCursor(50, 56);
250+
u8g2.print(sensor.curPresDiff);
251+
/* if (sensor.curBoostLim < 1)
250252
{
251253
u8g2.setCursor(10, 56);
252254
u8g2.print(F("LOW TEMP"));
253-
}
255+
}*/
254256
}
255257
else if (page == 3 && infoDisplay == 0)
256258
{

0 commit comments

Comments
 (0)