samroesch
Posts: 3
Joined: Mon Aug 17, 2020 5:52 pm

BUG: Cooling M106 occurs before starting scripts

Layer 1 print cooling fan setting (M106) is inserted into gcode before starting scripts, potentially being altered by starting scripts, and not corrected for subsequent layers. Furthermore, if layer 2+ is set to same value as layer 1, Simplify3D inserts no additional M106 commands for the fan, as it doesn't know the value might have been changed.

Current workarounds:
1. Avoid any commands that adjust fan in starting script
2. Toggle fan off for layer 1, and on for layer 2, forcing S3D to insert an M106 at layer 2

Code: Select all

;   singleExtrusionMaxPrintingWidthPercentage,200
;   singleExtrusionEndpointExtension,0.2
;   horizontalSizeCompensation,0
G90
M82
M106 S0 <------ This is setting applied in S3D for layer 1
M140 S60
M104 S200 T0
M109 S200 T0
G28 ; home all axes <------ Start of my "starting scripts"
G1 Z5 F3000 ; lift
M107 ; fan off <------- Turning fan off here will not be altered by S3D, and will remain off for the rest of the print 
G5 ; enable resume from power failure
M900 K0.0
G1 X10 Y5 F1500 ; move to prime
G1 Z0.2 F3000 ; get ready to prime
G92 E0 ; reset extrusion distance
G1 X80 E10 F600 ; prime nozzle
G1 X80 F5000 ; quick wipe
; process Process1 <------- Layer 1 gcode
; layer 1, Z = 0.100
T0
G92 E0.0000
G1 E-4.0000 F2400
; feature skirt
parallyze
Posts: 352
Joined: Fri Jun 05, 2015 4:18 am

Re: BUG: Cooling M106 occurs before starting scripts

Hi,
samroesch wrote: Layer 1 print cooling fan setting (M106) is inserted into gcode before starting scripts, potentially being altered by starting scripts, and not corrected for subsequent layers.
Fan is set to S0 when using 0% for layer 1. So the fan should not be spinning at all...

Furthermore, if layer 2+ is set to same value as layer 1, Simplify3D inserts no additional M106 commands for the fan, as it doesn't know the value might have been changed.
If you set layer 1 to 0%, layer 2 to 25% and layer 5 to 100% you will get M106 S0 on layer 1, M106 S64 on layer 2 and M106 S255 on layer 5.

(And, if "blip fan to full power" is enabled, additional M106 S255 commands might appear)

At what point exactly would you expect S3D to know of a changed value here, how is fan speed supposed to change between
layer 2 and 5 if it's not defined on the cooling tab?
Current workarounds:
1. Avoid any commands that adjust fan in starting script
2. Toggle fan off for layer 1, and on for layer 2, forcing S3D to insert an M106 at layer 2
Why bother with setting the part cooling fan inside the start script to anything at all?

Either you want it off (0% layer 1 -> M106 S0) or you want it on (25% layer 1 -> M106 S64)...

S3D will insert an M106 at each layer where's a change in temperature defined on the cooling tab. As the start script technically
does happen on the first layer I don't really see a problem there...

Code: Select all

M106 S0 <------ This is setting applied in S3D for layer 1
If you set cooling to 0% on the first layer, this is what happens, yes. The fan start command will be issued but the fan shouldn't
start spinning, because it's set to a duty cycle of 0: https://marlinfw.org/docs/gcode/M106.html

Code: Select all

M107 ; fan off <------- Turning fan off here will not be altered by S3D, and will remain off for the rest of the print 
Why turn off the fan using M107 when it's set to duty cycle 0% using M106 S0? It shouldn't be spinning anyways....

Maybe you'd like to attach a factory file so others can have a look at it... or some more information. Like what you're trying to achieve
and what your settings look like. Or what printer/firmware you're using.
samroesch
Posts: 3
Joined: Mon Aug 17, 2020 5:52 pm

Re: BUG: Cooling M106 occurs before starting scripts

Parallyze, thank you for the reply. To be clear, I'm raising this bug because the behaviour is not logical. I'm not saying I can't print because of it. Now that I understand what's happening, there are lots of ways to avoid this, BUT it did trip me up for 3 days of painful troubleshooting before I found the bug, so I wanted to raise it and have it corrected so no-one else has to go through what I did.

In my opinion, the logical behaviour is that the Layer 0 fan setting should be written into the gcode as and when Layer 0 starts. The scope for "starting scripts" is so large and varied that S3D should not be applying layer specific settings before the "starting scripts" are executed.

For all S3D knows, my starting script might be written to play a flute sonata with the cooling fan. It should set Layer 0 fan speed after starting scripts.

Please explain if you disagree with that logic, and why.
parallyze
Posts: 352
Joined: Fri Jun 05, 2015 4:18 am

Re: BUG: Cooling M106 occurs before starting scripts

Hi,
samroesch wrote: Tue Aug 18, 2020 8:09 pm Parallyze, thank you for the reply. To be clear, I'm raising this bug because the behaviour is not logical. I'm not saying I can't print because of it. Now that I understand what's happening, there are lots of ways to avoid this, BUT it did trip me up for 3 days of painful troubleshooting before I found the bug, so I wanted to raise it and have it corrected so no-one else has to go through what I did.
Still I don't see a "bug" here, but I admit it can take some time to realize this, especially when new to 3d printing/starting scripts and such.
In my opinion, the logical behaviour is that the Layer 0 fan setting should be written into the gcode as and when Layer 0 starts. The scope for "starting scripts" is so large and varied that S3D should not be applying layer specific settings before the "starting scripts" are executed.

The current behavior is this:

M106 S0 will be inserted, just like other commands. If fan speed is set to "0" for Layer 1, it will be set to PWM Duty 0% right
away. So the fan won't spin while doing the startup script and it won't spin when starting to print the features on layer 1.

Whenenver there's a change (25% at layer 2, 50% at layer 3 for example), this will be added right into the gcode where a
new layer starts. People usually don't want the part cooling fan enabled on the first layer because this might introduce problems
with layer/bed adhesion. And as it's the first layer anyways, there's no steep overhangs or anything which might rely on heavy
cooling.

So far my experience with S3D. I set a fan speed at a certain layer and it will be set.

And that's the part I don't really understand now on your side: What exactly is the problem with the
fan set to PWM speed 0 before the start script, do you want to enable/disable it inside the start script for
a reason... like...
For all S3D knows, my starting script might be written to play a flute sonata with the cooling fan. It should set Layer 0 fan speed after starting scripts.

Please explain if you disagree with that logic, and why.
...yes. In that case S3D would insert the M106 you would change it and it would stay on whatever value you set.

But it can be done. There is just one thing you probably didn't know about, yet. Variables inside the start script.

Have a look at your start script. One thing you might notice is there's no commands to heat the bed/extruder. S3D will
insert them before your start script, because it sees they are missing.

It is exactly the same for other things, like fanspeed. If there's no M106 inside your start script, S3D will put it in before.

The solution is pretty simple if you want to handle your fan inside the start script manually:

Inside the start script, add whatever commands you'd like the fan to do:

Code: Select all

M106 S255 ; set fan to 100% pwm
G4 P5000 ; wait 5000ms
M106 S64 ; slow fan down to 25% pwm
G4 P5000; wait another 5000ms
M106 S[fan_speed_pwm]
The last line includes the variable "fan_speed_pwm". If this M106 command exists inside your starting script
S3D will not add it in front of your script later, like it does now. It will take the layer 1 temperature set on the cooling tab.

This way you should be able to do whatever you want and simply tell it at the end of your start script to
"take over" the value set for layer 1.

This is very close to another very common thing mentioned: Heating. Some people would like to heat bed/extruder in
a specific order - but unless you add those commands to your starting script they will be added automatically in front
of it, just like M106.

Here's more information on this all: viewtopic.php?f=8&t=1959&p=7574

Does this help?
samroesch
Posts: 3
Joined: Mon Aug 17, 2020 5:52 pm

Re: BUG: Cooling M106 occurs before starting scripts

Have a look at your start script. One thing you might notice is there's no commands to heat the bed/extruder. S3D will
insert them before your start script, because it sees they are missing.

It is exactly the same for other things, like fanspeed. If there's no M106 inside your start script, S3D will put it in before.
I see, that does make sense that it would be setting those values for the heat before starting scripts, and I can see why it is logical to do the same with the fan.

The slightly insidious part is that I hadn't touched my starting scripts since the day I set up S3D, they are copy/paste directly from the manufacturer, however the issue didn't rear it's head until I innocently changed my cooling settings in S3D from:

Layer 1->0 / Layer 2->100
to
Layer 1->100 (Yes I know this isn't usually a good thing for adhesion)

I carried on assuming my fan would be blowing at 100% all of the time, but in fact it was turned off entirely. For whatever reason, the manufacturer places an M107 (fan off) in their starting scripts, and this works fine as long as Layer 1 is set to 0 in S3D, but breaks if it is not.

I think the most foolproof, and cross compatible behaviour would be if S3D applied the M106, and maybe even the nozzle/bed temps again at the start of Layer 1, in addition to applying them before the starting scripts.

For what it's worth, CURA posts the fan speed at Layer 1, after the starting scripts.

Code: Select all

;Generated with Cura_SteamEngine 4.6.2
M140 S60
M105
M190 S60
M104 S200
M105
M109 S200
M82 ;absolute extrusion mode <----- Default manufacturer starting scripts
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
M107 ;start with the fan off
G28 X0 Y0 ;move X/Y to min endstops
G28 Z0 ;move Z to min endstops
G1 Z15.0 F50 ;move the platform down 15mm
G92 E0 ;zero the extruded length
G1 F200 E3 ;extrude 3mm of feed stock
G92 E0 ;zero the extruded length again
G1 F50
G0 Y20 F50
M117 Printing...
G5
G92 E0 <----- Start of print
G92 E0
G1 F2400 E-6
;LAYER_COUNT:113
;LAYER:0
M106 S255 <----- Fan speed set!
M204 S3000
M205 X10 Y10
parallyze
Posts: 352
Joined: Fri Jun 05, 2015 4:18 am

Re: BUG: Cooling M106 occurs before starting scripts

samroesch wrote: Wed Aug 19, 2020 10:40 am I see, that does make sense that it would be setting those values for the heat before starting scripts, and I can see why it is logical to do the same with the fan.

The slightly insidious part is that I hadn't touched my starting scripts since the day I set up S3D, they are copy/paste directly from the manufacturer, however the issue didn't rear it's head until I innocently changed my cooling settings in S3D from:
Did you ask S3D for a profile? You can send them an email and they will send you a profile if they do have one. As far as I can tell they do have
access to numerous profiles not yet available to the public.
I carried on assuming my fan would be blowing at 100% all of the time, but in fact it was turned off entirely. For whatever reason, the manufacturer places an M107 (fan off) in their starting scripts, and this works fine as long as Layer 1 is set to 0 in S3D, but breaks if it is not.
It does break because that M107 shouldn't be there. And S3D simply doesn't touch the start script except to fill in variables and check for some specific commands. That's the part where one can customize everything, doing something like changing orders or putting commands in the middle would somewhat defeat the purpose of it...

M107/fan off is usually to be found in the ending script (or implied by M18/M84, depending on firmware/model/version)...


"for whatever reason" - I wonder if the manufacturer does even know about the single steps inside that script, depending on what manufacturer we're talking about. I remember a lot of copy/paste start scripts setting vref to all steppers to max (on sailfish/makerbot clones)... and everybody copied it and wondered why the extruder stepper would reach 70°C on a 60 minute print...
Did you ask them why they put this into the start script they recommend for s3d? Maybe there's a simple explanation we both don't know off.

I think the most foolproof, and cross compatible behaviour would be if S3D applied the M106, and maybe even the nozzle/bed temps again at the start of Layer 1, in addition to applying them before the starting scripts.
That sounds more like a "let's en-/disable or set something AGAIN because some start script might do something whatever"-workaround ^^
And did you check it's the same way with Slic3r/PrusaSlicer, KISSlicer, ReplicatorG, MatterControl, IdeaMaker, Cel Robox - is there any cross compatability to be found?
Just because Cura does add it at another position it doesn't mean all the others handle it like this. How does Cura behave if you reordered the
start script there? You can do something like in S3D there, too. The variables do have different names, but it's based on the same principle...
For what it's worth, CURA posts the fan speed at Layer 1, after the starting scripts.

Code: Select all

G92 E0 <----- Start of print
G92 E0
G1 F2400 E-6
;LAYER_COUNT:113
;LAYER:0
M106 S255 <----- Fan speed set!
M204 S3000
M205 X10 Y10
If you simply add M106 S[fan_speed_pwm] as the last line inside your start script, the gcode will look like this:

Code: Select all

G28 ; home all axes <------ Start of my "starting scripts"
G1 Z5 F3000 ; lift
M107 ; fan off <------- Turning fan off here will not be altered by S3D, and will remain off for the rest of the print 
G5 ; enable resume from power failure
M900 K0.0
G1 X10 Y5 F1500 ; move to prime
G1 Z0.2 F3000 ; get ready to prime
G92 E0 ; reset extrusion distance
G1 X80 E10 F600 ; prime nozzle
G1 X80 F5000 ; quick wipe
M106 S64 ;                                     <---- [fan_speed_pwm] replaced with 64 -> 25% on Layer 1 / Cooling Tab
; process Process1
; layer 1, Z = 0.180
M135 T0
G92 E0.0000
G1 E-1.0000 F1800
; feature skirt
Instead of putting it in front of your start script, S3D will leave M106 where it is. After M107 at the end of the script.
Result is the same, fan speed is set right before selecting the tool and starting the print...

Or simply remove the M107, so far there's no reason to have it in there anyways...?
Bluemalu
Posts: 3
Joined: Thu Jun 19, 2014 12:01 pm

Re: BUG: Cooling M106 occurs before starting scripts

Resurrecting an old thread with some further info.

I have a dual extruder printer, T0 and T1 change the Tool but this is setup in the start up scripts, so...

If the system powers up, T0 is normally chosen. Simplify creates it's gcode but the code generated is
G90
M83
M106 S255
; Startup script.....

Unfortunately, if you are only using the T1 extruder the M106 command will start the T0 part cooling fan. If the speed isn't changed on the T1 part cooler will not start.

Solution:- Don't put in the M106 command in the pre startup section, put it in the layer 1 section- would require an update....

Solution: Switch off all fans with M106 P0 S0 and M106 P1 S0 in startup script and ensure that the fan is switched on to the required speed on layer 2. A bit clumsy but it works.

Return to “Troubleshooting and Bug Reports”