rt-thread icon indicating copy to clipboard operation
rt-thread copied to clipboard

[hwtimer] rt_device_read 接口读取的时间存在精度损失问题

Open liuyangzys opened this issue 3 years ago • 2 comments

目前 hwtimer 模块提供的 rt_device_read 接口读取时间,存在精度损失问题。 其原因是,时间变量使用 float 类型,再换算成为整形的 秒 和 微秒。 这导致了比如 1234.123456s 这样的时间,根本无法表达到其毫秒和微秒级别的精度。

是否可以考虑要运算时使用整形变量如 uint64 作为总时间的变量烈性,再换算成 整形的秒和微秒就不会存在上述的精度损失问题了。

liuyangzys avatar Jul 16 '22 03:07 liuyangzys

这个精度损失是在什么情况下会出现,一般来说 都是测量相对时间 t2-t1,固有的执行时间将会被消除掉。

mysterywolf avatar Jul 17 '22 02:07 mysterywolf

https://club.rt-thread.org/ask/article/8493fe4546bac15b.html 考虑一下,设定的时间精度问题先?

thewon86 avatar Jul 18 '22 05:07 thewon86