diff --git a/speeduino/corrections.ino b/speeduino/corrections.ino index 72765191..0bcd665a 100644 --- a/speeduino/corrections.ino +++ b/speeduino/corrections.ino @@ -605,7 +605,7 @@ byte correctionAFRClosedLoop() if( (currentStatus.runSecs > configPage6.ego_sdelay) || (configPage2.incorporateAFR == true) ) { currentStatus.afrTarget = get3DTableValue(&afrTable, currentStatus.fuelLoad, currentStatus.RPM); } //Perform the target lookup } - if( configPage6.egoType > 0 ) //egoType of 0 means no O2 sensor + if((configPage6.egoType > 0) & (BIT_CHECK(currentStatus.status1, BIT_STATUS1_DFCO) != 1 ) ) //egoType of 0 means no O2 sensor. If DFCO is active do not run the ego controllers to prevent interator wind-up. { AFRValue = currentStatus.egoCorrection; //Need to record this here, just to make sure the correction stays 'on' even if the nextCycle count isn't ready diff --git a/speeduino/src/PID_v1/PID_v1.cpp b/speeduino/src/PID_v1/PID_v1.cpp index 6d5e8270..139d334a 100755 --- a/speeduino/src/PID_v1/PID_v1.cpp +++ b/speeduino/src/PID_v1/PID_v1.cpp @@ -54,21 +54,21 @@ bool PID::Compute() /*Compute all the working error variables*/ long input = *myInput; long error = *mySetpoint - input; - ITerm += (ki * error)/100; + ITerm += (ki * error); if(ITerm > outMax) ITerm= outMax; - else if(ITerm < outMin) ITerm= outMin; + else if(ITerm < outMin) ITerm = outMin; long dInput = (input - lastInput); /*Compute PID Output*/ - long output = (kp * error)/100 + ITerm- (kd * dInput)/100; + long output = (kp * error) + ITerm- (kd * dInput); if(output > outMax) { output = outMax; } else if(output < outMin) { output = outMin; } - *myOutput = output; + *myOutput = output/1000; /*Remember some variables for next time*/ lastInput = input; - //lastTime = now; + lastTime = now; return true; } //else return false; @@ -90,10 +90,10 @@ void PID::SetTunings(byte Kp, byte Ki, byte Kd) ki = Ki * SampleTimeInSec; kd = Kd / SampleTimeInSec; */ - long InverseSampleTimeInSec = 100000 / SampleTime; + long InverseSampleTimeInSec = 100; kp = Kp; - ki = (Ki * 100) / InverseSampleTimeInSec; - kd = (Kd * InverseSampleTimeInSec) / 100; + ki = Ki; + kd = Kd * 10; if(controllerDirection ==REVERSE) { @@ -129,8 +129,8 @@ void PID::SetSampleTime(int NewSampleTime) void PID::SetOutputLimits(long Min, long Max) { if(Min >= Max) return; - outMin = Min; - outMax = Max; + outMin = Min*1000; + outMax = Max*1000; if(inAuto) {