2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
#include "defaults.h"
|
2022-05-17 14:54:11 -07:00
|
|
|
#include "vr_pwm.h"
|
2023-03-03 18:27:48 -08:00
|
|
|
#include "kline.h"
|
2023-07-19 10:58:43 -07:00
|
|
|
#if HW_PROTEUS
|
|
|
|
#include "proteus_meta.h"
|
|
|
|
#endif // HW_PROTEUS
|
2021-06-02 14:50:07 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
static void setDefaultAlternatorParameters() {
|
2021-06-02 14:50:07 -07:00
|
|
|
engineConfiguration->alternatorOffAboveTps = 120;
|
|
|
|
|
|
|
|
engineConfiguration->targetVBatt = 14;
|
|
|
|
|
|
|
|
engineConfiguration->alternatorControl.offset = 0;
|
|
|
|
engineConfiguration->alternatorControl.pFactor = 30;
|
|
|
|
engineConfiguration->alternatorControl.periodMs = 100;
|
|
|
|
}
|
|
|
|
|
2023-06-10 09:46:39 -07:00
|
|
|
void setGDIFueling() {
|
|
|
|
// Use high pressure sensor
|
|
|
|
engineConfiguration->injectorPressureType = IPT_High;
|
|
|
|
// Automatic compensation of injector flow based on rail pressure
|
|
|
|
engineConfiguration->injectorCompensationMode = ICM_SensedRailPressure;
|
|
|
|
// Reference rail pressure is 10 000 kPa = 100 bar
|
|
|
|
engineConfiguration->fuelReferencePressure = 10000;
|
|
|
|
//setting "flat" 0.2 ms injector's lag time
|
|
|
|
setArrayValues(engineConfiguration->injector.battLagCorr, 0.2);
|
2023-06-12 16:39:46 -07:00
|
|
|
|
|
|
|
setTable(config->injectionPhase, -200.0f);
|
|
|
|
engineConfiguration->injectionTimingMode = InjectionTimingMode::Center;
|
2023-06-10 09:46:39 -07:00
|
|
|
}
|
|
|
|
|
2022-10-25 18:54:26 -07:00
|
|
|
/* Cylinder to bank mapping */
|
|
|
|
void setLeftRightBanksNeedBetterName() {
|
2023-03-27 00:58:18 -07:00
|
|
|
for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) {
|
2022-10-25 18:54:26 -07:00
|
|
|
engineConfiguration->cylinderBankSelect[i] = i % 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-24 21:41:13 -07:00
|
|
|
static void setDefaultHPFP() {
|
2023-08-29 13:46:04 -07:00
|
|
|
engineConfiguration->hpfpCamLobes = 3;
|
2023-04-24 21:55:47 -07:00
|
|
|
// todo: would be nice for unit tests to be happy about these defaults
|
|
|
|
#if EFI_PROD_CODE
|
2023-04-24 21:41:13 -07:00
|
|
|
engineConfiguration->hpfpPumpVolume = 0.290;
|
|
|
|
engineConfiguration->hpfpMinAngle = 10;
|
|
|
|
engineConfiguration->hpfpActivationAngle = 30;
|
|
|
|
engineConfiguration->hpfpTargetDecay = 2000;
|
|
|
|
engineConfiguration->hpfpPidP = 0.01;
|
|
|
|
engineConfiguration->hpfpPidI = 0.0003;
|
|
|
|
engineConfiguration->hpfpPeakPos = 10;
|
2023-04-24 21:55:47 -07:00
|
|
|
#endif
|
2023-04-24 21:41:13 -07:00
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setDefaultBaseEngine() {
|
2021-06-02 14:50:07 -07:00
|
|
|
// Base Engine Settings
|
2023-03-27 00:58:18 -07:00
|
|
|
engineConfiguration->displacement = 2;
|
2023-07-23 23:41:45 -07:00
|
|
|
setInline4();
|
2021-06-02 14:50:07 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->compressionRatio = 9;
|
2023-03-30 07:01:51 -07:00
|
|
|
engineConfiguration->vssFilterReciprocal = VSS_FILTER_MIN;
|
2023-05-09 16:33:47 -07:00
|
|
|
engineConfiguration->boardUseCanTerminator = true;
|
2021-06-02 14:50:07 -07:00
|
|
|
|
2023-04-24 21:41:13 -07:00
|
|
|
setDefaultHPFP();
|
|
|
|
|
2022-09-19 09:06:00 -07:00
|
|
|
engineConfiguration->turbochargerFilter = 0.01f;
|
|
|
|
|
2021-06-03 11:40:19 -07:00
|
|
|
engineConfiguration->fuelAlgorithm = LM_SPEED_DENSITY;
|
2022-01-21 12:22:11 -08:00
|
|
|
// let's have valid default while we still have the field
|
|
|
|
engineConfiguration->debugMode = DBG_INSTANT_RPM;
|
2021-06-03 11:40:19 -07:00
|
|
|
|
2023-05-05 12:27:02 -07:00
|
|
|
engineConfiguration->boostCutPressure = 300;
|
|
|
|
engineConfiguration->boostCutPressureHyst = 20;
|
|
|
|
|
2023-06-18 20:02:38 -07:00
|
|
|
engineConfiguration->primingDelay = 0.5;
|
2023-06-19 07:47:26 -07:00
|
|
|
engineConfiguration->vvtControlMinRpm = 500.0;
|
2023-06-18 20:02:38 -07:00
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
// Limits and Fallbacks
|
|
|
|
engineConfiguration->rpmHardLimit = 7000;
|
2023-04-29 07:43:53 -07:00
|
|
|
engineConfiguration->rpmHardLimitHyst = 50;
|
2021-06-02 14:50:07 -07:00
|
|
|
engineConfiguration->cutFuelOnHardLimit = true;
|
|
|
|
engineConfiguration->cutSparkOnHardLimit = true;
|
|
|
|
|
2023-04-22 11:22:39 -07:00
|
|
|
// engineConfiguration->totalGearsCount = 5;
|
|
|
|
// engineConfiguration->gearRatio[0] = 3.35f;
|
|
|
|
// engineConfiguration->gearRatio[1] = 1.99f;
|
|
|
|
// engineConfiguration->gearRatio[2] = 1.33f;
|
|
|
|
// engineConfiguration->gearRatio[3] = 1.00f;
|
|
|
|
// engineConfiguration->gearRatio[4] = 0.72f;
|
2023-04-22 08:57:07 -07:00
|
|
|
|
2022-12-16 20:51:50 -08:00
|
|
|
engineConfiguration->ALSMinRPM = 400;
|
|
|
|
engineConfiguration->ALSMaxRPM = 3200;
|
2023-02-06 15:05:38 -08:00
|
|
|
engineConfiguration->ALSMaxDuration = 3.5;
|
2022-12-16 20:51:50 -08:00
|
|
|
engineConfiguration->ALSMaxCLT = 105;
|
|
|
|
// engineConfiguration->alsMinPps = 10;
|
2022-12-14 19:25:06 -08:00
|
|
|
engineConfiguration->alsMinTimeBetween = 5;
|
|
|
|
engineConfiguration->alsEtbPosition = 30;
|
2022-12-31 11:47:48 -08:00
|
|
|
engineConfiguration->ALSMaxTPS = 5;
|
2022-12-14 19:25:06 -08:00
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
// Trigger
|
2023-05-31 22:56:40 -07:00
|
|
|
engineConfiguration->trigger.type = trigger_type_e::TT_TOOTHED_WHEEL_60_2;
|
2022-04-03 03:58:25 -07:00
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
engineConfiguration->globalTriggerAngleOffset = 0;
|
|
|
|
|
|
|
|
// Default this to on - if you want to diagnose, turn it off.
|
|
|
|
engineConfiguration->silentTriggerError = true;
|
|
|
|
|
2023-03-27 18:33:49 -07:00
|
|
|
engineConfiguration->idleStepperReactionTime = 3;
|
|
|
|
engineConfiguration->idleStepperTotalSteps = 200;
|
2023-03-27 19:01:20 -07:00
|
|
|
engineConfiguration->stepperForceParkingEveryRestart = true;
|
2023-06-14 21:57:28 -07:00
|
|
|
engineConfiguration->iacByTpsTaper = 2;
|
2023-03-27 18:33:49 -07:00
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
// Advanced Trigger
|
|
|
|
|
|
|
|
// Battery and alternator
|
|
|
|
engineConfiguration->vbattDividerCoeff = ((float) (15 + 65)) / 15;
|
|
|
|
|
|
|
|
#if EFI_ALTERNATOR_CONTROL
|
2021-11-16 01:15:29 -08:00
|
|
|
setDefaultAlternatorParameters();
|
2021-06-02 14:50:07 -07:00
|
|
|
#endif /* EFI_ALTERNATOR_CONTROL */
|
|
|
|
|
|
|
|
// Fuel pump
|
|
|
|
engineConfiguration->startUpFuelPumpDuration = 4;
|
|
|
|
|
2023-03-03 18:27:48 -08:00
|
|
|
engineConfiguration->kLineBaudRate = KLINE_BAUD_RATE;
|
|
|
|
|
2022-05-22 06:42:58 -07:00
|
|
|
engineConfiguration->benchTestOnTime = 4;
|
|
|
|
engineConfiguration->benchTestOffTime = 500;
|
|
|
|
engineConfiguration->benchTestCount = 3;
|
|
|
|
|
2021-06-13 05:06:45 -07:00
|
|
|
// Fans
|
2021-06-02 14:50:07 -07:00
|
|
|
engineConfiguration->fanOnTemperature = 95;
|
|
|
|
engineConfiguration->fanOffTemperature = 91;
|
2021-06-13 05:06:45 -07:00
|
|
|
engineConfiguration->fan2OnTemperature = 95;
|
|
|
|
engineConfiguration->fan2OffTemperature = 91;
|
2021-06-02 14:50:07 -07:00
|
|
|
|
|
|
|
// Tachometer
|
|
|
|
// 50% duty cycle is the default for tach signal
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->tachPulseDurationAsDutyCycle = true;
|
|
|
|
engineConfiguration->tachPulseDuractionMs = 0.5;
|
|
|
|
engineConfiguration->tachPulsePerRev = 1;
|
2021-06-02 14:50:07 -07:00
|
|
|
|
2022-05-02 02:24:50 -07:00
|
|
|
engineConfiguration->etbMinimumPosition = 1;
|
|
|
|
engineConfiguration->etbMaximumPosition = 100;
|
2022-04-25 14:20:56 -07:00
|
|
|
|
|
|
|
engineConfiguration->tcuInputSpeedSensorTeeth = 1;
|
2022-04-25 14:42:19 -07:00
|
|
|
engineConfiguration->issFilterReciprocal = 2;
|
2022-04-25 14:20:56 -07:00
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
// Check engine light
|
|
|
|
#if EFI_PROD_CODE
|
|
|
|
engineConfiguration->warningPeriod = 10;
|
|
|
|
#else
|
|
|
|
engineConfiguration->warningPeriod = 0;
|
|
|
|
#endif /* EFI_PROD_CODE */
|
2022-05-17 14:54:11 -07:00
|
|
|
|
|
|
|
setDefaultVrThresholds();
|
|
|
|
|
2021-06-02 14:50:07 -07:00
|
|
|
}
|
2022-10-29 20:04:24 -07:00
|
|
|
|
|
|
|
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2) {
|
|
|
|
engineConfiguration->throttlePedalPositionAdcChannel = pps1;
|
|
|
|
engineConfiguration->throttlePedalPositionSecondAdcChannel = pps2;
|
2022-10-29 20:55:14 -07:00
|
|
|
}
|
|
|
|
|
2022-10-29 21:17:42 -07:00
|
|
|
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2) {
|
|
|
|
engineConfiguration->tps1_1AdcChannel = tps1;
|
|
|
|
engineConfiguration->tps1_2AdcChannel = tps2;
|
|
|
|
}
|
|
|
|
|
2023-03-03 07:35:06 -08:00
|
|
|
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax) {
|
2022-11-04 09:37:28 -07:00
|
|
|
engineConfiguration->tpsMin = tpsMin;
|
|
|
|
engineConfiguration->tpsMax = tpsMax;
|
2023-03-03 07:35:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax, uint16_t tps1SecondaryMin, uint16_t tps1SecondaryMax) {
|
|
|
|
setTPS1Calibration(tpsMin, tpsMax);
|
|
|
|
|
2022-11-04 09:37:28 -07:00
|
|
|
|
|
|
|
engineConfiguration->tps1SecondaryMin = tps1SecondaryMin;
|
|
|
|
engineConfiguration->tps1SecondaryMax = tps1SecondaryMax;
|
|
|
|
}
|
|
|
|
|
2022-10-29 20:55:14 -07:00
|
|
|
void setPPSCalibration(float primaryUp, float primaryDown, float secondaryUp, float secondaryDown) {
|
|
|
|
engineConfiguration->throttlePedalUpVoltage = primaryUp;
|
|
|
|
engineConfiguration->throttlePedalWOTVoltage = primaryDown;
|
|
|
|
engineConfiguration->throttlePedalSecondaryUpVoltage = secondaryUp;
|
|
|
|
engineConfiguration->throttlePedalSecondaryWOTVoltage = secondaryDown;
|
|
|
|
}
|
2022-11-04 10:27:40 -07:00
|
|
|
|
|
|
|
void setEtbPID(float p, float i, float d) {
|
|
|
|
engineConfiguration->etb.pFactor = p;
|
|
|
|
engineConfiguration->etb.iFactor = i;
|
|
|
|
engineConfiguration->etb.dFactor = d;
|
|
|
|
}
|
2023-07-12 08:34:25 -07:00
|
|
|
|
|
|
|
void setInline4() {
|
|
|
|
engineConfiguration->cylindersCount = 4;
|
|
|
|
engineConfiguration->firingOrder = FO_1_3_4_2;
|
|
|
|
}
|
2023-07-19 10:36:19 -07:00
|
|
|
|
|
|
|
void setProteusEtbIO() {
|
2023-07-19 10:50:51 -07:00
|
|
|
#if HW_PROTEUS && EFI_PROD_CODE
|
2023-07-19 10:36:19 -07:00
|
|
|
engineConfiguration->tps1_2AdcChannel = PROTEUS_IN_TPS1_2;
|
|
|
|
setPPSInputs(PROTEUS_IN_PPS, PROTEUS_IN_PPS2);
|
|
|
|
#endif // HW_PROTEUS
|
|
|
|
}
|