Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
890279b7
Commit
890279b7
authored
Aug 25, 2014
by
Matthieu Cattin
Committed by
Projects
Sep 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sw: add altitude to pressure helper function and example for altitude calibration.
parent
9d4027e3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
8 deletions
+68
-8
main.c
sw/alti_test/main.c
+21
-4
altimeter.c
sw/common/drivers/altimeter.c
+32
-2
altimeter.h
sw/common/drivers/altimeter.h
+15
-2
No files found.
sw/alti_test/main.c
View file @
890279b7
...
...
@@ -50,6 +50,8 @@ int main(void)
double
temp
=
0
;
double
pressure
=
0
;
double
altitude
=
0
;
double
pressure_calc
;
double
pressure_comp
;
/* Setup SysTick Timer for 1 msec interrupts */
if
(
SysTick_Config
(
CMU_ClockFreqGet
(
cmuClock_CORE
)
/
1000
))
while
(
1
);
...
...
@@ -70,25 +72,40 @@ int main(void)
text
(
&
font_helv11
,
5
,
10
,
str
);
lcd_update
();
err
=
alti_get_temp_pressure
(
&
temp
,
&
pressure
,
true
);
err
=
alti_altitude2mbar
(
&
pressure_calc
,
440
);
pressure_comp
=
pressure
-
pressure_calc
;
while
(
1
)
{
err
=
alti_get_temp_pressure
(
&
temp
,
&
pressure
,
true
);
sprintf
(
str
,
"temp: %f C"
,
temp
);
text
(
&
font_helv11
,
5
,
20
,
str
);
sprintf
(
str
,
"pressure: %f mbar"
,
pressure
);
sprintf
(
str
,
"pressure: %
5.2
f mbar"
,
pressure
);
text
(
&
font_helv11
,
5
,
30
,
str
);
err
=
alti_mbar2altitude
(
pressure
,
&
altitude
);
sprintf
(
str
,
"altitude: %f m"
,
altitude
);
sprintf
(
str
,
"altitude: %
4.2
f m"
,
altitude
);
text
(
&
font_helv11
,
5
,
40
,
str
);
sprintf
(
str
,
"p calc: %5.2f mbar"
,
pressure_calc
);
text
(
&
font_helv11
,
5
,
60
,
str
);
sprintf
(
str
,
"p comp: %5.2f mbar"
,
pressure_comp
);
text
(
&
font_helv11
,
5
,
70
,
str
);
err
=
alti_mbar2altitude
(
pressure
-
pressure_comp
,
&
altitude
);
sprintf
(
str
,
"alti comp: %4.2f m"
,
altitude
);
text
(
&
font_helv11
,
5
,
50
,
str
);
//sprintf(str, "err: 0x%02x", err);
//text(&font_helv11, 5, 50, str);
lcd_update
();
//Delay(1000);
box
(
5
,
10
,
128
,
50
,
0
);
//
lcd_clear();
//
box(5, 10, 128, 50, 0);
lcd_clear
();
}
...
...
sw/common/drivers/altimeter.c
View file @
890279b7
...
...
@@ -281,8 +281,8 @@ uint8_t alti_get_temp_pressure(double* temp, double* pressure, bool filter)
* source: Intersema (Meas-spec), AN501 - Using MS5534 for Altimeters and Barometers
*
* @param pressure : Pressure in millibars.
* @param altitude : Altitude in me
r
ters.
* @return
i2c error code or crc error (-1), 0 if no errors
.
* @param altitude : Altitude in meters.
* @return
coefficient index
.
*/
uint8_t
alti_mbar2altitude
(
double
pressure
,
double
*
altitude
)
{
...
...
@@ -300,3 +300,33 @@ uint8_t alti_mbar2altitude(double pressure, double* altitude)
return
i
;
}
/**
* @brief Helper function to convert from altitude to mbar.
*
* Uses piecewise interpolation of pressure to altitude conversion formula (troposhere model)
* h = 288.15/0.065 * (1 - (p/1013.25)^(0.065*287.052/9.81))
* source: Intersema (Meas-spec), AN501 - Using MS5534 for Altimeters and Barometers
*
* @param pressure : Pressure in millibars.
* @param altitude : Altitude in meters.
* @return coefficient index.
*/
uint8_t
alti_altitude2mbar
(
double
*
pressure
,
double
altitude
)
{
uint8_t
i
;
for
(
i
=
0
;
i
<
P2A_COEFF_SIZE
;
i
++
)
{
if
(
altitude
>
p2a_coeff
[
i
][
3
])
{
i
--
;
break
;
}
}
*
pressure
=
(
p2a_coeff
[
i
][
0
]
+
(
p2a_coeff
[
i
][
3
]
-
altitude
)
*
pow
(
2
,
11
)
/
p2a_coeff
[
i
][
2
])
/
10
;
return
i
;
}
sw/common/drivers/altimeter.h
View file @
890279b7
...
...
@@ -83,10 +83,23 @@ uint8_t alti_get_temp_pressure(double* temp, double* pressure, bool filter);
* source: Intersema (Meas-spec), AN501 - Using MS5534 for Altimeters and Barometers
*
* @param pressure : Pressure in millibars.
* @param altitude : Altitude in me
r
ters.
* @return
i2c error code or crc error (-1), 0 if no errors
.
* @param altitude : Altitude in meters.
* @return
coefficient index
.
*/
uint8_t
alti_mbar2altitude
(
double
pressure
,
double
*
altitude
);
/**
* @brief Helper function to convert from altitude to mbar.
*
* Uses piecewise interpolation of pressure to altitude conversion formula (troposhere model)
* h = 288.15/0.065 * (1 - (p/1013.25)^(0.065*287.052/9.81))
* source: Intersema (Meas-spec), AN501 - Using MS5534 for Altimeters and Barometers
*
* @param pressure : Pressure in millibars.
* @param altitude : Altitude in meters.
* @return coefficient index.
*/
uint8_t
alti_altitude2mbar
(
double
*
pressure
,
double
altitude
);
#endif
/* ALTIMETER_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment