Many small updates to the idle system (Including additional logging)

This commit is contained in:
Josh Stewart 2017-03-20 22:29:42 +11:00
parent c28547dc3a
commit 880947746f
6 changed files with 47 additions and 19 deletions

View File

@ -36,9 +36,11 @@
; name = type, min, max; ; name = type, min, max;
; ;
; type List: value will be index. ; type List: value will be index.
rpmhigh = scalar, U16, "rpm", 1, 0, 0, 30000, 0 rpmhigh = scalar, U16, "rpm", 1, 0, 0, 30000, 0
rpmwarn = scalar, U16, "rpm", 1, 0, 0, 30000, 0 rpmwarn = scalar, U16, "rpm", 1, 0, 0, 30000, 0
rpmdang = scalar, U16, "rpm", 1, 0, 0, 30000, 0 rpmdang = scalar, U16, "rpm", 1, 0, 0, 30000, 0
idleUnits = bits, U08, [0:2], "None", "On/Off", "Duty Cycle", "Duty Cycle", "Steps", "Steps"
[Constants] [Constants]
@ -1774,6 +1776,7 @@ menuDialog = main
currentError = bits, U08, 36, [2:7] currentError = bits, U08, 36, [2:7]
boostTarget = scalar, U08, 37, "kPa", 2.000, 0.000 boostTarget = scalar, U08, 37, "kPa", 2.000, 0.000
boostDuty = scalar, U08, 38, "%", 1.000, 0.000 boostDuty = scalar, U08, 38, "%", 1.000, 0.000
idleLoad = scalar, U08, 39, { bitStringValue( idleUnits , iacAlgorithm ) }, 2.000, 0.000 ; This is a combined variable covering both PWM and stepper IACs. The units used depend on which idle algorithm is chosen
; Computed output channels. See "megatuneExamples.ini" for all the ; Computed output channels. See "megatuneExamples.ini" for all the
; pre-defined variables, search for "???" and you'll see them. ; pre-defined variables, search for "???" and you'll see them.
@ -1885,8 +1888,9 @@ menuDialog = main
entry = errorNum, "Error #", int, "%d" entry = errorNum, "Error #", int, "%d"
entry = currentError, "Error ID", int, "%d" entry = currentError, "Error ID", int, "%d"
entry = boostTarget, "Boost Target",int, "%d", { boostEnabled } entry = boostTarget, "Boost Target",int, "%d", { boostEnabled }
entry = boostDuty, "Boost Duty" ,int, "%d", { boostEnabled } entry = boostDuty, "Boost Duty", int, "%d", { boostEnabled }
entry = boostCutOut , "Boost cut", ,int, "%d" entry = boostCutOut , "Boost cut", int, "%d"
entry = idleLoad, "IAC value", int, "%d"
; Indicators ; Indicators

View File

@ -12,7 +12,7 @@
#define seqFuelPage 9 #define seqFuelPage 9
#define canbusPage 10//Config Page 10 #define canbusPage 10//Config Page 10
#define packetSize 39 #define packetSize 40
byte currentPage = 1;//Not the same as the speeduino config page numbers byte currentPage = 1;//Not the same as the speeduino config page numbers
boolean isMap = true; boolean isMap = true;

View File

@ -263,6 +263,7 @@ void sendValues(int packetlength, byte portNum)
response[36] = getNextError(); response[36] = getNextError();
response[37] = currentStatus.boostTarget; response[37] = currentStatus.boostTarget;
response[38] = currentStatus.boostDuty; response[38] = currentStatus.boostDuty;
response[39] = currentStatus.idleLoad;
//cli(); //cli();
if (portNum == 0) { Serial.write(response, (size_t)packetlength); } if (portNum == 0) { Serial.write(response, (size_t)packetlength); }

View File

@ -207,6 +207,7 @@ struct statuses {
volatile byte startRevolutions; //A counter for how many revolutions have been completed since sync was achieved. volatile byte startRevolutions; //A counter for how many revolutions have been completed since sync was achieved.
byte boostTarget; byte boostTarget;
byte boostDuty; byte boostDuty;
byte idleLoad; //Either the current steps or current duty cycle for the idle control.
//Helpful bitwise operations: //Helpful bitwise operations:
//Useful reference: http://playground.arduino.cc/Code/BitMath //Useful reference: http://playground.arduino.cc/Code/BitMath

View File

@ -19,8 +19,8 @@ enum StepperStatus {SOFF, STEPPING, COOLING}; //The 2 statuses that a stepper ca
struct StepperIdle struct StepperIdle
{ {
unsigned int curIdleStep; //Tracks the current location of the stepper int curIdleStep; //Tracks the current location of the stepper
unsigned int targetIdleStep; //What the targetted step is int targetIdleStep; //What the targetted step is
volatile StepperStatus stepperStatus; volatile StepperStatus stepperStatus;
volatile unsigned long stepStartTime; //The time the curren volatile unsigned long stepStartTime; //The time the curren
}; };

View File

@ -80,11 +80,10 @@ void initialiseIdle()
//Initialising comprises of setting the 2D tables with the relevant values from the config pages //Initialising comprises of setting the 2D tables with the relevant values from the config pages
switch(configPage4.iacAlgorithm) switch(configPage4.iacAlgorithm)
{ {
case 0: case IAC_ALGORITHM_NONE: //Case 0 is no idle control ('None')
//Case 0 is no idle control ('None')
break; break;
case 1: case IAC_ALGORITHM_ONOFF:
//Case 1 is on/off idle control //Case 1 is on/off idle control
if (currentStatus.coolant < configPage4.iacFastTemp) if (currentStatus.coolant < configPage4.iacFastTemp)
{ {
@ -92,7 +91,7 @@ void initialiseIdle()
} }
break; break;
case 2: case IAC_ALGORITHM_PWM_OL:
//Case 2 is PWM open loop //Case 2 is PWM open loop
iacPWMTable.xSize = 10; iacPWMTable.xSize = 10;
iacPWMTable.valueSize = SIZE_BYTE; iacPWMTable.valueSize = SIZE_BYTE;
@ -112,7 +111,7 @@ void initialiseIdle()
enableIdle(); enableIdle();
break; break;
case 3: case IAC_ALGORITHM_PWM_CL:
//Case 3 is PWM closed loop //Case 3 is PWM closed loop
iacClosedLoopTable.xSize = 10; iacClosedLoopTable.xSize = 10;
iacClosedLoopTable.valueSize = SIZE_BYTE; iacClosedLoopTable.valueSize = SIZE_BYTE;
@ -136,7 +135,7 @@ void initialiseIdle()
idleCounter = 0; idleCounter = 0;
break; break;
case 4: case IAC_ALGORITHM_STEP_OL:
//Case 2 is Stepper open loop //Case 2 is Stepper open loop
iacStepTable.xSize = 10; iacStepTable.xSize = 10;
iacStepTable.valueSize = SIZE_BYTE; iacStepTable.valueSize = SIZE_BYTE;
@ -150,10 +149,11 @@ void initialiseIdle()
//homeStepper(); //Returns the stepper to the 'home' position //homeStepper(); //Returns the stepper to the 'home' position
completedHomeSteps = 0; completedHomeSteps = 0;
idleStepper.curIdleStep = 0;
idleStepper.stepperStatus = SOFF; idleStepper.stepperStatus = SOFF;
break; break;
case 5: case IAC_ALGORITHM_STEP_CL:
//Case 5 is Stepper closed loop //Case 5 is Stepper closed loop
iacClosedLoopTable.xSize = 10; iacClosedLoopTable.xSize = 10;
iacClosedLoopTable.valueSize = SIZE_BYTE; iacClosedLoopTable.valueSize = SIZE_BYTE;
@ -167,6 +167,7 @@ void initialiseIdle()
completedHomeSteps = 0; completedHomeSteps = 0;
idleCounter = 0; idleCounter = 0;
idleStepper.curIdleStep = 0;
idleStepper.stepperStatus = SOFF; idleStepper.stepperStatus = SOFF;
idlePID.SetOutputLimits(0, (configPage4.iacStepHome * 3)); //Maximum number of steps probably needs its own setting idlePID.SetOutputLimits(0, (configPage4.iacStepHome * 3)); //Maximum number of steps probably needs its own setting
@ -175,6 +176,7 @@ void initialiseIdle()
break; break;
} }
idleInitComplete = configPage4.iacAlgorithm; //Sets which idle method was initialised idleInitComplete = configPage4.iacAlgorithm; //Sets which idle method was initialised
currentStatus.idleLoad = 0;
} }
void idleControl() void idleControl()
@ -211,6 +213,7 @@ void idleControl()
if( currentStatus.idleDuty == 0 ) { disableIdle(); break; } if( currentStatus.idleDuty == 0 ) { disableIdle(); break; }
enableIdle(); enableIdle();
idle_pwm_target_value = percentage(currentStatus.idleDuty, idle_pwm_max_count); idle_pwm_target_value = percentage(currentStatus.idleDuty, idle_pwm_max_count);
currentStatus.idleLoad = currentStatus.idleDuty >> 1;
idleOn = true; idleOn = true;
} }
break; break;
@ -224,6 +227,7 @@ void idleControl()
idle_pwm_target_value = idle_pid_target_value; idle_pwm_target_value = idle_pid_target_value;
if( idle_pwm_target_value == 0 ) { disableIdle(); } if( idle_pwm_target_value == 0 ) { disableIdle(); }
else{ enableIdle(); } //Turn on the C compare unit (ie turn on the interrupt) else{ enableIdle(); } //Turn on the C compare unit (ie turn on the interrupt)
currentStatus.idleLoad = ((unsigned long)(idle_pwm_target_value * 100UL) / idle_pwm_max_count) >> 1;
//idle_pwm_target_value = 104; //idle_pwm_target_value = 104;
idleCounter++; idleCounter++;
@ -251,6 +255,7 @@ void idleControl()
} }
doStep(); doStep();
} }
currentStatus.idleLoad = idleStepper.curIdleStep >> 1; //Current step count (Divided by 2 for byte)
break; break;
case IAC_ALGORITHM_STEP_CL://Case 5 is closed loop stepper control case IAC_ALGORITHM_STEP_CL://Case 5 is closed loop stepper control
@ -262,9 +267,10 @@ void idleControl()
idle_cl_target_rpm = table2D_getValue(&iacClosedLoopTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET) * 10; //All temps are offset by 40 degrees idle_cl_target_rpm = table2D_getValue(&iacClosedLoopTable, currentStatus.coolant + CALIBRATION_TEMPERATURE_OFFSET) * 10; //All temps are offset by 40 degrees
idlePID.Compute(); idlePID.Compute();
idleStepper.targetIdleStep = (idle_pid_target_value >> 7); //Target is scalled down by 128 to bring it inline with most stepper motors range. Allows a sane range of around 300 steps (Maximum RPM error of 600, P=64) idleStepper.targetIdleStep = (idle_pid_target_value >> 7); //Target is scaled down by 128 to bring it inline with most stepper motors range. Allows a sane range of around 300 steps (Maximum RPM error of 600, P=64)
doStep(); doStep();
currentStatus.idleLoad = idleStepper.curIdleStep >> 1; //Current step count (Divided by 2 for byte)
idleCounter++; idleCounter++;
break; break;
} }
@ -344,15 +350,31 @@ static inline void doStep()
//This function simply turns off the idle PWM and sets the pin low //This function simply turns off the idle PWM and sets the pin low
static inline void disableIdle() static inline void disableIdle()
{ {
IDLE_TIMER_DISABLE(); if(configPage4.iacAlgorithm == IAC_ALGORITHM_PWM_CL || configPage4.iacAlgorithm == IAC_ALGORITHM_PWM_OL)
digitalWrite(pinIdle1, LOW); {
IDLE_TIMER_DISABLE();
digitalWrite(pinIdle1, LOW);
}
else if (configPage4.iacAlgorithm == IAC_ALGORITHM_STEP_CL || configPage4.iacAlgorithm == IAC_ALGORITHM_STEP_OL)
{
idleStepper.targetIdleStep = 1; //Home the stepper
doStep();
}
} }
//Any common functions associated with starting the Idle //Any common functions associated with starting the Idle
//Typically this is enabling the PWM interrupt //Typically this is enabling the PWM interrupt
static inline void enableIdle() static inline void enableIdle()
{ {
IDLE_TIMER_ENABLE(); if(configPage4.iacAlgorithm == IAC_ALGORITHM_PWM_CL || configPage4.iacAlgorithm == IAC_ALGORITHM_PWM_OL)
{
IDLE_TIMER_ENABLE();
}
else if (configPage4.iacAlgorithm == IAC_ALGORITHM_STEP_CL || configPage4.iacAlgorithm == IAC_ALGORITHM_STEP_OL)
{
}
} }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) //AVR chips use the ISR for this