From 4f94c98caa4eb04d659d3fa3b17a5ff38dadf7c9 Mon Sep 17 00:00:00 2001 From: Richard Metcalfe Date: Sun, 2 Dec 2018 22:36:41 +0000 Subject: [PATCH] Provide support for changing the idle stepper direction through the use of an "inverted Y/N" setting. This is to avoid the need to change wiring if it turns out the stepper is working in the opposite direction to what is expected. --- reference/speeduino.ini | 12 ++++++++---- speeduino/globals.h | 5 +++-- speeduino/idle.h | 2 ++ speeduino/idle.ino | 40 +++++++++++++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 98088a9f..9ac9615a 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -547,6 +547,7 @@ page = 6 fanPWMBins = array, U08, 124, [4], "F", 1.8, -22.23, -40, 215, 0 #endif + ;-------------------------------------------------- ;Boost and vvt maps (Page 7) ;-------------------------------------------------- @@ -852,7 +853,9 @@ page = 9 ;unused10_150 = scalar, U08, 150, "", 1, 0, 0, 255, 0 ;unused10_151 = scalar, U08, 151, "", 1, 0, 0, 255, 0 ;unused10_152 = scalar, U08, 152, "", 1, 0, 0, 255, 0 - unused10_153 = scalar, U08, 153, "", 1, 0, 0, 255, 0 + ;unused10_153 = scalar, U08, 153, "", 1, 0, 0, 255, 0 + iacStepperInv = bits, U08, 153, [0:0], "No", "Yes" + unused10_154 = scalar, U08, 154, "", 1, 0, 0, 255, 0 unused10_155 = scalar, U08, 155, "", 1, 0, 0, 255, 0 unused10_156 = scalar, U08, 156, "", 1, 0, 0, 255, 0 @@ -1714,6 +1717,7 @@ menuDialog = main field = "Step time (ms)", iacStepTime, { iacAlgorithm == 4 || iacAlgorithm == 5 } field = "Home steps", iacStepHome, { iacAlgorithm == 4 || iacAlgorithm == 5 } field = "Minimum Steps", iacStepHyster, { iacAlgorithm == 4 || iacAlgorithm == 5 } + field = "Stepper Inverted", iacStepperInv, { iacAlgorithm == 4 || iacAlgorithm == 5 } dialog = pwm_idle, "PWM Idle" field = "Number of outputs", iacChannels, { iacAlgorithm == 2 || iacAlgorithm == 3 } @@ -1801,7 +1805,7 @@ menuDialog = main field = "Cranking advance Angle", CrankAng field = "Spark Outputs triggers", IgInv field = "" - field = "Enabled Fixed/Locked timing", fixAngEnable + field = "Enabled Fixed/Locked timing", fixAngEnable field = "Fixed Angle", FixAng, { fixAngEnable } field = "#Note: During cranking the fixed/locked timing angle is overriden by the Cranking advance angle value above" field = "" @@ -1895,8 +1899,8 @@ menuDialog = main field = "Nitrous is armed when pin is", n2o_pin_polarity,{ n2o_enable > 0 } field = "Minimum CLT", n2o_minCLT, { n2o_enable > 0 } field = "Minimum TPS", n2o_minTPS, { n2o_enable > 0 } - field = "Maximum MAP", n2o_maxMAP, { n2o_enable > 0 } - field = "Leanest AFR", n2o_maxAFR, { n2o_enable > 0 } + field = "Maximum MAP", n2o_maxMAP, { n2o_enable > 0 } + field = "Leanest AFR", n2o_maxAFR, { n2o_enable > 0 } dialog = NitrousControl, "Nitrous" panel = NitrousMain, North diff --git a/speeduino/globals.h b/speeduino/globals.h index 27984a1c..8a662b80 100644 --- a/speeduino/globals.h +++ b/speeduino/globals.h @@ -726,8 +726,9 @@ struct config9 { uint16_t obd_address; //speeduino OBD diagnostic address uint8_t Auxinpina[16]; //analog pin number when internal aux in use uint8_t Auxinpinb[16]; // digital pin number when internal aux in use - - byte unused10_152; + + byte iacStepperInv : 1; //stepper direction of travel to allow reversing. 0=normal, 1=inverted. + byte unused10_153; byte unused10_154; byte unused10_155; diff --git a/speeduino/idle.h b/speeduino/idle.h index ffa4f22c..53a89826 100644 --- a/speeduino/idle.h +++ b/speeduino/idle.h @@ -23,6 +23,8 @@ struct StepperIdle int targetIdleStep; //What the targetted step is volatile StepperStatus stepperStatus; volatile unsigned long stepStartTime; //The time the curren + byte lessAirDirection; + byte moreAirDirection; }; #if defined(CORE_AVR) diff --git a/speeduino/idle.ino b/speeduino/idle.ino index 9b66c7af..5ff9dd22 100644 --- a/speeduino/idle.ino +++ b/speeduino/idle.ino @@ -177,6 +177,17 @@ void initialiseIdle() completedHomeSteps = 0; idleStepper.curIdleStep = 0; idleStepper.stepperStatus = SOFF; + if (! configPage9.iacStepperInv) + { + idleStepper.lessAirDirection = STEPPER_BACKWARD; + idleStepper.moreAirDirection = STEPPER_FORWARD; + } + else + { + idleStepper.lessAirDirection = STEPPER_FORWARD; + idleStepper.moreAirDirection = STEPPER_BACKWARD; + } + break; case IAC_ALGORITHM_STEP_CL: @@ -197,6 +208,17 @@ void initialiseIdle() idleStepper.curIdleStep = 0; idleStepper.stepperStatus = SOFF; + if (! configPage9.iacStepperInv) + { + idleStepper.lessAirDirection = STEPPER_BACKWARD; + idleStepper.moreAirDirection = STEPPER_FORWARD; + } + else + { + idleStepper.lessAirDirection = STEPPER_FORWARD; + idleStepper.moreAirDirection = STEPPER_BACKWARD; + } + idlePID.SetOutputLimits(0, (configPage6.iacStepHome * 3)); //Maximum number of steps probably needs its own setting idlePID.SetTunings(configPage6.idleKP, configPage6.idleKI, configPage6.idleKD); idlePID.SetMode(AUTOMATIC); //Turn PID on @@ -348,7 +370,7 @@ static inline byte isStepperHomed() bool isHomed = true; //As it's the most common scenario, default value is true if( completedHomeSteps < (configPage6.iacStepHome * 3) ) //Home steps are divided by 3 from TS { - digitalWrite(pinStepperDir, STEPPER_BACKWARD); //Sets stepper direction to backwards + digitalWrite(pinStepperDir, idleStepper.lessAirDirection); //homing the stepper closes off the air bleed digitalWrite(pinStepperEnable, LOW); //Enable the DRV8825 digitalWrite(pinStepperStep, HIGH); idleStepper.stepStartTime = micros_safe(); @@ -404,8 +426,20 @@ static inline void doStep() { if ( (idleStepper.targetIdleStep <= (idleStepper.curIdleStep - configPage6.iacStepHyster)) || (idleStepper.targetIdleStep >= (idleStepper.curIdleStep + configPage6.iacStepHyster)) ) //Hysteris check { - if(idleStepper.targetIdleStep < idleStepper.curIdleStep) { digitalWrite(pinStepperDir, STEPPER_BACKWARD); idleStepper.curIdleStep--; }//Sets stepper direction to backwards - else if (idleStepper.targetIdleStep > idleStepper.curIdleStep) { digitalWrite(pinStepperDir, STEPPER_FORWARD); idleStepper.curIdleStep++; }//Sets stepper direction to forwards + // the home position for a stepper is pintle fully seated, i.e. no airflow. + if(idleStepper.targetIdleStep < idleStepper.curIdleStep) + { + // we are moving toward the home position (reducing air) + digitalWrite(pinStepperDir, idleStepper.lessAirDirection); + idleStepper.curIdleStep--; + } + else + if (idleStepper.targetIdleStep > idleStepper.curIdleStep) + { + // we are moving away from the home position (adding air). + digitalWrite(pinStepperDir, idleStepper.moreAirDirection); + idleStepper.curIdleStep++; + } digitalWrite(pinStepperEnable, LOW); //Enable the DRV8825 digitalWrite(pinStepperStep, HIGH);