Commit Graph

564 Commits (9c9322d02f2f1b47d54986d3dbe8fd1beb6752dd)

Author SHA1 Message Date
D.R.racer 9c9322d02f Remove old commented code 2022-12-29 09:01:27 +01:00
D.R.racer b16ac63c5d Compute vSense dynamically from iRun/iHold 2022-12-29 09:01:27 +01:00
D.R.racer 7e8ad83e25 Distinguish iRun<32
as per suggestion from @leptun
2022-12-28 12:15:47 +01:00
D.R.racer e469929c1c Remove ErrEngagingIdler state 2022-12-28 12:15:47 +01:00
D.R.racer ada4ed3dda Workaround INVALID_TOOL error codes
May meed some more work to recover gracefully, not sure if it is just a unit test "issue" or a deeper problem in the state machines.
2022-12-28 12:15:47 +01:00
D.R.racer a52f833223 Fix and tune CutFilament + unit tests
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
2022-12-28 12:15:47 +01:00
D.R.racer b6c3cba396 Refactor CheckFINDAvsEEPROM and setup2 2022-12-27 12:41:29 +01:00
D.R.racer 98daf765af Separate NoCommand and StartUp (new state machine)
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.
2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 35344f5a5e If Finda is not pressed, don't report Unload Manually error 2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 8f212a5cb3 Add unit tests 2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 4d38d1f620 PFW-1423 add Retry handling in NoCommand for init error 2022-12-27 12:41:29 +01:00
Guðni Már Gilbert 6a4ebdaee6 optimisation: inline functions to reduce size
Change in memory:
Flash: -394 bytes
SRAM: 0 bytes

Breakdown:
|------------------------------------------------------------|
| Function name                            | Flash reduction |
|------------------------------------------| ----------------|
|CommandBase::FinishedOK                   | 182 bytes       |
|MovableBase::InitMovementNoReinitAxis     | 60 bytes        |
|TMC2130::CheckForErrors                   | 36 bytes        |
|Protocol::UInt16ToHex                     | 32 bytes        |
|AddErrorAxisBit                           | 24 bytes        |
|Application::CheckManualOperation         | 22 bytes        |
|CommandBase::GoToErrEngagingIdler         | 12 bytes        |
|Application::PlanCommand                  | 12 bytes        |
|Pulley::FinishHomingAndPlanMoveToParkPos  | 8 bytes         |
|Pulley::InitAxis                          | 4 bytes         |
|------------------------------------------------------------|
2022-11-19 11:55:46 +01:00
D.R.racer c0189d81af Distinguish among different error states when recovering ToolChange
Some errors need specific recovery, it seems it is no longer possible to "just" retry.
2022-11-18 22:42:05 +01:00
D.R.racer c8c39f7b69 Make sure ToolChange moves Selector to desired slot
and verify correct behaviour in unit tests - especially when Selector's start position is at a different slot.
2022-11-18 22:29:01 +01:00
Guðni Már Gilbert 2f6e364ad0 optimisation: compiler should not inline SetFilamentLoaded
Change in memory:
Flash: -130 bytes
SRAM: 0 bytes
2022-11-18 21:33:46 +01:00
D.R.racer 08f777b5cb Introduce FINDA_FLICKERS error code
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.
2022-11-17 07:32:38 +01:00
D.R.racer 3f09ba0c16 Unit tests: selector refused to move in ToolChange
Revealed all kinds of subtle issues (which is great). All have been fixed in this commit.
2022-11-17 07:32:38 +01:00
D.R.racer 8d992e2706 Report Selector refused to move as FINDA_DIDNT_SWITCH_OFF
MMU-176
2022-11-17 07:32:38 +01:00
D.R.racer c74d418016 Invalidate Idler+Selector homing flags when Retry from ToolChange Error
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
2022-11-15 17:42:12 +01:00
D.R.racer 299a31b765 Generate exactly 1 userInput event when button pressed (and held)
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
2022-11-15 07:19:20 +01:00
Alex Voinea a4463b9734 Selector: use freewheeling 2022-11-11 10:46:21 +01:00
Guðni Már Gilbert 21a3ceb2b2 PFW-1428 Enable UART1 receiver when the MMU is ready to process incoming messages 2022-11-01 06:39:10 +01:00
Guðni Már Gilbert 394f290bfb Check for ERRInternal in command_base Step()
Reduces code size significantly
2022-10-27 15:40:15 +00:00
Guðni Már Gilbert ef4246dd9a Fix issue where firmware panic error code is overwritten
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
2022-10-26 20:39:28 +00:00
Guðni Már Gilbert 0e625dc551 circular_buffer: implement reset()
reset() discards any data in the buffer (head == tail)

Change in memory:
Flash: -116 bytes
SRAM: 0 bytes
2022-10-25 07:21:33 +02:00
Alex Voinea 3b85df297e hwSanity: Disable the steppers after test
flash: -44
RAM: 0
2022-10-22 16:48:48 +02:00
Guðni Már Gilbert 7bbee87a08 Empty the entire block_index queue when planned moves are aborted 2022-10-22 14:10:31 +00:00
D.R.racer 2c6f2d7533 Only set new SGTHRS when planning a Homing move (not regular moves) 2022-10-20 12:09:42 +02:00
D.R.racer dc487c36b6 Remove Enable/Disable TMC when reiniting Movable axes
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.
2022-10-20 12:09:42 +02:00
Alex Voinea d7301b8d58 Adjust PWM_FREQ to allow lower current regulation
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).
2022-10-20 12:09:42 +02:00
Alex Voinea 2d4aba2cde Reduce idler parked current (IHOLD) 2022-10-20 12:09:42 +02:00
Alex Voinea d77d31b883 Idler dynamic IHOLD adjustments 2022-10-20 12:09:42 +02:00
D.R.racer 37f820e9a6 Prevent filament creep in activeSlot+1
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.
2022-10-11 07:15:57 +02:00
Alex Voinea e91e382c5c Fix tests
Pretty please 🥺
2022-10-11 07:13:42 +02:00
Alex Voinea 62a9abc235 Reformat modified files
rip history
maybe now?
2022-10-11 07:13:42 +02:00
Alex Voinea 55e8caa054 Always check for tmc errors 2022-10-11 07:13:42 +02:00
Alex Voinea ecb1696a12 Abort moves when tmc errors happen 2022-10-11 07:13:42 +02:00
Alex Voinea a71e8045b1 Clear tmc error flags on init 2022-10-11 07:13:42 +02:00
Alex Voinea abf25c2b3e Only check for errors if the driver is initialized 2022-10-11 07:13:42 +02:00
Alex Voinea 739f4cd2a3 Check for tmc2130 error flags 2022-10-11 07:13:42 +02:00
Alex Voinea 8b2de34e34 Make sure the error flags are turned into bools 2022-10-11 07:13:42 +02:00
Alex Voinea 31c4a26d82 Make gpio write atomic
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
2022-10-11 07:13:42 +02:00
VintagePC 33b9e74b72 Restore the Error check axis bits 2022-10-10 12:08:58 -04:00
Guðni Már Gilbert fd7e9c415c Don't detach USB before entering bootloader 2022-10-07 17:58:35 +00:00
vintagepc 9c7701c123
Merge pull request #203 from prusa3d/vintagepc-check-hardware
Add module to check for sketchy electronics
2022-09-22 12:17:04 -04:00
Yuri D'Elia 1007402b24 Change TIMSK1 atomically in mm::IsrSetEnabled 2022-09-22 17:05:11 +02:00
Alex Voinea dd7042e567 Fix typo 2022-09-22 12:16:41 +02:00
D.R.racer 4f1a301e0e Force fix formatting 2022-09-22 12:16:41 +02:00
D.R.racer 0fa8a3c278 Refactor original solution from @leptun
- 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
2022-09-22 12:16:41 +02:00
Alex Voinea d5249f99fd Configurable SGTHRS 2022-09-22 12:16:41 +02:00