Now the whole functionality takes +196B
As noted by @leptun, we cannot reliably check for >1 buttons pressed at once.
Since the left button is the least used, let's use it for invoking the HW EEPROM clear upon MMU start.
Based on long-term test experience - saves some code + prevents the user from entering hard-to-understand states.
Only Retry remains as the one and only way of recovering from errors.
This commit introduces a new set of registers 0x1e, 0x1f and 0x20 which allow reading and writing iRun current values for each axis/motor.
Please note the register contains raw TMC2130 iRun value which needs to be translated into mA to be understandable by people.
Translation table of iRun -> mA is present in tmc2130.cpp for now.
Several issues addressed in this PR:
- CutFilament tuning + error recovery
- introduce register 0x1d (cut filament selector iRun current level)
- optimize setting iRun and iHold currents in the FW
- CutFilament unit test fixed
The reasons for this change are:
- NoCommand is used during the lifetime of the firmware as a fallback in case an unknown command is received (simplifies command handling code). It must remain not doing anything.
- StartUp became a complex infrastructure which needs to "live" until an error is fixed (if any). That requires a "standard" StateInner() function which waits for the user to resolve the error.
Unit tests renamed as well.
Intended for scenarios when FINDA used to be OFF but accidentally became ON without a reason.
The user is obliged to inspect FINDA and tune its switching.
If FSENSOR_DIDNT_SWITCH_ON was caused by misaligned Idler, rehoming it may fix the issue when auto retrying -> no user intervention.
So first invalidate homing flags as the user may have moved the Idler or Selector accidentally.
Beware: we may run into issues when FINDA or FSensor do not work correctly. Selector may rely on the presumed filament position and actually cut it accidentally when trying to rehome.
It is yet to be seen if something like this can actually happen.
MMU-191
This PR is a different solution to what @gudnimg found in PR#233 / PFW-1404.
The benefit of this approach is the fact, that the button press event is generated when the button is pressed and not after it has been released.
The downside is obvious:
CPUFLASH: +28B
RAM: +1B
If QUEUE_FULL error happened, it would be overwritten as INTERNAL
and incorrectly display FW_RUNTIME_ERROR on MK3S.
The fix is to add handling for ERRInternal in every StepInner() and forward the error
to higher application layer
The previous commits by @leptun were correct but there has been one call to Disable axis (and TMC) hidden in `InitMovement`.
Therefore `InitMovement` has been split into 2 separate functions - one is there to allow the original full axis reinit, but the other `InitMovementNoReinitAxis` now only prepares a move without reiniting the TMC driver.
This approach seems to have the benefit of fixing the Idler creep over time.
The disadvantage is the fact, that setting StallGuard threshold is no longer called. We may need to add a special piece of code to handle/apply SGTHRS change at runtime like before.
With PWM_FREQ=2 (fPWM = 2/512 fclk), the idler parked current was quite high since the setting was not actually respected (scientifically tested using hand). In order to allow lower current regulation in stealthchop, TBL and PWM_FREQ need to be adjusted. The lower both of these values, the better. Since TBL affects both stealthchop and spreadcycle, I chose to only modify PWM_FREQ.
This new PWM_FREQ results in half the previous stealthchop PWM frequency and also halves the low current limit (so if previously the minimum achievable current was 300mA, now it would be 150mA). I confirmed that this setting works correctly on a 24V supply. There is no audible noise from stealthChop PWM and the hold current is indeed reduced now (again, scientifically tested using my hand).
This PR is just about tuning the intermediate Idler positions so that the filament gets relieved from the Pulley safely while the Extruder gears take over and the activeSlot+1 filament is not affected by its Idler bearing.
On a test bench filament was creeping about 0.5mm per Toolchange.
Changing the intermediate position from exact middle into 3/4 practically elliminated the creep. We can play with these constants more if necessary in the future.
Unfortunately, there is no way to differentiate between an optimized gpio write (safe always on the atmega32u4) and an unoptimized write (read-modify-write, dangerous if any other pin on that Port is used in an ISR).
While very quickly polling the tmc registers, I noticed that the moving stepper would do some random extra steps. That can only be explained by the following sequence of actions:
- the spi code reads the PORT register
- ISR toggles the step line, changing the value in the PORT register
- the spi code writes the upated PORT back, resetting the step line to the old state
After making the writes atomic, the stepping issue disappeared and the driver checks also worked correctly
- rename stall*guard to StallGuard (match name with the vendor)
- separate TMC2130 module from EEPROM (they do not need to know about each other at all)
- separate SGTHRS settings from motion - moved to globals like all other "global" parameters
- improved EEPROM storage for SGTHRS
This needs some investigation if it is really possible to push the Registers into PROGMEM. I think it should be possible, but the compiler is currently not collaborating.
It is not critical though as we have lots of free RAM at the moment (I can't believe I wrote this on an AVR project :) )
This is to solve a potential problem while feeding to printer's drive gears - while disengaging the Idler, the Pulley was still rotating to avoid grinding the filament (printer is pulling it).
Other filaments could have moved a bit when the Idler's bearings ran over them while the Pulley was still rotating slowly -> the filament could have been moved into the Selector's path causing trouble (especially when not used in the print).
Therefore, the Idler disengages partially now - moves into an intermediate position between the slots.
Then, the Pulley is completely stopped and after that the Idler does a full disengage like before.
We cannot get a constexpr definition of the register addresses, and any
reinterpret cast is currently illegal for a constexpr in c++17.
Change the SPI0, TIFR and TIMSK to volatile const pointers instead.
SPI0 has volatile members instead of marking the entire struct as
volatile, which is probably not a good idea as it technically drops the
volatile from the original pointer.