Skip to content

Commit a31906a

Browse files
BST-Github-Adminkegov
authored andcommitted
Fixed an issue where the wrong formula was used for the high range resistance calculation.
1 parent 90aebea commit a31906a

9 files changed

Lines changed: 65 additions & 27 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
1+
Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
22

33
BSD-3-Clause
44

bme68x.c

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* BSD-3-Clause
55
*
@@ -31,8 +31,8 @@
3131
* POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
* @file bme68x.c
34-
* @date 2021-03-18
35-
* @version v4.4.4
34+
* @date 2021-04-26
35+
* @version v4.4.5
3636
*
3737
*/
3838

@@ -59,8 +59,11 @@ static uint32_t calc_pressure(uint32_t pres_adc, const struct bme68x_dev *dev);
5959
/* This internal API is used to calculate the humidity in integer */
6060
static uint32_t calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev);
6161

62-
/* This internal API is used to calculate the gas resistance */
63-
static uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev);
62+
/* This internal API is used to calculate the gas resistance high */
63+
static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range);
64+
65+
/* This internal API is used to calculate the gas resistance low */
66+
static uint32_t calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev);
6467

6568
/* This internal API is used to calculate the heater resistance using integer */
6669
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev);
@@ -76,8 +79,11 @@ static float calc_pressure(uint32_t pres_adc, const struct bme68x_dev *dev);
7679
/* This internal API is used to calculate the humidity value in float */
7780
static float calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev);
7881

79-
/* This internal API is used to calculate the gas resistance value in float */
80-
static float calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev);
82+
/* This internal API is used to calculate the gas resistance high value in float */
83+
static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range);
84+
85+
/* This internal API is used to calculate the gas resistance low value in float */
86+
static float calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev);
8187

8288
/* This internal API is used to calculate the heater resistance value using float */
8389
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev);
@@ -922,8 +928,8 @@ static uint32_t calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev)
922928
return (uint32_t)calc_hum;
923929
}
924930

925-
/* This internal API is used to calculate the gas resistance */
926-
static uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev)
931+
/* This internal API is used to calculate the gas resistance low */
932+
static uint32_t calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev)
927933
{
928934
int64_t var1;
929935
uint64_t var2;
@@ -951,6 +957,23 @@ static uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, con
951957
return calc_gas_res;
952958
}
953959

960+
/* This internal API is used to calculate the gas resistance */
961+
static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range, const struct bme680_dev *dev)
962+
{
963+
uint32_t calc_gas_res;
964+
uint32_t var1 = UINT32_C(262144) >> gas_range;
965+
int32_t var2 = (int32_t)gas_res_adc - INT32_C(512);
966+
967+
var2 *= INT32_C(3);
968+
var2 = INT32_C(4096) + var2;
969+
970+
/* multiplying 10000 then dividing then multiplying by 100 instead of multiplying by 1000000 to prevent overflow */
971+
calc_gas_res = (UINT32_C(10000) * var1) / (uint32_t)var2;
972+
calc_gas_res = calc_gas_res * 100;
973+
974+
return calc_gas_res;
975+
}
976+
954977
/* This internal API is used to calculate the heater resistance value using float */
955978
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
956979
{
@@ -1070,8 +1093,8 @@ static float calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev)
10701093
return calc_hum;
10711094
}
10721095

1073-
/* This internal API is used to calculate the gas resistance */
1074-
static float calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev)
1096+
/* This internal API is used to calculate the gas resistance low value in float */
1097+
static float calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev)
10751098
{
10761099
float calc_gas_res;
10771100
float var1;
@@ -1094,6 +1117,21 @@ static float calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const
10941117
return calc_gas_res;
10951118
}
10961119

1120+
/* This internal API is used to calculate the gas resistance value in float */
1121+
static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range)
1122+
{
1123+
float calc_gas_res;
1124+
uint32_t var1 = UINT32_C(262144) >> gas_range;
1125+
int32_t var2 = (int32_t)gas_res_adc - INT32_C(512);
1126+
1127+
var2 *= INT32_C(3);
1128+
var2 = INT32_C(4096) + var2;
1129+
1130+
calc_gas_res = 1000000.0f * (float)var1 / (float)var2;
1131+
1132+
return calc_gas_res;
1133+
}
1134+
10971135
/* This internal API is used to calculate the heater resistance value */
10981136
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
10991137
{
@@ -1216,11 +1254,11 @@ static int8_t read_field_data(uint8_t index, struct bme68x_data *data, struct bm
12161254
data->humidity = calc_humidity(adc_hum, dev);
12171255
if (dev->variant_id == BME68X_VARIANT_GAS_HIGH)
12181256
{
1219-
data->gas_resistance = calc_gas_resistance(adc_gas_res_high, gas_range_h, dev);
1257+
data->gas_resistance = calc_gas_resistance_high(adc_gas_res_high, gas_range_h);
12201258
}
12211259
else
12221260
{
1223-
data->gas_resistance = calc_gas_resistance(adc_gas_res_low, gas_range_l, dev);
1261+
data->gas_resistance = calc_gas_resistance_low(adc_gas_res_low, gas_range_l, dev);
12241262
}
12251263

12261264
break;
@@ -1305,11 +1343,11 @@ static int8_t read_all_field_data(struct bme68x_data * const data[], struct bme6
13051343
data[i]->humidity = calc_humidity(adc_hum, dev);
13061344
if (dev->variant_id == BME68X_VARIANT_GAS_HIGH)
13071345
{
1308-
data[i]->gas_resistance = calc_gas_resistance(adc_gas_res_high, gas_range_h, dev);
1346+
data[i]->gas_resistance = calc_gas_resistance_high(adc_gas_res_high, gas_range_h);
13091347
}
13101348
else
13111349
{
1312-
data[i]->gas_resistance = calc_gas_resistance(adc_gas_res_low, gas_range_l, dev);
1350+
data[i]->gas_resistance = calc_gas_resistance_low(adc_gas_res_low, gas_range_l, dev);
13131351
}
13141352
}
13151353

bme68x.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* BSD-3-Clause
55
*
@@ -31,8 +31,8 @@
3131
* POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
* @file bme68x.h
34-
* @date 2021-03-18
35-
* @version v4.4.4
34+
* @date 2021-04-26
35+
* @version v4.4.5
3636
*
3737
*/
3838

bme68x_defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* BSD-3-Clause
55
*
@@ -31,8 +31,8 @@
3131
* POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
* @file bme68x_defs.h
34-
* @date 2021-03-18
35-
* @version v4.4.4
34+
* @date 2021-04-26
35+
* @version v4.4.5
3636
*
3737
*/
3838

examples/common/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (C) 2021 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/

examples/common/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2020 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (C) 2021 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/

examples/forced_mode/forced_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2020 Bosch Sensortec GmbH
2+
* Copyright (C) 2021 Bosch Sensortec GmbH
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*

examples/parallel_mode/parallel_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2020 Bosch Sensortec GmbH
2+
* Copyright (C) 2021 Bosch Sensortec GmbH
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*

examples/sequential_mode/sequential_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2020 Bosch Sensortec GmbH
2+
* Copyright (C) 2021 Bosch Sensortec GmbH
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*

0 commit comments

Comments
 (0)