BMP085 oss=3 wrong reading

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi avrfreaks,

Few days ago I got a reading from my pressure transmiter BMP085.
It looks ok when I set OSS from 0 to 2. With this setting I get P~991.50 hPa, however if I set oversampling to 3 the reading goes strange. With oss=3 I get P~742.07 hPa.
Did you use oss=3 with luck?
Below I paste some code, maybe You can see anything because I out of ideas.

long TWI_CzujnikBMP085_GetPressure(void)
{
	long x1, x2, b6, x3, b3, Pressure, UP = 0;
	unsigned long b4, b7 ;
	unsigned char LCD_string[7];
	
	TWI_StartSLA(PRESS_TEMP + TW_WRITE);
	TWI_Write(0xF4);						//write to register F4
	TWI_Write(0x34+(OSS<<6));				//pressure ultra high resolution
	//TWI_Write(0xF4);
	TWI_Stop();
	
	_delay_ms(30);							//pressure conversion time 24.5ms
	
	TWI_StartSLA(PRESS_TEMP + TW_WRITE);
	TWI_Write(0xF6);						//read from register
	//TWI_Stop();
	TWI_StartSLA(PRESS_TEMP + TW_READ);
	
	UP = (((unsigned long)TWI_ReadACK() << 16) + ((unsigned long)TWI_ReadACK() <<8) + (unsigned long)TWI_ReadNCK()) >> (8 - OSS);
	TWI_Stop();

	b6 = b5 - 4000;
	x1 = (b2 * (b6 * b6 >> 12)) >> 11;
	x2 = ac2 * b6 >> 11;
	x3 = x1 + x2;
	b3 = ((((long)ac1 * 4 + x3)<<OSS) + 2)/4;
	x1 = ac3 * b6 >> 13;
	x2 = (b1 * (b6 * b6 >> 12)) >> 16;
	x3 = ((x1 + x2) + 2) >> 2;
	b4 = (ac4 * (unsigned long) (x3 + 32768)) >> 15;
	
	b7 = (((unsigned long) UP - b3) * (50000 >> OSS));
	Pressure = b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2;
	x1 = (Pressure >> 8) * (Pressure >> 8);
	
	x1 = (x1 * 3038) >> 16;
	x2 = (-7357 * Pressure) >> 16;
	Pressure = Pressure + ((x1 + x2 + 3791) >> 4);


	
	//LCD_GoTo(0,1);
	//ltoa(Pressure, LCD_string, 10);
	//LCD_WriteText(LCD_string);

	return Pressure;
}

best regards

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It could be you have one of the faulty breakout boards from 'SF'. These do not have Vddd connected (pin 4). Leakage from Vdda and your TWI pull-ups can accumulate enough charge to support 'short' conversions, so the board seems to work, but will exhibit 'strange' behavior, like this.

Beyond that, are you sure about your CPU clock? In other words, are you sure the 30 millisecond delay is really 30 mS ? It might be better to test the EOC pin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I will try with making delay time longer.

Another question is:
how do you do avaraging/filtering samples from some period of time?
Did you try ODE with integral transfer function?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The best way IMHO: Have you tried comparing each step (each calculation) against the values specified in the datasheet? A complete example with all final and intermediate values are specified in there.
This might reveal some suttle difference which is proportionally enlarged when using OSS 3 versus 2 (this is very plausible since OSS have great important on the final result).
Also, do not hand-calculate it but let the AVR calculate every value and display them, since you might also experience integer overflows somewhere, which are hidden with hand-calculators.

At least this method revealed my typos when I wrote my source for the BMP-085.