这是我的代码, 为什么执行 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 好的, 非常感谢