Marlin is an optimized firmware for RepRap 3D printers based on the Arduino platform. Many commercial 3D printers come with Marlin installed. Check with your vendor if you need source code for your specific machine.
I did a little code analysis, trying to familiarize myself with Marlin code.
Noticed that the default time comparison style has not been compensated for the known best practices for using millis() and micros () timing.
This will cause issues when the timer counter overflows (for millis after 40days, for micros after 70minutes() ). This is a known trap for young players.
For detailed information see the very well written detailed explanation here:https://www.norwegiancreations.com/2018/10/arduino-tutorial-avoiding-the-overflow-issue-when-using-millis-and-micros/
As the issue is somewhat hidden behind the "macro magic" in the Marlins case so it took some more time to analyse. This is also some of the reason why I decided to share this info here, to spare some work for somebody else.
The easy initial solution to solve this would be to just edit the coding standards regarding the issue(https://marlinfw.org/docs/development/coding_standards.html#time-comparison). How to alter the "macro magic" I do not have any suggestions. I would suggest to keep it easy and just use the plain Arduino style without the macro magic.
All best Regards
Bug Timeline
native
Expected behavior
No response
Actual behavior
No response
Steps to Reproduce
No response
Version of Marlin Firmware
bugfix 2.1.x
Printer model
No response
Electronics
No response
LCD/Controller
No response
Other add-ons
No response
Bed Leveling
None
Your Slicer
None
Host Software
None
Don't forget to include
[X] A ZIP file containing your Configuration.h and Configuration_adv.h.
Did you test the latest
bugfix-2.1.x
code?Yes, and the problem still exists.
Bug Description
I did a little code analysis, trying to familiarize myself with Marlin code. Noticed that the default time comparison style has not been compensated for the known best practices for using millis() and micros () timing. This will cause issues when the timer counter overflows (for millis after 40days, for micros after 70minutes() ). This is a known trap for young players. For detailed information see the very well written detailed explanation here:https://www.norwegiancreations.com/2018/10/arduino-tutorial-avoiding-the-overflow-issue-when-using-millis-and-micros/
As the issue is somewhat hidden behind the "macro magic" in the Marlins case so it took some more time to analyse. This is also some of the reason why I decided to share this info here, to spare some work for somebody else.
The easy initial solution to solve this would be to just edit the coding standards regarding the issue(https://marlinfw.org/docs/development/coding_standards.html#time-comparison). How to alter the "macro magic" I do not have any suggestions. I would suggest to keep it easy and just use the plain Arduino style without the macro magic.
All best Regards
Bug Timeline
native
Expected behavior
No response
Actual behavior
No response
Steps to Reproduce
No response
Version of Marlin Firmware
bugfix 2.1.x
Printer model
No response
Electronics
No response
LCD/Controller
No response
Other add-ons
No response
Bed Leveling
None
Your Slicer
None
Host Software
None
Don't forget to include
Configuration.h
andConfiguration_adv.h
.Additional information & file uploads
No response