From 31e7531128916a4819f6d4a5bcbcd650f9f76637 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Sat, 16 Apr 2022 12:18:58 +1000 Subject: [PATCH] Remove duplicate iacClosedLoopTable. Lookup idle target RPM @ 4Hz after CLT reading --- speeduino/corrections.ino | 2 +- speeduino/idle.h | 1 - speeduino/idle.ino | 29 +---------------------------- speeduino/speeduino.ino | 6 ++++++ 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/speeduino/corrections.ino b/speeduino/corrections.ino index fb25743b..f16e10df 100644 --- a/speeduino/corrections.ino +++ b/speeduino/corrections.ino @@ -824,7 +824,7 @@ int8_t correctionIdleAdvance(int8_t advance) //Adjust the advance based on idle target rpm. if( (configPage2.idleAdvEnabled >= 1) && (runSecsX10 >= (configPage2.idleAdvDelay * 5)) && idleAdvActive) { - currentStatus.CLIdleTarget = (byte)table2D_getValue(&idleTargetTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees + //currentStatus.CLIdleTarget = (byte)table2D_getValue(&idleTargetTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees int idleRPMdelta = (currentStatus.CLIdleTarget - (currentStatus.RPM / 10) ) + 50; // Limit idle rpm delta between -500rpm - 500rpm if(idleRPMdelta > 100) { idleRPMdelta = 100; } diff --git a/speeduino/idle.h b/speeduino/idle.h index 5f25b928..a05dc363 100644 --- a/speeduino/idle.h +++ b/speeduino/idle.h @@ -35,7 +35,6 @@ struct StepperIdle byte moreAirDirection; }; -struct table2D iacClosedLoopTable; struct table2D iacPWMTable; struct table2D iacStepTable; //Open loop tables specifically for cranking diff --git a/speeduino/idle.ino b/speeduino/idle.ino index eb77d765..4d936b2e 100644 --- a/speeduino/idle.ino +++ b/speeduino/idle.ino @@ -92,12 +92,6 @@ void initialiseIdle() iacPWMTable.values = configPage6.iacOLPWMVal; iacPWMTable.axisX = configPage6.iacBins; - iacClosedLoopTable.xSize = 10; - iacClosedLoopTable.valueSize = SIZE_BYTE; - iacClosedLoopTable.axisSize = SIZE_BYTE; - iacClosedLoopTable.values = configPage6.iacCLValues; - iacClosedLoopTable.axisX = configPage6.iacBins; - iacCrankDutyTable.xSize = 4; iacCrankDutyTable.valueSize = SIZE_BYTE; iacCrankDutyTable.axisSize = SIZE_BYTE; @@ -122,12 +116,6 @@ void initialiseIdle() case IAC_ALGORITHM_PWM_CL: //Case 3 is PWM closed loop - iacClosedLoopTable.xSize = 10; - iacClosedLoopTable.valueSize = SIZE_BYTE; - iacClosedLoopTable.axisSize = SIZE_BYTE; - iacClosedLoopTable.values = configPage6.iacCLValues; - iacClosedLoopTable.axisX = configPage6.iacBins; - iacCrankDutyTable.xSize = 4; iacCrankDutyTable.valueSize = SIZE_BYTE; iacCrankDutyTable.axisSize = SIZE_BYTE; @@ -189,12 +177,6 @@ void initialiseIdle() case IAC_ALGORITHM_STEP_CL: //Case 5 is Stepper closed loop - iacClosedLoopTable.xSize = 10; - iacClosedLoopTable.valueSize = SIZE_BYTE; - iacClosedLoopTable.axisSize = SIZE_BYTE; - iacClosedLoopTable.values = configPage6.iacCLValues; - iacClosedLoopTable.axisX = configPage6.iacBins; - iacCrankStepsTable.xSize = 4; iacCrankStepsTable.valueSize = SIZE_BYTE; iacCrankStepsTable.axisSize = SIZE_BYTE; @@ -227,7 +209,7 @@ void initialiseIdle() idlePID.SetTunings(configPage6.idleKP, configPage6.idleKI, configPage6.idleKD); idlePID.SetMode(AUTOMATIC); //Turn PID on configPage6.iacPWMrun = false; // just in case. This needs to be false with stepper idle - idle_pid_target_value = table2D_getValue(&iacClosedLoopTable, (currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET)) * 3; + idle_pid_target_value = currentStatus.CLIdleTarget * 3; idlePID.Initialize(); break; @@ -239,12 +221,6 @@ void initialiseIdle() iacStepTable.values = configPage6.iacOLStepVal; iacStepTable.axisX = configPage6.iacBins; - iacClosedLoopTable.xSize = 10; - iacClosedLoopTable.valueSize = SIZE_BYTE; - iacClosedLoopTable.axisSize = SIZE_BYTE; - iacClosedLoopTable.values = configPage6.iacCLValues; - iacClosedLoopTable.axisX = configPage6.iacBins; - iacCrankStepsTable.xSize = 4; iacCrankStepsTable.valueSize = SIZE_BYTE; iacCrankStepsTable.axisSize = SIZE_BYTE; @@ -526,7 +502,6 @@ void idleControl() } else { - currentStatus.CLIdleTarget = (byte)table2D_getValue(&iacClosedLoopTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees idle_cl_target_rpm = (uint16_t)currentStatus.CLIdleTarget * 10; //Multiply the byte target value back out by 10 if( (idleCounter & 31) == 1) { idlePID.SetTunings(configPage6.idleKP, configPage6.idleKI, configPage6.idleKD); } //This only needs to be run very infrequently, once every 32 calls to idleControl(). This is approx. once per second @@ -567,7 +542,6 @@ void idleControl() //Read the OL table as feedforward term FeedForwardTerm = percentage(table2D_getValue(&iacPWMTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET), idle_pwm_max_count<<2); //All temps are offset by 40 degrees - currentStatus.CLIdleTarget = (byte)table2D_getValue(&iacClosedLoopTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees idle_cl_target_rpm = (uint16_t)currentStatus.CLIdleTarget * 10; //Multiply the byte target value back out by 10 if( (idleCounter & 31) == 1) { idlePID.SetTunings(configPage6.idleKP, configPage6.idleKI, configPage6.idleKD); } //This only needs to be run very infrequently, once every 32 calls to idleControl(). This is approx. once per 9 seconds if((currentStatus.RPM - idle_cl_target_rpm > configPage2.iacRPMlimitHysteresis*10) || (currentStatus.TPS > configPage2.iacTPSlimit)){ //reset integral to zero when TPS is bigger than set value in TS (opening throttle so not idle anymore). OR when RPM higher than Idle Target + RPM Histeresis (comming back from high rpm with throttle closed) @@ -672,7 +646,6 @@ void idleControl() { if( BIT_CHECK(LOOP_TIMER, BIT_TIMER_10HZ) ) { - currentStatus.CLIdleTarget = (byte)table2D_getValue(&iacClosedLoopTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees idle_cl_target_rpm = (uint16_t)currentStatus.CLIdleTarget * 10; //Multiply the byte target value back out by 10 if( idleTaper < configPage2.idleTaperTime ) { diff --git a/speeduino/speeduino.ino b/speeduino/speeduino.ino index 7e413e3a..4cc223df 100644 --- a/speeduino/speeduino.ino +++ b/speeduino/speeduino.ino @@ -333,6 +333,12 @@ void loop() nitrousControl(); idleControl(); //Perform any idle related actions. Even at higher frequencies, running 4x per second is sufficient. + //Lookup the current target idle RPM + if( (configPage2.idleAdvEnabled >= 1) || (configPage6.iacAlgorithm != IAC_ALGORITHM_NONE) ) + { + currentStatus.CLIdleTarget = (byte)table2D_getValue(&idleTargetTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET); //All temps are offset by 40 degrees + } + #ifdef SD_LOGGING if(configPage13.onboard_log_file_rate == LOGGER_RATE_4HZ) { writeSDLogEntry(); } #endif