Exponential Filter Issue

Hi all,

I’ve been trying to smooth the values from pressure sensor MPX5100AP, which is connected to external 16 bit ADC ADS1115. I am trying the exponential filter:

But the values are still spiky, although I use alpha = 0.1.

The code:

void setup()
 {
  Wire.beginTransmission(ADS1115);
  Wire.write(0x00);
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom (ADS1115, 2); 
  if(2 <= Wire.available())
  SSS = Wire.read() << 8 | Wire.read();
  Wire.endTransmission();
  delay (10);
  VSSS = SSS; //initial value SSS is being equaled to smoothed value for loop function
}

void loop() {
  Wire.beginTransmission(ADS1115);
  Wire.write(0x00);
  Wire.endTransmission();
  delay (10);
  Wire.requestFrom (ADS1115, 2);
  if(2 <= Wire.available())
  SSS = Wire.read() << 8 | Wire.read();
  Wire.endTransmission();
  delay (10);
  VSSS = LRSS*SSS+(1-LRSS)*VSSS; // LRSS = alpha;
}

Maybe you can suggest me something else? But as I see for other people it works well.

Thanks.

Use smaller values of alpha.

Since you did not post all of your code, it is not possible to determine whether you made other mistakes, like using integer calculations when you should be using floats.

jremington:
Since you did not post all of your code, it is not possible to determine whether you made other mistakes, like using integer calculations when you should be using floats.

Nope. Everything is in float. But yeah, I thought, that 0.1 is already very small, but I guess for 16 bit accuracy the number should be even smaller. I’ll try that.

I tried and now my values are constantly going up.

Post ALL your code.

Ok.

int SSS = 0; 
float SSV = 0;
float VPZS = 4.096/32768; 
float StS = 0;
float VSSV = 0;
float LR = 0.02;


 void setup ()
{
  Wire.begin();
  Wire.beginTransmission(ADS1115); 
  Wire.write(0x01);
  Wire.write(0xC2);
  Wire.write(0x85); 
  Wire.endTransmission(); 
  delay(10);
  Wire.beginTransmission(ADS1115);
  Wire.write(0x00); 
  Wire.endTransmission();
  delay(10);
  Wire.requestFrom (ADS1115, 2); 
  if(2 <= Wire.available())
  SSS = Wire.read() << 8 | Wire.read(); 
  Wire.endTransmission();
  delay (10);
  SSV = (float)SSS*VPZS; // converting to volts
  VSSV = SSV; //equaled to smoothed value
}

void loop()
{
 Wire.beginTransmission(ADS1115);
  Wire.write(0x00);
  Wire.endTransmission();
  delay (10);
  Wire.requestFrom (ADS1115, 2);
  if(2 <= Wire.available())
  SSS = Wire.read() << 8 | Wire.read(); 
  Wire.endTransmission();
  delay (10);
  SSV = (float)SSS*VPZS; 
  VSSV = LR*SSV+(1-LR)*VSSV; 
  StS = (VSSV+(5.0*0.095))/(5.0*0.009); // pressure
  delay(100);
 }

Can you post some raw data so we can see what you are trying to smooth.

Since you do no printing, how do you know that smoothing is not working?

Please post code that actually demonstrates the problem, with raw data as suggested above.