Questions about FreeRTOS and RTC on nrf52832

Hi all,

I am having an issue with FreeRTOS on the NRF52832 (SDK 17.1.0).

I need precise time so I use the io to measure the time. the code like this:

    nrf_gpio_cfg_output(18);
    PRINTF("nrf_gpio_cfg_output 18.");
    while(1)
    {
        nrf_gpio_pin_write(18, 1);
        vTaskDelay(1);
        nrf_gpio_pin_write(18, 0);
        vTaskDelay(1);
        nrf_gpio_pin_write(18, 1);
        nrf_delay_us(500);
        nrf_gpio_pin_write(18, 0);
        nrf_delay_us(500);
        nrf_delay_ms(10);
        PRINTF("while loop.");
    }

#define configTICK_RATE_HZ        1024

But the oscilloscope waveform shows that the interval is abnormal.

The first pullup interval is 738 us, and the first pulldown interval is 910us, but the second pullup interval is exact time 500us.

That means delay time on rtos is not accurate, but nrf_delay is accurate.

Did I set something wrong about freertos?

The config file is here.

8508.FreeRTOSConfig.h

5432.sdk_config.h

Hope you can give me some suggestions.

Best regards

Lurn

Parents
  • Hi,

    The time resolution of vtaskdelay is limited by the configTICK_RATE_HZ from the RTC. For short accurate delays I would recommend using busy waits (nrf_delay_us()). When you factor in the processing overhead associated with context switching, I don't think the power consumption difference will be significant. Another alternative is to use a TIMER instance.

    Best regards,

    Vidar

  • Hi Vidar,

    Actually, what i want to do is that I have 1 PRX and 2 PTX, and I want to synchronize the timer of the 3 devices via ESB.

    Then make sure that the time points when the two TXs send data are separated to ensure that the data does not conflict(due to I need real-time data, I can't use the esb retransmit). And The sending interval of each TX is 2MS. It's looks like the sending time of TX 1 to be at an odd time, another at even time.

    So I want to do it with clock synchronization, but now I can't achieve precise 2ms time synchronization.

    Maybe what I'm doing is not right, because I'm just trying, so I should need to say what I want to do so that you can correctly understand whether I'm trying to go in the right direction.

    So did PPI can help me to do this?

    In this link, @haakonsh said it can use a propriatary 2.4GHz protocol to synchronize nordic devices, but the link he shared is lost, can you give me a new link about it?

    And will it solve my problem? If it doesn't work out, can you give me a better suggestion?

    Update:

    Can I use the timeslot to do this? If I can use it, can you give me a example about it. my project didn't use the SoftDevice, 

    Best regards,

    Lurn

Reply
  • Hi Vidar,

    Actually, what i want to do is that I have 1 PRX and 2 PTX, and I want to synchronize the timer of the 3 devices via ESB.

    Then make sure that the time points when the two TXs send data are separated to ensure that the data does not conflict(due to I need real-time data, I can't use the esb retransmit). And The sending interval of each TX is 2MS. It's looks like the sending time of TX 1 to be at an odd time, another at even time.

    So I want to do it with clock synchronization, but now I can't achieve precise 2ms time synchronization.

    Maybe what I'm doing is not right, because I'm just trying, so I should need to say what I want to do so that you can correctly understand whether I'm trying to go in the right direction.

    So did PPI can help me to do this?

    In this link, @haakonsh said it can use a propriatary 2.4GHz protocol to synchronize nordic devices, but the link he shared is lost, can you give me a new link about it?

    And will it solve my problem? If it doesn't work out, can you give me a better suggestion?

    Update:

    Can I use the timeslot to do this? If I can use it, can you give me a example about it. my project didn't use the SoftDevice, 

    Best regards,

    Lurn

Children
Related