[2.0.x] Creality3D Power-Loss Recovery#10479
[2.0.x] Creality3D Power-Loss Recovery#10479thinkyhead merged 4 commits intoMarlinFirmware:bugfix-2.0.xfrom
Conversation
854b59e to
1e07501
Compare
1e07501 to
11ab017
Compare
|
Does Marlin have the ability to see if the main power is down? I know my Tevo Tarantula board stays on with the USB plugged in but no motor control. Idea being on main poweroff transition, either use the last bit of charge to write to the card, or plug in a USB battery pack as a backup power supply to get the full SD card write in. |
Here's an idea:have a voltage divider from the PSU voltage triggering an interrupt pin. (with a capacitor to debounce). I never looked into Marlin's code but since you guys are fussing with this, you probably could add an option to detect a power break with a few lines of code. The hardware:
|
|
Thanks! We do plan to implement that soon. You can find some machines that use just that sort of circuit. I personally think the best place to detect the dropped voltage would be at the AC input to the PSU, so then you have several seconds to respond. There are some machines out now (e.g., the Alfawise U10) that include small board that detects the drop on the 12V DC line and include a fast-charging capacitor to provide extra time for shutdown. And the Alfawise U10 version of Marlin is open source, so we will probably borrow from it. |
|
well it's very easy to implement a mains detector that will work on 110 and 220v. |
|
Power loss seems to work great but unfortunately consume a lot of ram. Around 1500 Bytes of Ram is used (to buffer the recovery information) and for small board such as ATmega2560 , we jump from 60% to 80% of ram on the latest 1.1 bugfix branch. |
|
@systemik — A lot of optimization is possible. Someone just has to put in a full day or two to rewrite it. |
|
Anet boards have no free inputs available but... And what about counting the processed gcode commands? |
|
@peekpt this exists off the shelf as "MKS DET" board. It's used with MKS smart touchscreens to enable power resume feature in their spooler. @MasterPIC Creality also has no power loss detection and no free inputs, so that's not a problem. It just dumps the status every layer into a cookie and if such is present, reloads it from there and can continue the print. There's a possibility to try to detect the ATMega supply voltage slipping without consuming any pins, by doing a read of the internal voltage reference; however at that point it's unreliable to try to write to SD-card. SD-card is supplied 3.3V via a regulator from 5V that has an internal drop of up to 1.5V in cheaper display controller models. ATMega itself is specified to run down to 4.5V at 16 MHz, by that time, the SD-card voltage may reach 3V, which is a bit close for comfort. Usually however, you expect ATMega to still perform at 16 MHz down to 3.3-3.5V or so, but not necessarily reliably, which however means an EEPROM write has a reasonable chance to succeed when an SD-card write would have failed. Especially if one had the capability to drop the frequency in an emergency down to 1 MHz or so, to give you even more room. This is not guaranteed for the common 2560, but a select grade is available that is guaranteed to run down to 1.8V at 2 MHz, and most chips might behave similarly, just not quite this good - it might end up being the same silicon, just binned. Might be good enough for an emergency feature, of course not for steady state. Geeetech board GT2560 has two voltage probes that divide the supply voltages 11:1, one for bed (up to 24V nominal), one for the main 12V rail, so it may be possible to detect voltage sag and quickly turn off all high-power consumers, and you might still have plenty of time to do an SD-card write before the 5V/3.3V rails start actually failing. A hypothetical possibility is saving a cookie on SD-card which just contains the file and current status settings, and not touching that during the print unless there are major non-position/non-extrusion status changes - the cookie gets deleted when the print is finished; in the EEPROM, you just need to save the position to spool forward to. Unfortunately spooling forward is not directly compatible with Creality's approach and is very slow. Perhaps there's a way to make them complete each other by having the cookie be principally or exactly as Creality's current one, and spool forward within the layer from that. If one were to do that, how would one get feedback as to how much has been actually printed vs. just G-code consumed and planned out? |
|
Something that needs to be brought up again, is the internal voltage reference is used for making sure the ADC read back values are kept consistent. |
|
I think XY endstops are pretty useless while printing. |
This is Creality3D's power-loss recovery feature (for SD Card printing), adapted almost verbatim to the current Marlin codebase. Support has been added for delta printers, bed leveling, and the print job timer, and the code has been slightly reworked and re-organized.
Posted for review, study, and comment. This feature should be considered experimental, as it has some problems in its design and hasn't been tested with kinematic machines.
How it works: With this feature enabled, the machine state (temperatures, command queue, SD progress, etc.) is periodically (by default, once per layer) saved to a file named "BIN" on the SD card. If the power goes out during a print, then when the machine comes back to life this file is checked. If its
valid_headandvalid_footare non-zero and matching, a "recovery command queue" is populated from the file and then an LCD menu is presented giving the option to Resume or Cancel.When the print is resumed, the "recovery command queue" is drained ahead of continuing the SD print.
Caveats:
A hidden option (
SAVE_EACH_CMD_MODE) permits saving the state after every command, if you really want to stress-test your SD cards.Counterpart to #10437