|
|
发表于 2014-4-19 02:39:35
|
显示全部楼层
未知数 发表于 2014-4-19 00:19 
谢谢啊,看你的回复,真心受教了。赋值确实是这样,我处理的不太好。那个速度计算,我在备注这样写的,因 ...
同時有頻密的多個 interrupt, 我也不知 Arduino 是否有解決方法.
樓據網上資料:
Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be ignored (turned off) until the current one is finished. as delay() and millis() both rely on interrupts, they will not work while an ISR is running. delayMicroseconds(), which does not rely on interrupts, will work as expected.
如果左右同時 觸發, 有可能當中一個會被 ignore. 而且, LCount 及 RCount 也算是 short 了, 但 flash 實在有點長. 我不太肯定 MsTimer2 是否也是經 interrupt 觸發, 如果是的話, 因為執行 flash 而導致 lcount/rcount 失效的機會更大.
如果是 flash 引致就好辦了, 只要把 flash 改成不再由 interrupt 觸發就可以了, 例如放在 loop() 內, 再自行計算兩次讀取計數值的時間差去推算速度. 雖然多了一點計算, 但相信不會是問題.
但如果是因為左右同時觸發, 至導致當中一個失效, 就比較難解決了.
如果有個計數器的模塊自動計數, 無需靠 interrupt 計數, 在 Arduino 中向它發出要求, 回傳及重設數值會比較安全. |
|