nrf_delay_us() and ble connection question

HI

softdvice : s132 

SDK version : nRF5_SDK_17.1.0_ddde560

I am using the nrf_delay_us() function.
The product I am using now controls the gpio in us units. Since it is a product that affects even 1us, I have the following question.
There is a problem with the nrf_delay_us() function intermittently delaying.
However, the problem seems to be a problem with the BLE connection status (connection interval). If I disconnect the BLE, the problem does not occur.
Could the nrf_delay_us() function be affected by the signal that periodically checks the connection? If so, is there a way to solve this problem?

BR

Cabin

Parents
  • Could the nrf_delay_us() function be affected by the signal that periodically checks the connection? If so, is there a way to solve this problem?

    This function is busy wait that just loops keeping the CPU busy and not allowing any lower or equal priority interrupt contexts to run until the delay is finished and the current running contexts exits.

    Having small  busy delays like this in micro seconds should be ok but should not use busy delays in higher priority interrupt contexts.

    Can you please tell me in which interrupt context you are using the nrf_delay_us()? Can you use a timer instead and sleep using sd_app_evt_wait()? after wakeup from this sleep in the timer event handler, you can do the same things that you do after nrf_delay_us, this way you can avoid the busy loop waiting.

  • HI

    The method I'm currently using is as follows:

    for(;;)
        {
            nrf_gpio_pin_write(EXIT_4,EXIT_4_DISABLE);
            nrf_delay_us(3);
            nrf_gpio_pin_write(EXIT_4,EXIT_4_ENABLE);
            nrf_delay_us(16);
        }
    In this situation, when I connect BLE, nrf_delay_us(3) sometimes gets delayed by 100us. I would like to know how to solve this problem.
  • We are developing a low-frequency treatment device.
    So we are controlling the low frequency with gpio to low and high.

    However, there is a big difference in the output depending on the interval between low and high.

    The delay we want is 10us, but due to ble, the delay is 100us, and the output is momentarily high.

  • You can configure a TIMER+GPIOTE+PPI to toggle the gpio without the use of CPU 

    You can use a PRESCALAR of 1 with TIMER1 (for example, do not use Timer0 when using BLE) and you then you can get one timer tick of 2us. If you put CC value as 5, then you will get a tick every 10us. Use the code something like this

    // Configure the GPIOTE output pin to toggle on a GPIOTE task
    NRF_GPIOTE->CONFIG[GPIOTE_CH_OUT] = GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos |
    GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos |
    16 /*LED4*/ << GPIOTE_CONFIG_PSEL_Pos |
    GPIOTE_CONFIG_OUTINIT_High << GPIOTE_CONFIG_MODE_Pos;
    
    // Configure Timer 0 to generate events every 10 microseconds
    NRF_TIMER2->BITMODE = TIMER_BITMODE_BITMODE_32Bit << TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER2->PRESCALER = 1;
    NRF_TIMER2->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Enabled << 0;
    NRF_TIMER2->MODE = TIMER_MODE_MODE_Counter << TIMER_MODE_MODE_Pos;
    
    // Set the counter limit to 10 microseconds
    NRF_TIMER2->CC[0] = 5; // This value might need to be adjusted based on the clock speed
    
    // Start the timer
    NRF_TIMER3->TASKS_START = 1;
    Now the pin will toggle irrespective of what BLE is doing.
  • Thank you for your answer.
    First of all, we need to operate 4 gpio in order in us units.
    Also, one gpio has different delay values ​​for high and low.
    I think we need to test if it is possible to do so with the above gpiote+timer+ppi configuration. Is there any way to use the function of the nrf_delay_us function without affecting the ble?

  • cabin said:
    Is there any way to use the function of the nrf_delay_us function without affecting the ble?

    Unfortunately no, there is no other way that nrf_delay_us work efficiently with BLE apart from using it inside Timeslots. And timeslots only approves time to application when BLE is not sending any data or not doing any housekeeping.

  • When you say ble sends data, does that mean it sends data to the service? Also, can you explain what housekeeping is? It's a term that doesn't show up in searches. If so, does the above method mean that PPI is not affected by ble?

Reply Children
Related