这是我的代码,为什么执行1个多小时之后又从0开始计时,这是什么原因? 我用的是w806
查看更多
检查下millis的实现是否正确,一般系统tick数是一个uint32_t的数据类型,最大值为2的32次幂减一,换算成时间值和1:11:34的秒数正好差了1000倍。
发布 问题
分享 好友
手机 浏览
回到 顶部
我感觉问题出在“微秒级计时被当成毫秒用”或 core 在实现 millis() 时错误使用/转换了 micros()。
@xiaoxuesheng Using millis() to calculate uptime is incorrect. The return value of the millis() function is a 32-bit unsigned number.
Interrupts that increment the tick counter occur every microsecond in our Arduino Core implementation.
During long-term operation, this value is periodically reset to 0 upon overflow.The millis() function is useful for measuring short intervals between code sections. For calculating uptime, it's better to use the built-in real-time clock module.
@AnatolSher 感谢你的回答对我很有帮助,我想节约成本所以不使用RTC时钟模块,计算大概时间就行
It might look something like this
@xiaoxuesheng Don't skimp on your time. Solve the problem technically correctly. :)
@AnatolSher 好的,非常感谢