Skip to content

Commit ed37e3d

Browse files
committed
atf sensor smoothing
1 parent 0ae5af5 commit ed37e3d

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

main/config.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ int n3Speed = 0;
6262
extern unsigned int __bss_end;
6363
extern unsigned int __heap_start;
6464
extern void *__brkval;
65-
const int atfReadNum = 10;
66-
int atfReadVal[atfReadNum];
65+
const int atfSensorFilterWeight = 16; // higher numbers = heavier filtering
66+
const int atfSensorNumReadings = 10; // number of readings
67+
int atfSensorAverage = 0; // the running average
6768

6869
// End of internals
6970

main/core.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void decideGear(int wantedGear) {
124124
int atfTemp = atfRead();
125125
int tpsPercentValue = tpsRead();
126126
// Determine speed related downshift and upshift here.
127-
int autoGear = ReadMap(gearMap,tpsPercentValue, vehicleSpeed);
127+
int autoGear = readMap(gearMap,tpsPercentValue, vehicleSpeed);
128128

129129
if ( ! shiftBlocker && wantedGear < 6 ) {
130130
if ( (fullAuto && autoGear > gear && wantedGear > gear) || (! fullAuto && wantedGear > gear && autoGear > gear) ) {

main/main.ino

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ void setup() {
5959
analogWrite(spc,0); // No pressure here by default.
6060
analogWrite(mpc,255); // We want constant pressure here.
6161
analogWrite(tcc,0); // No pressure here by default.
62-
for (int atfNum = 0; atfNum < atfReadNum; atfNum++) { atfReadVal[atfNum]; }
6362
Serial.println("Started.");
6463
updateDisplay();
6564
}

main/sensors.h

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
23
int tpsRead() {
34
int tpsPercentValue = 0;
45
if ( tpsSensor ) {
@@ -102,25 +103,23 @@ int loadRead() {
102103
}
103104
//reading oil temp sensor / pn-switch (same input pin, see page 27: http://www.all-trans.by/assets/site/files/mercedes/722.6.1.pdf)
104105
int atfRead() {
105-
int readIndex = 0;
106-
int total = 0;
107-
int average = 0;
108106
int atfTempCalculated = 0;
109107
int atfTempRaw = analogRead(atfPin);
110108
int atfTemp = 0;
109+
int sensorReading = 0;
110+
int i = 0;
111111

112112
if (atfTempRaw > 1015 ) { drive = false; atfTempCalculated = 9999; atfTemp = 0; }
113113
else { drive = true;
114-
total = total - atfReadVal[readIndex];
115114
atfTempCalculated = (0.0309*atfTempRaw * atfTempRaw) - 44.544*atfTempRaw + 16629;
116115
atfTemp = -0.000033059* atfTempCalculated * atfTempCalculated + 0.2031 * atfTempCalculated - 144.09; //same as above
117-
atfReadVal[readIndex] = atfTemp;
118-
total = total + atfReadVal[readIndex];
119-
readIndex = readIndex + 1;
120-
if (readIndex >= atfReadNum) { readIndex = 0; }
121-
average = total / atfReadNum;
116+
if ( i < atfSensorNumReadings ) {
117+
sensorReading = atfTemp;
118+
atfSensorAverage = atfSensorAverage + (sensorReading - atfSensorAverage) / atfSensorFilterWeight;
119+
i++;
120+
}
122121
}
123-
return average;
122+
return atfSensorAverage;
124123
}
125124

126125
int oilRead() {

0 commit comments

Comments
 (0)