PIC plus-5110 LCD-GPS-BMP280-HMC5983

jjw

Member
That looks right now !
Dorset air pressure 1025mb.
mb = Pa / 100

There is formula for height based on air pressure.
I will look for it.

camerart

Active Member
That looks right now !
Dorset air pressure 1025mb.
mb = Pa / 100

There is formula for height based on air pressure.
I will look for it.
Hi J,
Multiply the atmospheric pressure in hectopascals times 100 using a scientific calculator. For example, the pressure is 1037 hPa: 1037 x 100 = 103700.

Divide your answer by 101325 using a scientific calculator. For example, 103700/101325 = 1.2034.

Take the natural log of your answer using a scientific calculator. For example, ln (1.2034) = 0.02316.

Multiply your answer times 287.053 using a scientific calculator. For example, 0.02316 x 287.053 = 6.6507.

Multiply your answer times the product of the temperature plus 459.67 and 5/9 using a scientific calculator. For example, 6.6507 x [(37 + 459.67) x 5/9] = 1835.116.

Divide your answer by -9.8 using a scientific calculator. For example, 1835.116/-9.8 = -187.25. Your altitude is -187.25 meters, or 187.25 meters below sea level.

I'm not sure I'll be doing much diving though C

camerart

Active Member
Hi,
I've looked at the settings, and I think I have the best to suit me, but I'm getting readings that vary XXXXX0 to 1 ish.
How can I make an average of 10 readings, by adding the new reading on each LOOP, dividing by 10, subtracting one reading, and so on?
C.

ericgibbs

Well-Known Member
hi C,
You need a ring buffer for your averaging.

Be aware of the size of a 10 reading Sum, does not exceed the LONG or SINGLE type.
E

ericgibbs

Well-Known Member
hi C,
This is demo play Basic of the buffer, use the Sim and PORTA.0 ADC to vary the test value.
I have used two Proc' to make it easier to follow.
NOTE: the latency [ delay] in getting the final Average result;
For a 10 long array its 10 readings.!

E

Attachments

• 8.5 KB Views: 7
• 1.8 KB Views: 9

jjw

Member
Hi,
I've looked at the settings, and I think I have the best to suit me, but I'm getting readings that vary XXXXX0 to 1 ish.
How can I make an average of 10 readings, by adding the new reading on each LOOP, dividing by 10, subtracting one reading, and so on?
C.
You can specify oversampling / filtering in control register 0XF4.
It can reduce noise in pressure to about 0.2 Pa ~ about 2cm in height.
Do you need absolute height or change in height?
I found a formula for height vs. pressure and temperature:

h = 29.26 × T × ln ( P0 / P )
T is temperature in kelvins, P0 pressure at ground level.
For example at T=22 C ( 295.15 K )
h~8636 × ln (P0 / P )
and 12 Pa change is about 1m.

camerart

Active Member
You can specify oversampling / filtering in control register 0XF4.
It can reduce noise in pressure to about 0.2 Pa ~ about 2cm in height.
Do you need absolute height or change in height?
I found a formula for height vs. pressure and temperature:

h = 29.26 × T × ln ( P0 / P )
T is temperature in kelvins, P0 pressure at ground level.
For example at T=22 C ( 295.15 K )
h~8636 × ln (P0 / P )
and 12 Pa change is about 1m.
Hi J,
Thanks.
Here are the settings given in #483, this is why I am trying to average 10x READings.
PORTD.5 = 0 'CHIP SELECT BMP280 ON
SPISend 0x74 'WRITE 0xF4 Control CTRL_MEAS reg addr
SPISend 0x5f '%01011111 T/ON P/ON 't_x2 p_x16 Normal Mode
PORTD.5 = 1 'CHIP SELECT BMP280 OFF
EDIT: Error corrected (Hopefully)
C.

Last edited:

camerart

Active Member
hi C,
This is demo play Basic of the buffer, use the Sim and PORTA.0 ADC to vary the test value.
I have used two Proc' to make it easier to follow.
NOTE: the latency [ delay] in getting the final Average result;
For a 10 long array its 10 readings.!

E
Hi E,
I'm going to try it straight into the program, instead of the SIM, I can compare the results with a none AVE program, and your results.

What was the latency, or more to the point, what would you expect it to be in a working program?

EDIT: Would you be good enough to convert it to an actual program section please? With 'pr' as the READing, instead of SAMPLE.
C

Last edited:

ericgibbs

Well-Known Member
hi C,
I would need your latest working program.
E

camerart

Active Member
Hi E,
Here's my attempt but I don't think it's working properly.
I get READings between 103069 to 77.
C.

Attachments

• 9.1 KB Views: 8

jjw

Member
You have as buffer index and buffer value the same variable = pr ( word ) and pressure = pr ( single ).
Does'nt compiler give error messages?

jpanhalt

Well-Known Member
eric
I hope this doesn't pull the thread OT, but I do not quite see what you are doing in Post #486: The first value (68) is easy to get. With some crazy assumptions, I get the next value. But I cannot get the third value. Does it ever settle to 682?

My first impression from your code was a simple moving average (FIR):

Code:
'sum all 10 values of the ring bfr
For x = 0 To 9
sum = sum + mybfr(x)
Next x
average = sum / 10
But there seems more to it than that. My main reference for the math is this: http://www.analog.com/media/en/training-seminars/design-handbooks/MixedSignal_Sect6.pdf Specifically, I am referencing Figure 6.8 in that link: Can you explain, perhaps by a worked example, how you get the highlighted value? Also, why it doesn't seem to settle on 682?

Regards, John

camerart

Active Member
You have as buffer index and buffer value the same variable = pr ( word ) and pressure = pr ( single ).
Does'nt compiler give error messages?
Hi J,
No error, the compiler probably accepted the last order.
I sense that there are errors in my efforts, but I'm not much of a programmer today.
C.

jjw

Member
Anyway the mybfr(), sum, average should be singles as you calculate with pressure values,, which are singles.

jjw

Member
eric
I hope this doesn't pull the thread OT, but I do not quite see what you are doing in Post #486:

View attachment 110718

The first value (68) is easy to get. With some crazy assumptions, I get the next value. But I cannot get the third value. Does it ever settle to 682?

My first impression from your code was a simple moving average (FIR):

Code:
'sum all 10 values of the ring bfr
For x = 0 To 9
sum = sum + mybfr(x)
Next x
average = sum / 10
But there seems more to it than that. My main reference for the math is this: http://www.analog.com/media/en/training-seminars/design-handbooks/MixedSignal_Sect6.pdf Specifically, I am referencing Figure 6.8 in that link:

View attachment 110719

Can you explain, perhaps by a worked example, how you get the highlighted value? Also, why it doesn't seem to settle on 682?

Regards, John
In the basic program ( msg#486 ) the buffer size is 9, should be 10, index 0- 9

camerart

Active Member
Hi,
Here's the latest with corrections MARKED ??????????? ###############
Gives readings between 102952 to 61

EDIT: Should line: 'If index > 9 Then index = 0' also be 10?
EDITEDIT: I tried it and it looks like it's trying, but it could be my imagination.

C

Attachments

• 9.3 KB Views: 6
Last edited:

camerart

Active Member
eric
I hope this doesn't pull the thread OT, but I do not quite see what you are doing in Post #486:

View attachment 110718

The first value (68) is easy to get. With some crazy assumptions, I get the next value. But I cannot get the third value. Does it ever settle to 682?

My first impression from your code was a simple moving average (FIR):

Code:
'sum all 10 values of the ring bfr
For x = 0 To 9
sum = sum + mybfr(x)
Next x
average = sum / 10
But there seems more to it than that. My main reference for the math is this: http://www.analog.com/media/en/training-seminars/design-handbooks/MixedSignal_Sect6.pdf Specifically, I am referencing Figure 6.8 in that link:

View attachment 110719

Can you explain, perhaps by a worked example, how you get the highlighted value? Also, why it doesn't seem to settle on 682?

Regards, John
Hi J2,
I'm guessing that when E, simulated these numbers, he set the INPUT and watched the result. On the PCB the INPUT is changing all of the time, so I assume that eventually, the result would show 682 using the SIM, but not on the PCB.

The D/S strongly suggests that 'Burst READ' is used. This is to avoid READs of different columns happening as one of them rolls over, so between 09 and 10 could READ 19. or 190 with a different column.

Is this a possible reason that the READings jump about a bit?
C.

ericgibbs

Well-Known Member
hi,
Using Singles in the program as a replacement for Words is not a problem.
The posted Basic program was to show only the principle of averaging a ring buffer.

The final value does converge, this modified program shows that, also has only 5 index's. Uses 12345.56 as the sample value.

Attachments

• 8.9 KB Views: 7
• 1.8 KB Views: 6

jjw

Member
Hi J2,
I'm guessing that when E, simulated these numbers, he set the INPUT and watched the result. On the PCB the INPUT is changing all of the time, so I assume that eventually, the result would show 682 using the SIM, but not on the PCB.

The D/S strongly suggests that 'Burst READ' is used. This is to avoid READs of different columns happening as one of them rolls over, so between 09 and 10 could READ 19. or 190 with a different column.

Is this a possible reason that the READings jump about a bit?
C.
It is normal, that they jump a bit.
About RMS noise in the datasheet:
Standard resolution 2.1 Pa
with 16x oversampling 0.3 Pa

Ultrahigh resolution 1.3 Pa and 0.2 Pa

Have you looked at the jumps, how big they are at worst?
If there are some high peeks, median filter might be better.
It is simple: take a number of samples, sort them from lowest to highest and choose the middle one. 