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
{