timer and ppi on nrf connect sdk

hello Nordic

i work with nrf52832, nrf52840 with ncs 1.9

i have 2 issues, is there some example or guid fo using 2 ppi channels for the same gpiote, one timer pullup the gpio and the other timer pulls the same gpio down .. what functions are a must ?  gpioite_channel allocation is a must or ppi_channel_allocations are enough etc.

second issue is that i use three timers in my code and it looks like one of them does not work ok, 

also if i look at pin toggle in ppk power profiler i see that if i light a led while the sampling then i the gpio (pulled up by ppi and pulled down by spi_done handler) sometimes miss some toggling every some time .. any ideas why ?

hope to read from you soon

best regards

Ziv

  • hi Jorgen

    thanks 

    one more question 

    is it a problem or may cause undefined behaviour to call the IRQ_CONNECT() more then one time?

    in my app i set the timer with all ppi and IRQ_CONNECT() call .. it looks like this:

    {
        nrfx_timer_config_t timer_cfg = {
            .frequency = NRF_TIMER_FREQ_16MHz,
            .mode = NRF_TIMER_MODE_TIMER,
            .bit_width = NRF_TIMER_BIT_WIDTH_32,
            .p_context = handler_context,
        };
    
        int res = nrfx_timer_init(timer, &timer_cfg, ads8866_spi_done_event_handler);
        if (res != NRFX_SUCCESS)
        {
            AUGU_LOG_ERR("error in nrfx_timer_init %x", res);
            return -EINVAL;
        }
        IRQ_CONNECT(TIMER2_IRQn, 0, nrfx_timer_2_irq_handler, NULL, 0);
    
        uint32_t compar_val = nrfx_timer_us_to_ticks(timer, 2);
        nrfx_timer_compare(timer, NRF_TIMER_CC_CHANNEL1, compar_val, false);
    
        compar_val = nrfx_timer_us_to_ticks(timer, 14);
        nrfx_timer_compare(timer, NRF_TIMER_CC_CHANNEL2, compar_val, true);
    
        compar_val = nrfx_timer_us_to_ticks(timer, 1000000 / sample_freq);
        nrfx_timer_extended_compare(timer, NRF_TIMER_CC_CHANNEL3, compar_val, NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK, false);
    
        *time_conv_up = nrfx_timer_compare_event_address_get(timer, NRF_TIMER_CC_CHANNEL3);
        *time_spi_xfer = nrfx_timer_compare_event_address_get(timer, NRF_TIMER_CC_CHANNEL1);
        *timr_conv_down = nrfx_timer_compare_event_address_get(timer, NRF_TIMER_CC_CHANNEL2);
    
        return 0;
    }

    followed by :

    // init timers:
                    nrfx_timer_enable(&ads8866_sample_timer);

    and then when i am done sampling i turn off the timer with:

    // stop timers:
                    nrfx_timer_disable(&ads8866_sample_timer);
                    nrfx_timer_uninit(&ads8866_sample_timer);

    and this process repeats many times in the app's life .. each time we start sample we init the timer with the IRQ_CONNECT() call and then disable the timer

    so is there a problem or is ti no problem if we disable and uninit the timer each time ?

    hope to read you soon

    best regards

    Ziv

  • You should only call IRQ_CONNECT once for each interrupt. Please move it out of the init function and call it once at the start of the application.

  • hi 

    If you set the instance to 2 in the NRFX_TIMER_INSTANCE() macro, this is the instance that will be used. If your question is how you can use the number from the instance definition to select the IRQn object, this can be achieved using the concatenation operator (##), see e.g NRFX_CONCAT_2()

    regarding the above, the IRQ_CONNECT has several parameters that are timer instance dependent, also the timer itself wich you suggested using NRFX_CONCAT_2() to find it according to the instance but also the handler 'nrfx_timer_2_irq_handler' is instance dependent.. is there also a macro for concatenating between the timer instance and the handler ? 

    my goal is to have an instance define which i can change if needed at one place in the code and not search for more place of use if for some reason i will one day need to change it 

    hope to read you soon 

    best regards

    Ziv

  • You can use the same principle for concatenating the name for the handler, see this macro.

Related