Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * @file    advance_map.cpp
  3.  *
  4.  * @date Mar 27, 2013
  5.  * @author Andrey Belomutskiy, (c) 2012-2015
  6.  *
  7.  * This file is part of rusEfi - see http://rusefi.com
  8.  *
  9.  * rusEfi is free software; you can redistribute it and/or modify it under the terms of
  10.  * the GNU General Public License as published by the Free Software Foundation; either
  11.  * version 3 of the License, or (at your option) any later version.
  12.  *
  13.  * rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  14.  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License along with this program.
  18.  * If not, see <http://www.gnu.org/licenses/>.
  19.  */
  20.  
  21. #include "main.h"
  22. #include "advance_map.h"
  23. #include "interpolation.h"
  24. #include "efilib2.h"
  25. #include "engine_configuration.h"
  26. #include "engine_math.h"
  27.  
  28. EXTERN_ENGINE;
  29.  
  30. static ign_Map3D_t advanceMap;
  31. static ign_Map3D_t iatAdvanceCorrectionMap;
  32. static int knockCount;
  33.  
  34. static const float iatTimingRpmBins[IGN_LOAD_COUNT] = {880, 1260,   1640,   2020,   2400,   2780,   3000,   3380,   3760,   4140,   4520,   5000,   5700,   6500,   7200,   8000};
  35.  
  36. //880   1260    1640    2020    2400    2780    3000    3380    3760    4140    4520    5000    5700    6500    7200    8000
  37. static const ignition_table_t defaultIatTiming = {
  38.         { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2},
  39.         { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2},
  40.         { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2},
  41.         { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2},
  42.         {3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 2, 2, 2, 2, 2},
  43.         { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2},
  44.         { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0},
  45.         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  46.         { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  47.         { 0, 0, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9, -0.9},
  48.         { -3.3, -3.4, -4.9, -4.9, -4.9, -4.9, -4.4, -4.4, -4.4, -4.4, -4.4, -0.9, -0.9, -0.9, -0.9, -0.9},
  49.         { -4.4, -4.9, -5.9, -5.9, -5.9, -5.9, -4.9, -4.9, -4.9, -4.9, -4.9, -2.4, -2.4, -2.4, -2.4, -2.4},
  50.         { -4.4, -4.9, -5.9, -5.9, -5.9, -5.9, -4.9, -4.9, -4.9, -4.9, -4.9, -2.9, -2.9, -2.9, -2.9, -2.9},
  51.         {-4.4, -4.9, -5.9, -5.9, -5.9, -5.9, -4.9, -4.9, -4.9, -4.9, -4.9, -3.9, -3.9, -3.9, -3.9, -3.9},
  52.         {-4.4, -4.9, -5.9, -5.9, -5.9, -5.9, -4.9, -4.9, -4.9, -4.9, -4.9, -3.9, -3.9, -3.9, -3.9, -3.9},
  53.         {-4.4, -4.9, -5.9, -5.9, -5.9, -5.9, -4.9, -4.9, -4.9, -4.9, -4.9, -3.9, -3.9, -3.9, -3.9, -3.9},
  54. };
  55.  
  56. bool_t isStep1Condition(int rpm DECLARE_ENGINE_PARAMETER_S) {
  57.     return  boardConfiguration->enabledStep1Limiter && rpm >= engineConfiguration->step1rpm;
  58. }
  59.  
  60. /**
  61.  * @return ignition timing angle advance before TDC
  62.  */
  63. static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
  64.     engine->m.beforeAdvance = GET_TIMESTAMP();
  65.     if (cisnan(engineLoad)) {
  66.         warning(OBD_PCM_Processor_Fault, "NaN engine load");
  67.         return NAN;
  68.     }
  69.     efiAssert(!cisnan(engineLoad), "invalid el", NAN);
  70.     efiAssert(!cisnan(engineLoad), "invalid rpm", NAN);
  71.     engine->m.beforeZeroTest = GET_TIMESTAMP();
  72.     engine->m.zeroTestTime = GET_TIMESTAMP() - engine->m.beforeZeroTest;
  73.  
  74.     if (isStep1Condition(rpm PASS_ENGINE_PARAMETER)) {
  75.         return engineConfiguration->step1timing;
  76.     }
  77.  
  78.     float iatCorrection = iatAdvanceCorrectionMap.getValue(engine->engineState.clt, (float) rpm);
  79.  
  80.     float result = advanceMap.getValue(engineLoad, (float) rpm) + iatCorrection - engine->knockCount;
  81.     engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance;
  82.     return result;
  83. }
  84.  
  85. angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
  86.     angle_t angle;
  87.     if (isCrankingR(rpm)) {
  88.         angle = engineConfiguration->crankingTimingAngle;
  89.     } else {
  90.         angle = getRunningAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER);
  91.     }
  92.     angle -= engineConfiguration->ignitionBaseAngle;
  93.     fixAngle(angle);
  94.     return angle;
  95. }
  96.  
  97. void setDefaultIatTimingCorrection(DECLARE_ENGINE_PARAMETER_F) {
  98.     setTableBin2(config->ignitionIatCorrLoadBins, IGN_LOAD_COUNT, -40, 110, 1);
  99.     memcpy(config->ignitionIatCorrRpmBins, iatTimingRpmBins, sizeof(iatTimingRpmBins));
  100.     copyTimingTable(defaultIatTiming, config->ignitionIatCorrTable);
  101. }
  102.  
  103. void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F) {
  104.     advanceMap.init(config->ignitionTable, config->ignitionLoadBins,
  105.             config->ignitionRpmBins);
  106.     iatAdvanceCorrectionMap.init(config->ignitionIatCorrTable, config->ignitionIatCorrLoadBins,
  107.             config->ignitionIatCorrRpmBins);
  108. }