Hi,
I’m working with Timer 0 on my nRF5340 DK and trying to set up two different intervals: one at 1 second and another at 60 seconds, each on separate channels (COMPARE0 and COMPARE1). In the timer handler, the event for channel 1 (60 seconds) is not triggering, while the 1-second event is executing as expected. When initializing a single channel, everything works fine, but when both channels are initialized, the second channel (60 seconds) fails to trigger. Does anyone know the reason for this behavior?
I have attached the code snippet for the same.
static void timer_handler(nrf_timer_event_t event_type, void * p_context) { if (event_type == NRF_TIMER_EVENT_COMPARE1) { LOG_INF("60 sec Interrupt"); } if (event_type == NRF_TIMER_EVENT_COMPARE0){ LOG_INF("1 sec Interrupt"); } } /* Function for Timer initialization */ int led_timer_init(void) { nrfx_err_t status; #if defined(__ZEPHYR__) IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_TIMER_INST_GET(TIM_INST_IDX)), IRQ_PRIO_LOWEST, NRFX_TIMER_INST_HANDLER_GET(TIM_INST_IDX), 0, 0); #endif // Configuring timer instance in timer mode with the base frequency and 32-bit width uint32_t base_frequency = NRF_TIMER_BASE_FREQUENCY_GET(timer_t_inst.p_reg); nrfx_timer_config_t config = NRFX_TIMER_DEFAULT_CONFIG(base_frequency); config.bit_width = NRF_TIMER_BIT_WIDTH_32; config.p_context = &timer_t_inst; status = nrfx_timer_init(&timer_t_inst, &config, timer_handler); if(status == NRFX_SUCCESS){ return SEM_RET_SUCCESS; } else{ return SEM_RET_ERROR; } } /*Function for starting the Timer*/ int led_timer_start(void) { // Enable the timer nrfx_timer_enable(&timer_t_inst); bool adv_timer_state = nrfx_timer_is_enabled(&timer_t_inst); if (adv_timer_state){ uint32_t desired_ticks = nrfx_timer_ms_to_ticks(&timer_t_inst, TIME_TO_WAIT_60s); // Set compare on channel 1 to trigger an interrupt and clear the timer on compare match nrfx_timer_extended_compare(&timer_t_inst, NRF_TIMER_CC_CHANNEL1, desired_ticks, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, true); desired_ticks = nrfx_timer_ms_to_ticks(&timer_t_inst, TIME_TO_WAIT_1s); //Set compare on channel 0 to trigger an interrupt and clear the timer on compare match nrfx_timer_extended_compare(&timer_t_inst, NRF_TIMER_CC_CHANNEL0, desired_ticks,NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true); return SEM_RET_SUCCESS; } else{ return SEM_RET_ERROR; } }