mirror of https://github.com/rusefi/rusefi-1.git
MAP phase sensing #3544
This commit is contained in:
parent
f1b8acb1fd
commit
e2fa1af527
|
@ -96,6 +96,8 @@ trigger_type_e getVvtTriggerType(vvt_mode_e vvtMode) {
|
||||||
return TT_VVT_NISSAN_VQ35;
|
return TT_VVT_NISSAN_VQ35;
|
||||||
case VVT_NISSAN_MR:
|
case VVT_NISSAN_MR:
|
||||||
return TT_NISSAN_MR18_CAM_VVT;
|
return TT_NISSAN_MR18_CAM_VVT;
|
||||||
|
case VVT_MAP_V_TWIN:
|
||||||
|
return TT_VVT_MAP_45_V_TWIN;
|
||||||
default:
|
default:
|
||||||
firmwareError(OBD_PCM_Processor_Fault, "getVvtTriggerType for %s", getVvt_mode_e(vvtMode));
|
firmwareError(OBD_PCM_Processor_Fault, "getVvtTriggerType for %s", getVvt_mode_e(vvtMode));
|
||||||
return TT_ONE; // we have to return something for the sake of -Werror=return-type
|
return TT_ONE; // we have to return something for the sake of -Werror=return-type
|
||||||
|
|
|
@ -94,7 +94,7 @@ static void startAveraging(scheduling_s *endAveragingScheduling) {
|
||||||
#if HAL_USE_ADC
|
#if HAL_USE_ADC
|
||||||
/**
|
/**
|
||||||
* This method is invoked from ADC callback.
|
* This method is invoked from ADC callback.
|
||||||
* @note This method is invoked OFTEN, this method is a potential bottle-next - the implementation should be
|
* @note This method is invoked OFTEN, this method is a potential bottleneck - the implementation should be
|
||||||
* as fast as possible
|
* as fast as possible
|
||||||
*/
|
*/
|
||||||
void mapAveragingAdcCallback(adcsample_t adcValue) {
|
void mapAveragingAdcCallback(adcsample_t adcValue) {
|
||||||
|
@ -107,6 +107,17 @@ void mapAveragingAdcCallback(adcsample_t adcValue) {
|
||||||
}
|
}
|
||||||
#endif // EFI_TUNER_STUDIO
|
#endif // EFI_TUNER_STUDIO
|
||||||
|
|
||||||
|
if (engineConfiguration->vvtMode[0] == VVT_MAP_V_TWIN) {
|
||||||
|
float voltage = adcToVoltsDivided(adcValue);
|
||||||
|
float instantMap = convertMap(voltage).value_or(0);
|
||||||
|
engine->triggerCentral.mapState.add(instantMap);
|
||||||
|
if (engine->triggerCentral.mapState.isPeak()) {
|
||||||
|
efitick_t stamp = getTimeNowNt();
|
||||||
|
hwHandleVvtCamSignal(TV_RISE, stamp, /*index*/0);
|
||||||
|
hwHandleVvtCamSignal(TV_FALL, stamp, /*index*/0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Calculates the average values from the ADC samples.*/
|
/* Calculates the average values from the ADC samples.*/
|
||||||
if (isAveraging) {
|
if (isAveraging) {
|
||||||
// with locking we will have a consistent state
|
// with locking we will have a consistent state
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include "pin_repository.h"
|
#include "pin_repository.h"
|
||||||
#include "local_version_holder.h"
|
#include "local_version_holder.h"
|
||||||
|
|
||||||
|
#define MAP_CAM_BUFFER 8
|
||||||
|
|
||||||
class Engine;
|
class Engine;
|
||||||
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp);
|
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp);
|
||||||
|
|
||||||
|
@ -32,6 +34,26 @@ public:
|
||||||
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES];
|
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MapState {
|
||||||
|
float current, previous, prevPrevious;
|
||||||
|
cyclic_buffer<float, MAP_CAM_BUFFER> mapBuffer;
|
||||||
|
|
||||||
|
void add(float value) {
|
||||||
|
// rotate state
|
||||||
|
prevPrevious = previous;
|
||||||
|
previous = current;
|
||||||
|
|
||||||
|
// add new value
|
||||||
|
mapBuffer.add(value);
|
||||||
|
current = mapBuffer.sum(MAP_CAM_BUFFER);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isPeak() {
|
||||||
|
return previous > prevPrevious && previous >= current;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maybe merge TriggerCentral and TriggerState classes into one class?
|
* Maybe merge TriggerCentral and TriggerState classes into one class?
|
||||||
* Probably not: we have an instance of TriggerState which is used for trigger initialization,
|
* Probably not: we have an instance of TriggerState which is used for trigger initialization,
|
||||||
|
@ -45,6 +67,8 @@ public:
|
||||||
void resetCounters();
|
void resetCounters();
|
||||||
void validateCamVvtCounters();
|
void validateCamVvtCounters();
|
||||||
|
|
||||||
|
MapState mapState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true if a recent configuration change has changed any of the trigger settings which
|
* true if a recent configuration change has changed any of the trigger settings which
|
||||||
* we have not adjusted for yet
|
* we have not adjusted for yet
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
#include "trigger_central.h"
|
||||||
#define MAP_CAM_BUFFER 8
|
|
||||||
|
|
||||||
static int getZigZag(int index) {
|
static int getZigZag(int index) {
|
||||||
index = index % 1000;
|
index = index % 1000;
|
||||||
|
@ -23,25 +22,6 @@ static int getZigZag(int index) {
|
||||||
return 1000 - index;
|
return 1000 - index;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MapState {
|
|
||||||
float current, previous, prevPrevious;
|
|
||||||
cyclic_buffer<float, MAP_CAM_BUFFER> mapBuffer;
|
|
||||||
|
|
||||||
void add(float value) {
|
|
||||||
// rotate state
|
|
||||||
prevPrevious = previous;
|
|
||||||
previous = current;
|
|
||||||
|
|
||||||
// add new value
|
|
||||||
mapBuffer.add(value);
|
|
||||||
current = mapBuffer.sum(MAP_CAM_BUFFER);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isPeak() {
|
|
||||||
return previous > prevPrevious && previous >= current;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(trigger, map_cam) {
|
TEST(trigger, map_cam) {
|
||||||
|
|
||||||
MapState state;
|
MapState state;
|
||||||
|
|
Loading…
Reference in New Issue