Configuring gpio pin pull-up continuously enabled/disabled

Hi,

We have a battery powered wireless sensor working as an OpenThread SED. We have a single push button switch for UI purposes. The design is like this.

The issue is when the switch is pressed the current draw is much higher. We have a long key press of 10 secs and I wanted to improve this battery drain due to switch press.

What I thought was to remove R24 and then dynamically turn on/off the internal pull-up to charge the C7. This way the current drain is only during a small portion of the time per scan cycle.

This is how I tried it.

In coap_client.c 

#define SW0_NODE	DT_ALIAS(sw0)	// Feature 13
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, {0});

void main () {
    ...
    ret = dk_buttons_init(on_button_changed);
    ...
    ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
    ...
}

So after dk_button_init() configuring the pin as input with a pull-up, I disable it after that.

Then I have two k_work items as follows.

static struct k_work_delayable button_off_work, button_scan_work;

...
static void button_scan () {
	
	gpio_pin_configure_dt(&button, GPIO_INPUT | GPIO_PULL_UP);	// charge the 100n by enabling internal pull-up
	k_work_schedule (&button_off_work, K_MSEC(10));	// schedule to turn off pull-up in 10ms
}

static void button_off () {
	gpio_pin_configure_dt(&button, GPIO_INPUT);	// turn off input pull-up to reduce current drain
	k_work_schedule (&button_scan_work, K_MSEC(100));   // schedule pull-up enable in another 100ms
}
 

When I grab a scope view across push button I see this as expected.

The signal levels seems within spec (0.9V and 2.1V @ 3V VDD). The power consumption is much better now with respect to previous.

Only issue is I dont get any button change events now!! 

I have traced the buttons_scan_fn() in dk_buttons)and_leds.c. It seems like this function gets invoked couple of time initially but then stops.

Any thoughts anyone??

Cheers,

Kaushalya

Parents Reply Children
Related