Hi, I am editing my question:
I have seen some strange behaviuor I could not explain. In order to test it I have made the next test program: I am using the application timer module to create 2 timers: one timer of 33.3 ms in repeat mode, and another of 2 ms in single shot mode, which is triggered once inside the 33.3 ms cycle (my code is attached below). inside the 2 ms timer I put the CPU to low power mode, using __WFE.
when I work with the debugger connected, I see the expected behaviour (see Logic image:)
but when I run the program without the debugger connected, this is what I get (program is stack after a few cycles):
I have also noticed that disabling __WFE in the 2 ms loop, or disabling the dc-dc solves this issue (see Logic images)
no WFE:
no dc-dc:
this is my code:
void timers_create(void)
{
// Initialize timer module.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
// Create timer for cycles (33.3 ms)
g_err_code = app_timer_create(&m_cycle_timer_timer_id, APP_TIMER_MODE_REPEATED, cycle_timeout_handler);
APP_ERROR_CHECK(g_err_code);
// Create timer for delays
g_err_code = app_timer_create(&m_delay_timer_id, APP_TIMER_MODE_SINGLE_SHOT, delay_timeout_handler);
APP_ERROR_CHECK(g_err_code);
}
void cycle_timer_start(void)
{
g_err_code = app_timer_start(m_cycle_timer_timer_id, CYCLE_INTERVAL, NULL);
APP_ERROR_CHECK(g_err_code);
}
void main()
{
NRF_POWER->DCDCEN = 1;
g_err_code = nrf_drv_clock_init(NULL);
APP_ERROR_CHECK(g_err_code);
// start LFCLK
nrf_drv_clock_lfclk_request();
timers_create();
nrf_gpio_cfg_output(25);
nrf_gpio_pin_clear(25);
nrf_gpio_cfg_output(26);
nrf_gpio_pin_clear(26);
cycle_timer_start(); // 33 ms cycle
while(1)
{
// wait for fglag
while(!g_activate_flag) {};
nrf_gpio_pin_toggle(25);
g_activate_flag = false;
// delay timer start
app_timer_start(m_delay_timer_id, 66, NULL);
nrf_gpio_pin_set(26);
while (!g_delay_ended)
{
// Wait for event
__WFE();
}
g_delay_ended = false;
nrf_gpio_pin_clear(26);
}
}
Can someone explain this behaviour? Thanks Yaron