Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions FilterOnePole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ void FilterOnePole::setFilter( FILTER_TYPE ft, float fc, float initialValue ) {
}

float FilterOnePole::input( float inVal ) {
long time = micros();
ElapsedUS = float(time - LastUS); // cast to float here, for math
long int time = micros();
long int ElapsedUS = time - LastUS; // stick to long int here, because of underflow with float on subtractions.
// (31+1 bits of long int compared to 23+1 bit of the mantissa of float)
LastUS = time; // update this now

// minimize the effect of an overflow of micros(), which happens every 70 Minutes.
if(ElapsedUS < 0)
{
ElapsedUS = 10; // do not set to zero!!! (division by zero)
}

// shift the data values
Ylast = Y;
X = inVal; // this is now the most recent input value
Expand Down