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

Timer expires instantly

Hi all,

I have seen a pair of questions (this and this) that I think have something to do with this, but didn't find a solution.

I have a custom board with a button which acts as a reset button. This button must be pressed during 3 seconds to reset the device (otherwise it has no effect). I do this activating a 3 seconds timer when the button is pressed, and when the timer expires, I reset the device. If I release the button before, I stop the timer.

Normally this goes well, but I have found that after waiting for some time (maybe 5 minutes), the next time I press the button, the reset occurs instantly (because the timer that should expire in 3 seconds does it instantly). I attach the relevant part of the code:

Buttons interrupt handler:

static void button_evt_handler(uint8_t pin_no, uint8_t button_action)
{	
	if (button_action == APP_BUTTON_PUSH && pin_no == PIN_RESET_BUTTON)
    {
        start_reset_button_timer();
    }else if(button_action == APP_BUTTON_RELEASE && pin_no == PIN_RESET_BUTTON)
	{
		stop_reset_button_timer();
	}
}

Timer functions (I init the timer once at the beginning of the code):

static void reset_button_handler(void * p_context) // After 3 seconds pressing the button we get here
{
	// Factory values
	set_param_default_values(&param_ibk); // Set default values in flash and reset
	uint32_t err_code = access_paramIBK_flash(&param_ibk, ES_FLASH_ACCESS_WRITE);
	APP_ERROR_CHECK(err_code);
	
	// Reset after flash
	flag_reset=true;
}

void init_reset_button_timer(void)
{
	uint32_t err_code;
	
	err_code = app_timer_create(&reset_button_timer, APP_TIMER_MODE_SINGLE_SHOT, reset_button_handler);
	APP_ERROR_CHECK(err_code);
}

void start_reset_button_timer(void)
{
	uint32_t err_code;
	
	err_code = app_timer_start(reset_button_timer, APP_TIMER_TICKS(TIME_RESET_BUTTON, APP_TIMER_PRESCALER), NULL); // After 3 seconds will reset the device if not stopped before
	APP_ERROR_CHECK(err_code);
}

void stop_reset_button_timer(void)
{
	app_timer_stop(reset_button_timer); // Button released, timer stopped
}

and TIME_RESET_BUTTON defined as 3000, and the flag_reset variable will reset the code properly after flash writing.

I am using the following:

nRF52832

SDK 12.2.0

Code based on experimental_ble_app_eddystone example.

Is there any solution to this, or maybe I am doing something wrong?

Thank you

Parents
  • I found also this problem and in some cases even using the dummy timer doesn't work... Some months ago I found one answer in the forum proposing some modifications on the timer library to fix this. I have tested my code with those changes and now it seems to work better... I don't know if the bug i solved with the new SDK 12.3.0.

    My modified timer library for sdk 12.2 is attached:

    app_timer.c

Reply
  • I found also this problem and in some cases even using the dummy timer doesn't work... Some months ago I found one answer in the forum proposing some modifications on the timer library to fix this. I have tested my code with those changes and now it seems to work better... I don't know if the bug i solved with the new SDK 12.3.0.

    My modified timer library for sdk 12.2 is attached:

    app_timer.c

Children
No Data
Related