Variations in the Main Cycle Using k_timer

Hello.

I used `k_timer` to create the main cycle (5 ms), but there is a deviation of ±1 ms.

I’ve determined that the cause is the UART interrupt callback, but I don’t know how to minimize this deviation.
Note that the interrupt handling took approximately 25 μs.

Based on the above, I have two questions:
① Is a deviation of ±0.5 ms unavoidable in the Zephyr OS thread-based implementation?
② What is the recommended approach to minimize this variation on the nRF54L05?

My development environment is as follows:
 SoC used: nRF54L05
 SDK version: nRF Connect SDK v3.1.1
 Zephyr OS version: v4.1.99
 Development tool: nRF Connect for VS Code

Parents
  • Hello,

    Could you provide a minimal sample project that reproduces this issue, so I can test it here? I don't see how the UART callback could explain a 1 ms deviation when according to your measurements it only blocks for about 25 us. Could you also say a bit more about what you’re trying to achieve with this periodic timer interrupt? I may be able to suggest another approach.

    Best regards,

    Vidar

  • Dear Vidar,

    Good evening.

    This issue has been successfully resolved.
    The cause of the main cycle offset was that a while loop was executing a 1ms wait within the k_timer handler (ISR).

    Therefore, we resolved the issue by using a semaphore within the k_timer handler to simply send notifications,
    and by moving all main processing to the main() function.

    I apologize for the inconvenience.

    Best regards,
    Fumiya

Reply Children
Related