From df7700cdd71d90aee5e2f488e7fe1c0236476243 Mon Sep 17 00:00:00 2001 From: rbaron Date: Fri, 25 Nov 2022 23:42:40 +0100 Subject: [PATCH] Recalibrated. BLE sample seems to work e2e @ 2.7uA sleep :) --- code/nrf-connect/Kconfig | 2 +- code/nrf-connect/prj.conf | 8 +++----- code/nrf-connect/src/main.c | 2 -- code/nrf-connect/src/prst/adc.c | 7 ++++--- code/nrf-connect/src/prst/adc.h | 1 + 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/code/nrf-connect/Kconfig b/code/nrf-connect/Kconfig index 6e9512f..8ab20c9 100644 --- a/code/nrf-connect/Kconfig +++ b/code/nrf-connect/Kconfig @@ -16,7 +16,7 @@ endchoice # PRST_NETWORK config PRST_SLEEP_DURATION_SEC int "Sleep duration in seconds" - default 1 + default 600 ### ### BLE configs diff --git a/code/nrf-connect/prj.conf b/code/nrf-connect/prj.conf index ce9324f..dd84d36 100644 --- a/code/nrf-connect/prj.conf +++ b/code/nrf-connect/prj.conf @@ -1,6 +1,6 @@ -CONFIG_LOG=y +# Enabling log has a big impact in power consumption. Only enable it while debugging. +CONFIG_LOG=n CONFIG_PWM=y -CONFIG_PWM_LOG_LEVEL_DBG=y CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_I2C=y CONFIG_ADC=y @@ -9,12 +9,11 @@ CONFIG_GPIO=y CONFIG_BT=y CONFIG_BT_PERIPHERAL=y CONFIG_BT_DEBUG_LOG=n -CONFIG_BT_DEVICE_NAME="para" +CONFIG_BT_DEVICE_NAME="prst" CONFIG_BT_SETTINGS=n CONFIG_SETTINGS=n CONFIG_BT_CTLR_TX_PWR_PLUS_8=y -CONFIG_CONSOLE=n CONFIG_SERIAL=n CONFIG_PM=y CONFIG_PM_DEVICE=y @@ -25,4 +24,3 @@ CONFIG_CONSOLE=n CONFIG_RTT_CONSOLE=n CONFIG_PINCTRL=y - diff --git a/code/nrf-connect/src/main.c b/code/nrf-connect/src/main.c index fe51d11..ee7e5e3 100644 --- a/code/nrf-connect/src/main.c +++ b/code/nrf-connect/src/main.c @@ -42,8 +42,6 @@ int main(void) { RET_IF_ERR(prst_ble_adv_start()); k_sleep(K_SECONDS(CONFIG_PRST_BLE_ADV_DURATION_SEC)); - k_msleep(200); - k_busy_wait(200 * 1000); RET_IF_ERR(prst_ble_adv_stop()); diff --git a/code/nrf-connect/src/prst/adc.c b/code/nrf-connect/src/prst/adc.c index 4105876..9046798 100644 --- a/code/nrf-connect/src/prst/adc.c +++ b/code/nrf-connect/src/prst/adc.c @@ -38,8 +38,8 @@ static const struct adc_dt_spec adc_batt_spec = static inline float get_soil_moisture_percent(float battery_voltage, int16_t raw_adc_output) { const double x = battery_voltage; - const double dry = -12.9 * x * x + 111 * x + 228; - const double wet = -5.71 * x * x + 60.2 * x + 126; + const double dry = -11.7f * x * x + 101.0f * x + 306.0f; + const double wet = 3.42f * x * x - 4.98f * x + 19.0f; LOG_DBG("Raw %u | Batt: %.2f | Dry: %.2f | Wet: %.2f", raw_adc_output, x, dry, wet); return (raw_adc_output - dry) / (wet - dry); @@ -96,7 +96,8 @@ int prst_adc_soil_read(float battery_voltage, prst_adc_soil_moisture_t* out) { // Turn off fast discharge circuit. RET_IF_ERR(gpio_pin_set_dt(&fast_disch_dt, 0)); - out->percentage = get_soil_moisture_percent(battery_voltage, buf); + out->percentage = + MAX(0.0f, MIN(1.0f, get_soil_moisture_percent(battery_voltage, buf))); return 0; } diff --git a/code/nrf-connect/src/prst/adc.h b/code/nrf-connect/src/prst/adc.h index 2a1f66d..5ec3e9e 100644 --- a/code/nrf-connect/src/prst/adc.h +++ b/code/nrf-connect/src/prst/adc.h @@ -13,6 +13,7 @@ typedef struct { prst_adc_read_t adc_read; // A value from 0 (completely dry) to 2^10 (completely wet). uint16_t relative; + // In [0, 1.0]. float percentage; } prst_adc_soil_moisture_t;