這是我的代碼,為什麼執行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 好的,非常感謝