miata vvt trigger decoding is broken #1145

This commit is contained in:
rusefi 2020-02-14 13:02:27 -05:00
parent a2c4b36edc
commit e9a3b218c4
4 changed files with 23 additions and 10 deletions

View File

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

View File

@ -361,9 +361,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
// That's easy - trigger cycle matches engine cycle
triggerIndexForListeners = triggerState.getCurrentIndex();
} else {
// todo: should this logic reuse getCycleDuration?
bool isCrankDriven = operationMode == FOUR_STROKE_CRANK_SENSOR || operationMode == FOUR_STROKE_SYMMETRICAL_CRANK_SENSOR;
int crankDivider = isCrankDriven ? 2 : 4;
int crankDivider = operationMode == FOUR_STROKE_CRANK_SENSOR ? 2 : SYMMETRICAL_CRANK_SENSOR_DIVIDER;
int crankInternalIndex = triggerState.getTotalRevolutionCounter() % crankDivider;

View File

@ -12,6 +12,8 @@
#include "trigger_decoder.h"
#include "trigger_central_generated.h"
class Engine;
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
@ -79,3 +81,4 @@ void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#define SYMMETRICAL_CRANK_SENSOR_DIVIDER 4

View File

@ -123,12 +123,24 @@ TEST(sensors, testNB2CamInput) {
eth.setTriggerType(TT_ONE PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM";
for (int i = 0; i < 5;i++) {
eth.fireRise(50);
for (int i = 0; i < 7;i++) {
eth.fireRise(25);
ASSERT_EQ( 0, GET_RPM()) << "testNB2CamInput RPM";
}
eth.fireRise(25);
// first time we have RPM
ASSERT_EQ(1200, GET_RPM()) << "testNB2CamInput RPM";
// this would be ignored since we only consude one kind the other kind of fronts here
int totalRevolutionCountBeforeVvtSync = 10;
// need to be out of VVT sync to see VVT sync in action
eth.fireRise(25);
eth.fireRise(25);
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
ASSERT_TRUE((totalRevolutionCountBeforeVvtSync % SYMMETRICAL_CRANK_SENSOR_DIVIDER) != 0);
eth.moveTimeForwardUs(MS2US(3)); // shifting VVT phase a few anlges
// this would be ignored since we only consume the other kind of fronts here
hwHandleVvtCamSignal(TV_FALL, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX);
eth.moveTimeForwardUs(MS2US(20));
// this would be be first VVT signal - gap duration would be calculated against 'DEEP_IN_THE_PAST_SECONDS' initial value
@ -139,13 +151,13 @@ TEST(sensors, testNB2CamInput) {
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_FLOAT_EQ(0, engine->triggerCentral.getVVTPosition());
ASSERT_EQ(5, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
ASSERT_EQ(totalRevolutionCountBeforeVvtSync, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
eth.moveTimeForwardUs(MS2US(130));
// this third important front would give us first comparison between two real gaps
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt() PASS_ENGINE_PARAMETER_SUFFIX);
ASSERT_NEAR(-46, engine->triggerCentral.getVVTPosition(), EPS3D);
ASSERT_NEAR(-67.6, engine->triggerCentral.getVVTPosition(), EPS3D);
// actually position based on VVT!
ASSERT_EQ(8, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
ASSERT_EQ(totalRevolutionCountBeforeVvtSync + 2, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
}