This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Slow Wake-Up and Timer Start from Power Off

Hello,

I am trying to set the nRF52 to power off and wake up on a momentary button push (scope measures momentary push logic low around 50ms-100ms). However, I am struggling to have my debounce timer start up fast enough to detect the button being still pressed. If I hold the button down for a longer press, 200ms+, then I am able to read the button pin as registering a press in my debounce timer. The nRF52 tOFF2ON is stated as 16.5us, so I am thinking the timer is not starting fast enough or the button pin is not setup quick enough? Any direction would be very helpful!

First I set up my button input and debounce timer:

int
main (void)
{
  uint32_t err_code;
  uint32_t time_ticks;
  uint32_t time_ms = 1; //Time(in miliseconds) between consecutive compare

  //Initialize.
  err_code = NRF_LOG_INIT(NULL);
  APP_ERROR_CHECK(err_code);

  /*********** Manual Input Config ******************/
  err_code = nrf_drv_gpiote_init ();
  APP_ERROR_CHECK(err_code);
  //nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
  in_config.pull = NRF_GPIO_PIN_PULLUP;
  err_code = nrf_drv_gpiote_in_init (BUTTON_1, &in_config, in_pin_handler);
  APP_ERROR_CHECK(err_code);
  nrf_drv_gpiote_in_event_enable (BUTTON_1, true);

  // Check initial button state
  if (button1_is_pressed())
    {
      btnpressed = 1;
    }

  /*********************************************/

  /*********** Timer Config ******************/
  nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
  err_code = nrf_drv_timer_init (&TIMER_LED, &timer_cfg,
				 timer_callback_handler);
  APP_ERROR_CHECK(err_code);
  time_ticks = nrf_drv_timer_ms_to_ticks (&TIMER_LED, time_ms);
  nrf_drv_timer_extended_compare (&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks,
				  NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
  nrf_drv_timer_enable (&TIMER_LED);
  /*****************************/

Here is my code to setup power off:

void
sleep_mode_enter (void)
{

  //uint32_t err_code;

  nrf_drv_gpiote_out_set (LED_1);

  //err_code = bsp_wakeup_button_enable(0);

  //err_code = nrf_gpio_cfg_sense_set( BUTTON_1, BUTTONS_ACTIVE_STATE ? NRF_GPIO_PIN_SENSE_HIGH :NRF_GPIO_PIN_SENSE_LOW );
  nrf_gpio_cfg_sense_set ( BUTTON_1, NRF_GPIO_PIN_SENSE_LOW);

  // Go to system-off mode (this function will not return; wakeup will cause a reset).
  nrf_drv_timer_compare_int_disable(&TIMER_LED,NRF_TIMER_CC_CHANNEL0);
  nrf_drv_timer_disable (&TIMER_LED);
  sd_power_system_off ();
//  err_code = sd_power_system_off ();
//  APP_ERROR_CHECK(err_code);
  while (1)
    ;
}

Here is my button debounce timer handler, after a short momentary push from wake-up, the system is seeing "state" as false, if I hold the button down for a long press it measures true.

void timer_callback_handler (nrf_timer_event_t event_type, void* p_context)
{
  static uint32_t button_debounce = 0;

  bool state;
  switch (event_type)
    {
    case NRF_TIMER_EVENT_COMPARE0:
      total_ticks++;
      state = button1_is_pressed();
      if (state && btnpressed) // Still held down
	{
Parents
  • @LukeC

    OK. I see what you are doing.

    But I'm not sure how the logic of this is going to work..

    Assuming it takes 50mS to start up from cold, and your button takes 200mS to settle down,

    Then you won't know for 200mS whether its a long or a short press (or perhaps 200mS is the time for a long press - not that makes any difference to this)

    So how is it possible to "blast out" an advertising packet and go back to sleep in under the time taken for a long press.

    Or would you immediately blast out an advert (takes about 5mS) and then wait for 200mS and recheck the button, and if so treat it as a long press and change the advert.

    Why are you using Power Off? To extend your battery life on a very small battery? I'm surprised that just turning off advertising would not be low enough power Or are you running from harvested energy?

Reply
  • @LukeC

    OK. I see what you are doing.

    But I'm not sure how the logic of this is going to work..

    Assuming it takes 50mS to start up from cold, and your button takes 200mS to settle down,

    Then you won't know for 200mS whether its a long or a short press (or perhaps 200mS is the time for a long press - not that makes any difference to this)

    So how is it possible to "blast out" an advertising packet and go back to sleep in under the time taken for a long press.

    Or would you immediately blast out an advert (takes about 5mS) and then wait for 200mS and recheck the button, and if so treat it as a long press and change the advert.

    Why are you using Power Off? To extend your battery life on a very small battery? I'm surprised that just turning off advertising would not be low enough power Or are you running from harvested energy?

Children
No Data
Related