Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update code base to Marlin 2.1.1 #364

Merged
merged 8 commits into from
Sep 12, 2022
Merged

Conversation

stklcode
Copy link
Contributor

@stklcode stklcode commented Sep 3, 2022

Description

This PR updates the upstream sources to Marlin 2.1.1

Changes

  • Merged all upstream changes, hopefully preserving all patches
    • Added some additional conditionals to the Trigorilla 1.4 pin configuration to apply Anycubic defaults again
  • Merged configuration files
    • axis drivers for Z-axis steppers are now explicitly configured as Z_DRIVER_TYPE and Z2_DRIVER_TYPE
  • Updated anycubic_touchscreen code with relevant changes
    • updates for refactored bedleveling code (for Chiron implementation)
  • Updated PlatformIO configuration

Tested

The firmware builds for all targets

I've tested the MEGA_P_DGUS_BLT_10 target on my printer, including special menu, autoleveling and laser. Works so far.

Benefits

The updates introduces new features and bugfixes in Marlin. It also brings this project closer to upstream for future development.

Configurations

The configuration files have been updated and hopefully all customization remain functional.

I have enabled FAN_SOFT_PWM with SOFT_PWM_SCALE value 2 (~15Hz), because of conflicts with SPEAKER (same timer for hardware PWM).
This has been an issue ever since that is just rarely is noticed (strange speaker sounds when fan speed changes during playback or short interrupt of fan speed), but latest sanity checks prevent compilation.
We hat soft PWM enabled in 1.4.0 (d19dbf0) and disabled it again in 1.4.1 (7071629), so we probably need some further testing here.

Related Issues

None.


Side note

I have done complete rabase of this repository on top of Marlin 2.0.5.3 where it all started: https://github.com/stklcode/Marlin/tree/knutwurst Makes merging upstream changes and conflict resolution much easier with proper tooling, so probably a well spent hour.

For this PR I have applied patches derived from the "knutwurst-next" branch where a real merge of 2.1.1 was done: https://github.com/stklcode/Marlin/tree/knutwurst-next

@knutwurst
Copy link
Owner

Awesome!
Let me take a look at everything and roll out some tests to give some feedback before merging the PR into master.

@stklcode
Copy link
Contributor Author

Sure, take your time.

I only have one printer to test and only did a single real print so far (and some dummy test-sequences). But especially for the Chiron implementation the changes were made blindly, so I can only say it compiles...

For the soft PWM changes I honestly can't remember if I experienced the ticking issues back in 1.4.0, so no idea if it is still present for anyone. Disabling the sanity check, i.e. tolerate the conflict as we did before, would be another possibility of course.

@knutwurst
Copy link
Owner

After all, I only own a Mega S and cannot test the Chiron implementation. But I know some people who do that. For now, I'll go through the code myself, then I'll compile everything and then have it tested.

Let's write on Discord if you like.

@DeadSix27
Copy link

DeadSix27 commented Sep 10, 2022

I tested it and now the cooling fan is pulsing slowly, for example setting the fan speed to 50% M106 S128 makes my fan go on and off rapidly, as if the pulse length is wrong, 100% M106 S255 seems to work though

@stklcode
Copy link
Contributor Author

You are right, seems too slow.
SOFT_PWM_SCALE is not set, we probably should use 1 or 2 (i.e. 2x or 4x speed).

The previous attempt in 1.4 was 5 (32x speed) with dithering caused issues, so we should figure out something in between.

@DeadSix27
Copy link

DeadSix27 commented Sep 10, 2022

You are right, seems too slow. SOFT_PWM_SCALE is not set, we probably should use 1 or 2 (i.e. 2x or 4x speed).

The previous attempt in 1.4 was 5 (32x speed) with dithering caused issues, so we should figure out something in between.

Yeah, I was about to say, SOFT_PWM_SCALE wasn't enabled by default which I just did now, setting it to 2 seems to work fine.

@knutwurst
Copy link
Owner

If you activate SOFT_PWM, the heaters are also controlled via software pwm. I don't know why, but this has caused some bed MOSFETs to bust in the past.

@DeadSix27
Copy link

So whats the alternative?

@knutwurst
Copy link
Owner

So whats the alternative?

I don't know. As @stklcode mentioned, activating the dithering might be the problem here. Also it could be helpful to increase the pwm frequency.

@DeadSix27
Copy link

So whats the alternative?

I don't know. As @stklcode mentioned, activating the dithering might be the problem here. Also it could be helpful to increase the pwm frequency.

How was it handled prior to his Update to 2.1.1 ? Hardware PWM seems to have worked there on the fans as well, unless you had SOFT PWM enabled too in your latest build?

@stklcode
Copy link
Contributor Author

We used hardware PWM in previous versions (except 1.4.0). This conflicts with the speaker feature, as both speaker and fans share the same AVR timers. This has always been kind of a problem, but prior to Marlin 2.1 there simply was no sanity check which prevents the firmware from building now.

If there really is no suitable combination of soft PWM, frequency scaler and dithering, we can either not use the speaker or comment out the sanity check and tolerate the "problem".

Typically during print there aren't really many sounds to be played, so it should be acceptable that the speaker messes up with the fan PWM and vice versa. I believe it's only the fan, so fan speed is inaccurate during sound playback and sound is messed up when the fan speed changes at the same time. It's not pretty, but doesn't really affect the print job either.

@DeadSix27
Copy link

DeadSix27 commented Sep 10, 2022

I have the speaker completely off anyway, how would I go about re-enabling hardware PWM the way it was before? In my use case the speaker was annoying so Id be fine with it gone, can always just use octoprint to get audio feedback.

@stklcode
Copy link
Contributor Author

If have both SPEAKER and FAN_SOFT_PWM unset, the project compiles with hardware PWM and without speaker.

You'll run into an error during build.

/**
* Checks for SOFT PWM
*/
#if HAS_FAN0 && FAN_PIN == 9 && DISABLED(FAN_SOFT_PWM) && ENABLED(SPEAKER)
#error "FAN_PIN 9 Hardware PWM uses Timer 2 which conflicts with Arduino AVR Tone Timer (for SPEAKER)."
#error "Disable SPEAKER or enable FAN_SOFT_PWM."
#endif

Introduced in MarlinFirmware/Marlin#23672

@knutwurst knutwurst added the new feature New feature or request label Sep 10, 2022
@DeadSix27
Copy link

DeadSix27 commented Sep 10, 2022

Ignoring the build error (e.g commenting it out) should make it behave like prior though, no? Considering the speaker is always off for me.

The thing is, I didn't have SOFT PWM on before and it still had the slow-pulse fan issue as you remember.

So to get Pre-2.1 HardwarePWM FAN behavior, what do I have to do? Disable speaker and soft pwm? and comment out the error handling?

(Edit: Didn't notice the Conditional above errors only if speaker is on and soft off)

imo the MOSFET burning out is arguably the worse option, hence I'd rather have a buggy speaker or no speaker and I'm sure most others as well.

@stklcode
Copy link
Contributor Author

Exactly.

  • disable soft PWM, commenting out //#define FAN_SOFT_PWM in Configuration.h
  • any of:
    • disable the sanity check (comment out the previously linked block in SanityChecks.h)
    • disable the speaker (//#define SPEAKER in Configuration.h)

First option will give you the pre-2.1 behavior, second will disable the speaker completely.

@DeadSix27
Copy link

Exactly.

Perfect, for the public release maybe we should go with buggy speaker or offer 2 builds one with speaker and soft pwm and one without? Like I said I'd argue its better to not have the risk of blown mosfets.

@djepsylon
Copy link

djepsylon commented Sep 11, 2022

Hi,
Sorry to disturb you.
i don't speak and understand very well English, sorry if the answer was already posted but i don't understand correctly everything, i hope you understand. viva google translate loll but not perfect
I have a mega pro with laser recently.
I wouldn't tell you anything by telling you that the stock firmware is more than badly made lol.
I've been looking for quite a while, without finding answers, for a way to compile the firmware with the built-in bitmap converter so as not to lose the laser .
Anyway, I came across your GitHub and I see that you have been working on the same issue.
My questions are:
have you managed to make a firmware that allows you to keep the laser function without any modification of the machine?
Did you manage to find how to integrate the bmp converter or did you do otherwise?
And finally, would you agree to explain to me how you did it or provide me with a functional marlin?

Best regards

@stklcode
Copy link
Contributor Author

Perfect, for the public release maybe we should go with buggy speaker

I rebased my PR, reverted back to hardware PWM and disabled the sanity check with a corresponding comment. Just keep it "as is" for now and pospone optimization, if possible.

@knutwurst
Copy link
Owner

knutwurst commented Sep 11, 2022

Another Info that might be useful is the official MEGA S Firmware, where SOFT_PWM is used, but no PID for Heaters. -> Click here.

#define FAN_SOFT_PWM
#define SOFT_PWM_SCALE 2

Maybe I should get out my oscilloscope and take a good look at the PWM signals from the heaters to find out why MOSFETs have died in the past.

@DeadSix27
Copy link

Another Info that might be useful is the official MEGA S Firmware, where SOFT_PWM is used, but no PID for Heaters. -> Click here.

#define FAN_SOFT_PWM
#define SOFT_PWM_SCALE 2

Maybe I should get out my oscilloscope and take a good look at the PWM signals from the heaters to find out why MOSFETs have died in the past.

Personally have no skill with a oscilloscope, so go ahead 😅, I have a Mega S as well though if you need me to test something

@stklcode
Copy link
Contributor Author

stklcode commented Sep 11, 2022

but no PID for Heaters. -> Click here.

Actually PIDTEMP and with the very last commit also PIDBEDTEMP are enabled.

I had no issues with scale 2, fan has less ticking at 25% with 3. Just one small print job so far, normal brhavior. Didn't measure anything yet, maybe some time next week (connectors arrived yesterday, so I have a comfortable breakout cable now)

Remove unused variables, sanitize declarations and apply uncrust.
The hardware PWM for fan control conflicts with the speaker setup. While
this has always been an issue, sanity checks now fail because of this.

We've used soft PWM in 1.4.0 and reverted back to hardware PWM in 1.4.1,
so we probably need some additional investigation and testing here.
@knutwurst knutwurst merged commit 38f1521 into knutwurst:master Sep 12, 2022
@stklcode stklcode deleted the marlin-2.1.1 branch September 12, 2022 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants