fome-fw/firmware/controllers/algo/advance_map.cpp

64 lines
2.0 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file advance_map.c
*
* @date Mar 27, 2013
2015-01-12 15:04:10 -08:00
* @author Andrey Belomutskiy, (c) 2012-2015
2014-08-29 07:52:33 -07:00
*
* This file is part of rusEfi - see http://rusefi.com
*
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include "advance_map.h"
#include "interpolation.h"
2015-02-12 12:04:02 -08:00
#include "efilib2.h"
2014-08-29 07:52:33 -07:00
#include "engine_configuration.h"
#include "engine_math.h"
2014-11-25 08:04:15 -08:00
EXTERN_ENGINE;
2014-08-29 07:52:33 -07:00
static Map3D1616 advanceMap;
2014-11-25 08:04:15 -08:00
float getBaseAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
2014-09-13 13:04:13 -07:00
if (cisnan(engineLoad)) {
warning(OBD_PCM_Processor_Fault, "NaN engine load");
return NAN;
}
2014-08-29 07:52:33 -07:00
efiAssert(!cisnan(engineLoad), "invalid el", NAN);
efiAssert(!cisnan(engineLoad), "invalid rpm", NAN);
2015-02-12 12:04:02 -08:00
engine->m.beforeZeroTest = GET_TIMESTAMP();
engine->m.zeroTestTime = GET_TIMESTAMP() - engine->m.beforeZeroTest;
engine->m.beforeAdvance = GET_TIMESTAMP();
float result = advanceMap.getValue(engineLoad, engineConfiguration->ignitionLoadBins, (float) rpm,
2014-08-29 07:52:33 -07:00
engineConfiguration->ignitionRpmBins);
2015-02-12 12:04:02 -08:00
engine->m.advanceTime = GET_TIMESTAMP() - engine->m.beforeAdvance;
return result;
2014-08-29 07:52:33 -07:00
}
2014-11-12 13:05:43 -08:00
float getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_S) {
2014-08-29 07:52:33 -07:00
float angle;
if (isCrankingR(rpm)) {
2015-02-11 20:07:58 -08:00
angle = engineConfiguration->crankingTimingAngle;
2014-08-29 07:52:33 -07:00
} else {
2014-11-25 08:04:15 -08:00
angle = getBaseAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
}
2015-01-11 21:03:57 -08:00
angle -= engineConfiguration->ignitionBaseAngle;
2014-11-25 08:04:15 -08:00
fixAngle(angle);
2014-11-25 07:03:25 -08:00
return angle;
2014-08-29 07:52:33 -07:00
}
2014-11-25 08:04:15 -08:00
void prepareTimingMap(DECLARE_ENGINE_PARAMETER_F) {
2014-08-29 07:52:33 -07:00
advanceMap.init(engineConfiguration->ignitionTable);
}