Fixs PWM current consumption - SYSTEM ON sleep @ ~2.7uA

This commit is contained in:
rbaron 2022-11-22 22:21:16 +01:00
parent 6705c11867
commit 339e5bebe9
6 changed files with 52 additions and 10 deletions

View file

@ -6,4 +6,9 @@ config BOARD_ENABLE_DCDC
select SOC_DCDC_NRF52X select SOC_DCDC_NRF52X
default y default y
config BOARD_ENABLE_DCDC_HV
bool "High Voltage DCDC converter"
select SOC_DCDC_NRF52X_HV
default y
endif # BOARD_BPARASITE_NRF52840 endif # BOARD_BPARASITE_NRF52840

View file

@ -27,6 +27,7 @@
buttons { buttons {
compatible = "gpio-keys"; compatible = "gpio-keys";
button0: button_0 { button0: button_0 {
// P0.12.
gpios = <&gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; gpios = <&gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button switch 0"; label = "Push button switch 0";
}; };
@ -34,9 +35,18 @@
soil_pwm: soil_pwm { soil_pwm: soil_pwm {
compatible = "pwm-fixed"; compatible = "pwm-fixed";
pwms = <&pwm0 0 PWM_MSEC(100) PWM_POLARITY_INVERTED>; pwms = <&pwm0 0 PWM_MSEC(100) PWM_POLARITY_NORMAL>;
pulse = <PWM_MSEC(50)>; pulse = <PWM_MSEC(50)>;
}; };
ctrl {
compatible = "gpio-keys";
fast_disch: fast_disch {
// P1.10.
gpios = <&gpio1 10 GPIO_ACTIVE_HIGH>;
label = "Fast discharge circuitry";
};
};
}; };
&gpiote { &gpiote {
@ -53,7 +63,7 @@
&uart0 { &uart0 {
compatible = "nordic,nrf-uart"; compatible = "nordic,nrf-uart";
status = "okay"; status = "disabled";
current-speed = <115200>; current-speed = <115200>;
pinctrl-0 = <&uart0_default>; pinctrl-0 = <&uart0_default>;
pinctrl-1 = <&uart0_sleep>; pinctrl-1 = <&uart0_sleep>;

View file

@ -1,13 +1,28 @@
CONFIG_LOG=y CONFIG_LOG=y
CONFIG_PWM=y CONFIG_PWM=y
CONFIG_PWM_LOG_LEVEL_DBG=y
CONFIG_CBPRINTF_FP_SUPPORT=y CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_I2C=y CONFIG_I2C=y
CONFIG_ADC=y CONFIG_ADC=y
CONFIG_GPIO=y
CONFIG_BT=y CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEBUG_LOG=y CONFIG_BT_DEBUG_LOG=n
CONFIG_BT_DEVICE_NAME="para" CONFIG_BT_DEVICE_NAME="para"
# CONFIG_BT_SETTINGS=n CONFIG_BT_SETTINGS=n
# CONFIG_SETTINGS=n CONFIG_SETTINGS=n
CONFIG_BT_CTLR_TX_PWR_PLUS_8=y CONFIG_BT_CTLR_TX_PWR_PLUS_8=y
CONFIG_CONSOLE=n
CONFIG_SERIAL=n
CONFIG_PM=y
CONFIG_PM_DEVICE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_CONSOLE=n
CONFIG_RTT_CONSOLE=n
CONFIG_PINCTRL=y

View file

@ -1,4 +1,7 @@
#include <logging/log.h> #include <logging/log.h>
#include <zephyr/pm/device.h>
#include <zephyr/pm/pm.h>
#include <zephyr/pm/policy.h>
#include <zephyr/zephyr.h> #include <zephyr/zephyr.h>
#include "prst/adc.h" #include "prst/adc.h"
@ -38,8 +41,16 @@ int main(void) {
RET_IF_ERR(prst_ble_adv_set_data(&sensors)); RET_IF_ERR(prst_ble_adv_set_data(&sensors));
RET_IF_ERR(prst_ble_adv_start()); RET_IF_ERR(prst_ble_adv_start());
k_msleep(5000); k_sleep(K_SECONDS(2));
RET_IF_ERR(prst_ble_adv_stop()); RET_IF_ERR(prst_ble_adv_stop());
k_sleep(K_SECONDS(2));
prst_led_flash(1);
// Example: go to deep sleep.
pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
k_sleep(K_SECONDS(2));
} }
} }

View file

@ -74,14 +74,14 @@ int prst_adc_batt_read(prst_adc_read_t* out) {
int prst_adc_soil_read(float battery_voltage, prst_adc_soil_moisture_t* out) { int prst_adc_soil_read(float battery_voltage, prst_adc_soil_moisture_t* out) {
// Start PWM. // Start PWM.
RET_IF_ERR(pwm_set_pulse_dt(&soil_pwm_dt, pulse)); RET_IF_ERR(pwm_set_dt(&soil_pwm_dt, soil_pwm_dt.period, pulse));
k_msleep(30); k_msleep(30);
RET_IF_ERR(read_adc_spec(&adc_soil_spec, &out->adc_read)); RET_IF_ERR(read_adc_spec(&adc_soil_spec, &out->adc_read));
// Stop PWM. // Stop PWM.
RET_IF_ERR(pwm_set_pulse_dt(&soil_pwm_dt, 0)); RET_IF_ERR(pwm_set_dt(&soil_pwm_dt, 0, 0));
out->percentage = get_soil_moisture_percent(battery_voltage, buf); out->percentage = get_soil_moisture_percent(battery_voltage, buf);
return 0; return 0;

View file

@ -22,7 +22,8 @@ static void button_pressed(const struct device *dev, struct gpio_callback *cb,
int prst_button_init() { int prst_button_init() {
RET_IF_ERR(!device_is_ready(button.port)); RET_IF_ERR(!device_is_ready(button.port));
RET_IF_ERR(gpio_pin_configure_dt(&button, GPIO_INPUT)); RET_IF_ERR(gpio_pin_configure_dt(&button, GPIO_INPUT));
RET_IF_ERR(gpio_pin_interrupt_configure_dt(&button, GPIO_INT_EDGE_TO_ACTIVE)); // EDGE interrupts consume more power! Just use a LEVEL one.
RET_IF_ERR(gpio_pin_interrupt_configure_dt(&button, GPIO_INT_LEVEL_ACTIVE));
gpio_init_callback(&cb_data, button_pressed, BIT(button.pin)); gpio_init_callback(&cb_data, button_pressed, BIT(button.pin));
RET_IF_ERR(gpio_add_callback(button.port, &cb_data)); RET_IF_ERR(gpio_add_callback(button.port, &cb_data));
return 0; return 0;