rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
TriggerNoiseFilter Class Reference

#include <trigger_central.h>

Collaboration diagram for TriggerNoiseFilter:
Collaboration graph
[legend]

Public Member Functions

void resetAccumSignalData ()
 
bool noiseFilter (efitick_t nowNt, TriggerDecoderBase *triggerState, trigger_event_e signal)
 

Data Fields

efitick_t lastSignalTimes [HW_EVENT_TYPES]
 
efitick_t accumSignalPeriods [HW_EVENT_TYPES]
 
efitick_t accumSignalPrevPeriods [HW_EVENT_TYPES]
 

Detailed Description

Definition at line 32 of file trigger_central.h.

Member Function Documentation

◆ noiseFilter()

bool TriggerNoiseFilter::noiseFilter ( efitick_t  nowNt,
TriggerDecoderBase triggerState,
trigger_event_e  signal 
)

This is used to filter noise spikes (interference) in trigger signal. See The basic idea is to use not just edges, but the average amount of time the signal stays in '0' or '1'. So we update 'accumulated periods' to track where the signal is. And then compare between the current period and previous, with some tolerance (allowing for the wheel speed change).

Returns
true if the signal is passed through.

Definition at line 592 of file trigger_central.cpp.

594 {
595 // todo: find a better place for these defs
598 // we process all trigger channels independently
599 TriggerWheel ti = triggerIdx[signal];
600 // falling is opposite to rising, and vise versa
601 trigger_event_e os = opposite[signal];
602
603 // todo: currently only primary channel is filtered, because there are some weird trigger types on other channels
604 if (ti != TriggerWheel::T_PRIMARY)
605 return true;
606
607 // update period accumulator: for rising signal, we update '0' accumulator, and for falling - '1'
608 if (lastSignalTimes[signal] != -1)
609 accumSignalPeriods[signal] += nowNt - lastSignalTimes[signal];
610 // save current time for this trigger channel
611 lastSignalTimes[signal] = nowNt;
612
613 // now we want to compare current accumulated period to the stored one
614 efitick_t currentPeriod = accumSignalPeriods[signal];
615 // the trick is to compare between different
616 efitick_t allowedPeriod = accumSignalPrevPeriods[os];
617
618 // but first check if we're expecting a gap
619 bool isGapExpected = TRIGGER_WAVEFORM(isSynchronizationNeeded) && triggerState->getShaftSynchronized() &&
620 (triggerState->currentCycle.eventCount[(int)ti] + 1) == TRIGGER_WAVEFORM(getExpectedEventCount(ti));
621
622 if (isGapExpected) {
623 // usually we need to extend the period for gaps, based on the trigger info
624 allowedPeriod *= TRIGGER_WAVEFORM(syncRatioAvg);
625 }
626
627 // also we need some margin for rapidly changing trigger-wheel speed,
628 // that's why we expect the period to be no less than 2/3 of the previous period (this is just an empirical 'magic' coef.)
629 efitick_t minAllowedPeriod = 2 * allowedPeriod / 3;
630 // but no longer than 5/4 of the previous 'normal' period
631 efitick_t maxAllowedPeriod = 5 * allowedPeriod / 4;
632
633 // above all, check if the signal comes not too early
634 if (currentPeriod >= minAllowedPeriod) {
635 // now we store this period as a reference for the next time,
636 // BUT we store only 'normal' periods, and ignore too long periods (i.e. gaps)
637 if (!isGapExpected && (maxAllowedPeriod == 0 || currentPeriod <= maxAllowedPeriod)) {
638 accumSignalPrevPeriods[signal] = currentPeriod;
639 }
640 // reset accumulator
641 accumSignalPeriods[signal] = 0;
642 return true;
643 }
644 // all premature or extra-long events are ignored - treated as interference
645 return false;
646}
current_cycle_state_s currentCycle
bool getShaftSynchronized() const
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES]
efitick_t accumSignalPeriods[HW_EVENT_TYPES]
efitick_t lastSignalTimes[HW_EVENT_TYPES]
TriggerWheel
trigger_event_e
@ SHAFT_SECONDARY_RISING
@ SHAFT_SECONDARY_FALLING
@ SHAFT_PRIMARY_FALLING
@ SHAFT_PRIMARY_RISING
size_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM]

Referenced by TriggerCentral::handleShaftSignal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetAccumSignalData()

void TriggerNoiseFilter::resetAccumSignalData ( )

Definition at line 48 of file trigger_central.cpp.

48 {
49 memset(lastSignalTimes, 0xff, sizeof(lastSignalTimes)); // = -1
50 memset(accumSignalPeriods, 0, sizeof(accumSignalPeriods));
52}

Referenced by onConfigurationChangeTriggerCallback(), RpmCalculator::setStopSpinning(), and TriggerCentral::TriggerCentral().

Here is the caller graph for this function:

Field Documentation

◆ accumSignalPeriods

efitick_t TriggerNoiseFilter::accumSignalPeriods[HW_EVENT_TYPES]

Definition at line 40 of file trigger_central.h.

Referenced by noiseFilter(), and resetAccumSignalData().

◆ accumSignalPrevPeriods

efitick_t TriggerNoiseFilter::accumSignalPrevPeriods[HW_EVENT_TYPES]

Definition at line 41 of file trigger_central.h.

Referenced by noiseFilter(), and resetAccumSignalData().

◆ lastSignalTimes

efitick_t TriggerNoiseFilter::lastSignalTimes[HW_EVENT_TYPES]

Definition at line 39 of file trigger_central.h.

Referenced by noiseFilter(), and resetAccumSignalData().


The documentation for this class was generated from the following files: