Show Posts

Pages: 1 [2] 3 4 ... 189

21

Using Arduino / Programming Questions / Re: VirtualWire on arduino Due

on: July 27, 2014, 02:37:30 pm

Two likely problems:
where it says something is not declared in this scope, the usual reason is that the compiler cannot find an #include file, which is missing, or in the wrong place.
second possible reason, all those register names may be specific to the 8bit processors, and that library that you are trying to use might not be usable on the 32bit Due processor.



25

Using Arduino / Sensors / Re: Barometric Presure sensor BMP180

on: July 26, 2014, 10:35:55 pm

It appears (supposedly) as a constant in the code, perhaps it was intended to be a configurable number.
In the actual code, it's use is related to leastsignificantbit rounding, and not as an actual numerical context at all. If you add 32768, and then right shift 15 bits, that is what it does.



26

Using Arduino / Sensors / Re: Barometric Presure sensor BMP180

on: July 26, 2014, 10:20:10 pm

** Karma: 58 Posts: 2794 View Profile Email Personal Message (Offline) Re: Barometric Presure sensor BMP180 « Reply #31 on: Today at 01:29:29 am » Bigger Bigger Smaller Smaller Reset Reset Reply with quoteQuote Modify messageModify Remove messageRemove Looking at the code I have here, I seem to have two different versions of the temperature calculation, which are different. I had to "fix" it, for some reason, which I don't fully recall now. I am not 100% certain, but it appears that the first calculation is the wrong one, and the second one is correct. Code: X1 = ((latest_raw_temp  (int32_t)ac6) * (int32_t)ac5) >> 15; X2 = ((int32_t)mc << 11)  (X1 + md)/2; // round up X2 /= (X1 + md); B5 = X1 + X2; Code: int32_t X1 = ((latest_raw_temp  (int32_t)ac6) * (int32_t)ac5) >> 15; int32_t X2 = ((int32_t)mc << 11) / (X1 + (int32_t)md); int32_t B5 = X1 + X2; float temp = (float)((B5 + >> 4); temp /= 10; // divide by 10 This algorithm may have been intended for a device with a 32 bit int type. Two further comments on this. The mc<<11 will also potentially overflow if it is done as a 16 bit calculation. It is important to have the cast in this line to ensure this happens. The apparent big difference between the two calculations of X2 is not what it seems. The result will actually the almost the same. By subtracting half of the amount you are going to divide by, before doing the division, this has the effect of correcting the rounding of the least significant bit in the result of the division.



28

Using Arduino / Sensors / Re: Barometric Presure sensor BMP180

on: July 26, 2014, 09:58:47 pm

This is the code which I was using B6 = latest_B5  4000; X1 = ((int32_t)b2 * ( (B6 * B6)>>12 )) >> 11; X2 = ((int32_t)ac2 * B6) >> 11; X3 = X1 + X2; B3 = ((((int32_t)ac1*4 + X3) << oversampling) + 2) / 4;
X1 = ((int32_t)ac3 * B6) >> 13; X2 = ((int32_t)b1 * ((B6 * B6) >> 12)) >> 16; X3 = ((X1 + X2) + 2) >> 2; B4 = ((uint32_t)ac4 * (uint32_t)(X3 + 32768)) >> 15; B7 = ((uint32_t)latest_raw_pressure  B3) * (uint32_t)( 50000UL >> oversampling );



29

Using Arduino / Sensors / Re: Barometric Presure sensor BMP180

on: July 26, 2014, 09:57:17 pm

The sensors which have a big value for AC1, don't work, because AC1 x 4 will overflow in the calculation of B3, because it is performing a 16 bit calculation there, unless you tell it otherwise.
But if the sensor happens to have small value of AC1, you don't get this problem, because it still fits in 16 bits.
You will observe that in Bosch's calculation, AC1 is 408 and Leo's example ha 408 also, but Jacob and Erhja have 8000 and 9000 there, which will overflow when multiplied by 4.



30

Using Arduino / Sensors / Re: Barometric Presure sensor BMP180

on: July 26, 2014, 08:29:29 pm

Looking at the code I have here, I seem to have two different versions of the temperature calculation, which are different. I had to "fix" it, for some reason, which I don't fully recall now. I am not 100% certain, but it appears that the first calculation is the wrong one, and the second one is correct. X1 = ((latest_raw_temp  (int32_t)ac6) * (int32_t)ac5) >> 15; X2 = ((int32_t)mc << 11)  (X1 + md)/2; // round up X2 /= (X1 + md); B5 = X1 + X2;
int32_t X1 = ((latest_raw_temp  (int32_t)ac6) * (int32_t)ac5) >> 15; int32_t X2 = ((int32_t)mc << 11) / (X1 + (int32_t)md); int32_t B5 = X1 + X2; float temp = (float)((B5 + 8) >> 4); temp /= 10; // divide by 10
This algorithm may have been intended for a device with a 32 bit int type.



