Problem with timer_create() on pixhawk

Hi,
I have a problem with timer_create() on my pixhawk hardware. When create a timer with 100 ms, I get notified at every 101 ms. And it seems the drifting is always be there.
So is this a common issue on pixhawk/nuttx? What’s the accuracy with timer? How can I improve this, any suggestions? Thanks.

You should use the HRT API instead: https://github.com/PX4/Firmware/blob/fbd7c73043b184fbae0e94f3a2053cafdd89a145/src/drivers/drv_hrt.h

Hi Lorenz, HRT works more accurate than posix timer does on pixhawk. And that’s what I need. Thank you.

hi , dear yangyang,how did you test the time as you said? I want to try it.

Hi garlinplus, sorry for missed your reply. Actually, I used drv_hrt_every', then made a signal bythread_kill’ to notify corresponding worker. Then from the log’s time-stamp, we can check the result is quite acceptable. (Note: you should not work directly within callback of `drv_hrt_every’, since it’s under interrupt context.)