How to use the TIMER1 interrupt in nRF Connect SDK?

Hi,

My project has a requirement to toggle the GPIO output in 400 to 500 microseconds cycle, I've tried to use the Timer on Zephyr but it can't supply a stable cycle in 400 to 500 microseconds (sometimes the period up to 570 microseconds).

So I'm finding a other way to solve this issue, I'm tring to use the timer1 on nRF52833 chip directly, but the code can't worked well

const nrfx_timer_t TIMER_LED = NRFX_TIMER_INSTANCE(1);
static void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    static uint32_t i = 0;

    printk("i = %d", i++);
}

static void test_timer_init()
{
    uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    nrfx_err_t err_code;

    //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG;
    err_code = nrfx_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
    time_ticks = nrfx_timer_ms_to_ticks(&TIMER_LED, time_ms);

    nrfx_timer_extended_compare(
         &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrfx_timer_enable(&TIMER_LED);
}

the code run in zephyr can't work well, the output is as follows, is there have any example for me, or have any suggestions?  Is there another way to solve this requirement? 

E: >>> ZEPHYR FATAL ERROR 1: Unhandled interrupt on CPU 0
E: Current thread: 0x20003b88 (sysworkq)
E: Resetting system

Hope your reply soon.

B&R

Alex

Parents Reply Children
No Data
Related