etbActualCount logic to handle the scenario where only one ETB is present

This commit is contained in:
rusefi 2019-12-13 12:50:34 -05:00
parent 1c2d1495ec
commit e9e7a66cf8
5 changed files with 46 additions and 35 deletions

View File

@ -357,34 +357,11 @@ DISPLAY(DISPLAY_IF(hasEtbPedalPositionSensor))
static EtbHardware etbHardware[ETB_COUNT];
EtbController etbController[ETB_COUNT];
/**
* At the moment there are TWO ways to use this
* set_etb_duty X
* set etb X
* manual duty cycle control without PID. Percent value from 0 to 100
*/
void setThrottleDutyCycle(percent_t level) {
scheduleMsg(&logger, "setting ETB duty=%f%%", level);
if (cisnan(level)) {
directPwmValue = NAN;
return;
}
float dc = ETB_PERCENT_TO_DUTY(level);
directPwmValue = dc;
for (int i = 0 ; i < ETB_COUNT; i++) {
etbHardware[i].dcMotor.set(dc);
}
scheduleMsg(&logger, "duty ETB duty=%f", dc);
}
static bool etbOperational = false;
static void showEthInfo(void) {
#if EFI_PROD_CODE
static char pinNameBuffer[16];
if (!etbOperational) {
if (engine->etbActualCount == 0) {
scheduleMsg(&logger, "ETB DISABLED since no PPS");
}
@ -407,7 +384,7 @@ static void showEthInfo(void) {
scheduleMsg(&logger, "dir1=%s", hwPortname(CONFIG(etbIo[0].directionPin1)));
scheduleMsg(&logger, "dir2=%s", hwPortname(CONFIG(etbIo[0].directionPin2)));
for (int i = 0 ; i < ETB_COUNT; i++) {
for (int i = 0 ; i < engine->etbActualCount; i++) {
EtbHardware *etb = &etbHardware[i];
scheduleMsg(&logger, "ETB %%d", i);
@ -418,18 +395,39 @@ static void showEthInfo(void) {
#endif /* EFI_PROD_CODE */
}
static void etbPidReset() {
for (int i = 0 ; i < ETB_COUNT; i++) {
static void etbPidReset(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
for (int i = 0 ; i < engine->etbActualCount; i++) {
etbController[i].reset();
}
}
#if EFI_PROD_CODE
#if !EFI_UNIT_TEST
/**
* At the moment there are TWO ways to use this
* set_etb_duty X
* set etb X
* manual duty cycle control without PID. Percent value from 0 to 100
*/
void setThrottleDutyCycle(percent_t level) {
scheduleMsg(&logger, "setting ETB duty=%f%%", level);
if (cisnan(level)) {
directPwmValue = NAN;
return;
}
float dc = ETB_PERCENT_TO_DUTY(level);
directPwmValue = dc;
for (int i = 0 ; i < engine->etbActualCount; i++) {
etbHardware[i].dcMotor.set(dc);
}
scheduleMsg(&logger, "duty ETB duty=%f", dc);
}
static void setEtbFrequency(int frequency) {
engineConfiguration->etbFreq = frequency;
for (int i = 0 ; i < ETB_COUNT; i++) {
for (int i = 0 ; i < engine->etbActualCount; i++) {
etbHardware[i].setFrequency(frequency);
}
}
@ -437,7 +435,7 @@ static void setEtbFrequency(int frequency) {
static void etbReset() {
scheduleMsg(&logger, "etbReset");
for (int i = 0 ; i < ETB_COUNT; i++) {
for (int i = 0 ; i < engine->etbActualCount; i++) {
etbHardware[i].dcMotor.set(0);
}
@ -584,6 +582,9 @@ void onConfigurationChangeElectronicThrottleCallback(engine_configuration_s *pre
void startETBPins(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
/**
* safer to start 2nd ETB even if 2nd TPS is not configured by mistake
*/
for (int i = 0 ; i < ETB_COUNT; i++) {
etb_io *io = &engineConfiguration->etbIo[i];
// controlPinMode is a strange feature - it's simply because I am short on 5v I/O on Frankenso with Miata NB2 test mule
@ -676,7 +677,8 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (!engine->engineState.hasEtbPedalPositionSensor) {
return;
}
etbOperational = true;
engine->etbActualCount = hasTps2(PASS_ENGINE_PARAMETER_SIGNATURE) ? 2 : 1;
#if 0
// not alive code
autoTune.SetOutputStep(0.1);
@ -700,7 +702,7 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_PROD_CODE
if (engineConfiguration->etbCalibrationOnStart) {
for (int i = 0 ; i < ETB_COUNT; i++) {
for (int i = 0 ; i < engine->etbActualCount; i++) {
EtbHardware *etb = &etbHardware[i];
etb->dcMotor.set(70);
@ -737,9 +739,9 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#endif /* EFI_PROD_CODE */
etbPidReset();
etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE);
for (int i = 0 ; i < ETB_COUNT; i++) {
for (int i = 0 ; i < engine->etbActualCount; i++) {
etbController[i].Start();
}
}

View File

@ -65,6 +65,10 @@ public:
AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2];
bool needTdcCallback = true;
/**
* if 2nd TPS is not configured we do not run 2nd ETB
*/
int etbActualCount = 0;
/**
* By the way 32-bit value should hold at least 400 hours of events at 6K RPM x 12 events per revolution

View File

@ -819,6 +819,6 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0)
return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20191209;
return 20191213;
}
#endif /* EFI_UNIT_TEST */

View File

@ -217,6 +217,10 @@ bool hasPedalPositionSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->throttlePedalPositionAdcChannel != EFI_ADC_NONE;
}
bool hasTps2(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->tps2_1AdcChannel != EFI_ADC_NONE;
}
percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (mockPedalPosition != MOCK_UNDEFINED) {
return mockPedalPosition;

View File

@ -28,6 +28,7 @@ percent_t getTPSWithIndex(int index DECLARE_ENGINE_PARAMETER_SUFFIX);
bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
int convertVoltageTo10bitADC(float voltage);
int getTPS12bitAdc(int index DECLARE_ENGINE_PARAMETER_SUFFIX);
bool hasTps2(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#define getTPS10bitAdc() (getTPS12bitAdc(0 PASS_ENGINE_PARAMETER_SUFFIX) / TPS_TS_CONVERSION)
float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE);
percent_t getTpsValue(int index, int adc DECLARE_ENGINE_PARAMETER_SUFFIX);