diff --git a/firmware/config/engines/mazda_miata_vvt.cpp b/firmware/config/engines/mazda_miata_vvt.cpp index 16a24d81d5..d96d83305a 100644 --- a/firmware/config/engines/mazda_miata_vvt.cpp +++ b/firmware/config/engines/mazda_miata_vvt.cpp @@ -60,7 +60,7 @@ static const float ve18fsioLoadBins[FSIO_TABLE_8] = {30.0, 40.0, 50.0, 60.0, 70.0, 75.0, 82.0, 85.0} ; -float const fsio_table_random[FSIO_TABLE_8][FSIO_TABLE_8] = { +float const fsio_table_vvt_target[FSIO_TABLE_8][FSIO_TABLE_8] = { /* Generated by TS2C on Mon Feb 13 19:11:32 EST 2017*/ {/* 0 30.000 *//* 0 700.0*/1.000, /* 1 1000.0*/3.000, /* 2 2000.0*/10.000, /* 3 3000.0*/20.000, /* 4 3500.0*/27.000, /* 5 4500.0*/28.000, /* 6 5500.0*/11.000, /* 7 6500.0*/5.000, }, {/* 1 40.000 *//* 0 700.0*/3.000, /* 1 1000.0*/10.000, /* 2 2000.0*/19.000, /* 3 3000.0*/26.000, /* 4 3500.0*/30.000, /* 5 4500.0*/28.000, /* 6 5500.0*/11.000, /* 7 6500.0*/5.000, }, @@ -237,13 +237,63 @@ void setMazdaMiataNbInjectorLag(DECLARE_CONFIG_PARAMETER_SIGNATURE) { memcpy(engineConfiguration->injector.battLagCorrBins, injectorLagBins, sizeof(injectorLagBins)); } -void setMazdaMiata2003EngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { - setFrankensoConfiguration(PASS_CONFIG_PARAMETER_SIGNATURE); - +static void setMazdaMiataEngineNB2Defaults(DECLARE_CONFIG_PARAMETER_SIGNATURE) { engineConfiguration->trigger.type = TT_MIATA_VVT; setOperationMode(engineConfiguration, FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR); engineConfiguration->specs.displacement = 1.8; + // enable altdebug + engineConfiguration->targetVBatt = 13.8; + engineConfiguration->alternatorControl.offset = 40; + engineConfiguration->alternatorControl.pFactor = 14; + engineConfiguration->alternatorControl.iFactor = 0.1; + engineConfiguration->alternatorControl.dFactor = 0; + engineConfiguration->alternatorControl.periodMs = 10; + + // VVT closed loop + engineConfiguration->auxPid[0].pFactor = 2; + engineConfiguration->auxPid[0].iFactor = 0.005; + engineConfiguration->auxPid[0].dFactor = 0; + engineConfiguration->auxPid[0].offset = 33; + engineConfiguration->auxPid[0].minValue = 24; + engineConfiguration->auxPid[0].maxValue = 44; + engineConfiguration->activateAuxPid1 = true; // todo: remove this field? + + // set vvt_mode 3 + engineConfiguration->vvtMode = MIATA_NB2; + engineConfiguration->vvtOffset = 98; // 2003 red car value + + memcpy(config->veRpmBins, ve18vvtRpmBins, sizeof(ve18vvtRpmBins)); + memcpy(config->veLoadBins, ve18vvtLoadBins, sizeof(ve18vvtLoadBins)); + copyFuelTable(mapBased18vvtVeTable_NB_fuel_rail, config->veTable); + + memcpy(config->ignitionRpmBins, ignition18vvtRpmBins, sizeof(ignition18vvtRpmBins)); + memcpy(config->ignitionLoadBins, ignition18vvtLoadBins, sizeof(ignition18vvtLoadBins)); +#if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT + copyTimingTable(mapBased18vvtTimingTable, config->ignitionTable); +#endif + + memcpy(config->fsioTable1RpmBins, ve18fsioRpmBins, sizeof(ve18fsioRpmBins)); + memcpy(config->fsioTable1LoadBins, ve18fsioLoadBins, sizeof(ve18fsioLoadBins)); + // todo: there should be a better way? + for (int loadIndex = 0; loadIndex < FSIO_TABLE_8; loadIndex++) { + for (int rpmIndex = 0; rpmIndex < FSIO_TABLE_8; rpmIndex++) { + config->fsioTable1[loadIndex][rpmIndex] = fsio_table_vvt_target[loadIndex][rpmIndex]; + } + } + + // enable cylinder_cleanup + engineConfiguration->isCylinderCleanupEnabled = true; + + setMazdaMiataNbTpsTps(PASS_CONFIG_PARAMETER_SIGNATURE); +} // end of setMazdaMiataEngineNB2Defaults + + +void setMazdaMiata2003EngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { + setFrankensoConfiguration(PASS_CONFIG_PARAMETER_SIGNATURE); + + setMazdaMiataEngineNB2Defaults(PASS_CONFIG_PARAMETER_SIGNATURE); + // boardConfiguration->triggerInputPins[0] = GPIOA_8; // custom Frankenso wiring in order to use SPI1 for accelerometer boardConfiguration->triggerInputPins[0] = GPIOA_5; // board still not modified boardConfiguration->triggerInputPins[1] = GPIO_UNASSIGNED; @@ -259,32 +309,13 @@ void setMazdaMiata2003EngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { // boardConfiguration->vehicleSpeedSensorInputPin = GPIOA_8; - // enable altdebug - engineConfiguration->targetVBatt = 13.8; - engineConfiguration->alternatorControl.offset = 40; - engineConfiguration->alternatorControl.pFactor = 14; - engineConfiguration->alternatorControl.iFactor = 0.1; - engineConfiguration->alternatorControl.dFactor = 0; - engineConfiguration->alternatorControl.periodMs = 10; - - engineConfiguration->auxPid[0].pFactor = 2; - engineConfiguration->auxPid[0].iFactor = 0.005; - engineConfiguration->auxPid[0].dFactor = 0; - engineConfiguration->auxPid[0].offset = 33; - engineConfiguration->auxPid[0].minValue = 24; - engineConfiguration->auxPid[0].maxValue = 44; - // set idle_position 35 boardConfiguration->manIdlePosition = 35; - // set vvt_mode 3 - engineConfiguration->vvtMode = MIATA_NB2; boardConfiguration->vvtCamSensorUseRise = true; engineConfiguration->vvtDisplayInverted = true; - engineConfiguration->vvtOffset = 98; // 2003 red car value - engineConfiguration->activateAuxPid1 = true; // todo: remove this field? engineConfiguration->auxPidFrequency[0] = 300; engineConfiguration->auxPidPins[0] = GPIOE_3; // VVT solenoid control // /** @@ -324,37 +355,11 @@ void setMazdaMiata2003EngineConfiguration(DECLARE_CONFIG_PARAMETER_SIGNATURE) { // set_whole_ve_map 80 - memcpy(config->veRpmBins, ve18vvtRpmBins, sizeof(ve18vvtRpmBins)); - memcpy(config->veLoadBins, ve18vvtLoadBins, sizeof(ve18vvtLoadBins)); - copyFuelTable(mapBased18vvtVeTable_NB_fuel_rail, config->veTable); - - memcpy(config->ignitionRpmBins, ignition18vvtRpmBins, sizeof(ignition18vvtRpmBins)); - memcpy(config->ignitionLoadBins, ignition18vvtLoadBins, sizeof(ignition18vvtLoadBins)); -#if IGN_LOAD_COUNT == DEFAULT_IGN_LOAD_COUNT - copyTimingTable(mapBased18vvtTimingTable, config->ignitionTable); -#endif - - memcpy(config->fsioTable1RpmBins, ve18fsioRpmBins, sizeof(ve18fsioRpmBins)); - memcpy(config->fsioTable1LoadBins, ve18fsioLoadBins, sizeof(ve18fsioLoadBins)); - // todo: there should be a better way? - for (int loadIndex = 0; loadIndex < FSIO_TABLE_8; loadIndex++) { - for (int rpmIndex = 0; rpmIndex < FSIO_TABLE_8; rpmIndex++) { - config->fsioTable1[loadIndex][rpmIndex] = fsio_table_random[loadIndex][rpmIndex]; - } - } - - setMazdaMiataNbTpsTps(PASS_CONFIG_PARAMETER_SIGNATURE); - - setMazdaMiataNbInjectorLag(PASS_CONFIG_PARAMETER_SIGNATURE); engineConfiguration->tpsMin = 100; // convert 12to10 bit (ADC/4) engineConfiguration->tpsMax = 650; // convert 12to10 bit (ADC/4) - // enable cylinder_cleanup - engineConfiguration->isCylinderCleanupEnabled = true; - - // 0.0825 // 0.1375 @@ -500,7 +505,29 @@ void setMazdaMiata2003EngineConfigurationBoardTest(DECLARE_CONFIG_PARAMETER_SIGN /** * Pretty OEM 2003 Miata with ETB + * set engine_type 13 */ void setMiataNB2_MRE(DECLARE_CONFIG_PARAMETER_SIGNATURE) { + engineConfiguration->etb.pFactor = 22; + engineConfiguration->etb.iFactor = 0; + engineConfiguration->etb.dFactor = 0; + engineConfiguration->etb.offset = 0; + + // enable ETB + // set_rpn_expression 8 "0" + setFsio(7, GPIOC_8, "0" PASS_CONFIG_PARAMETER_SUFFIX); + + // set_analog_input_pin pps PA7 + // EFI_ADC_7: "31 - AN volt 3" - PA7 + engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_7; + + // set tps_min 90 + engineConfiguration->tpsMin = 870; + + // set tps_max 540 + engineConfiguration->tpsMax = 870; + + + }