Back to the Gcode Dictionary
M106: Fan On
- Pnnn Fan number (optional, defaults to 0). (In RRF3 relates to the fan number created by M950, NOT the fan pin number on the board)
- Snnn Fan speed (0 to 255 or 0.0 to 1.0))
- Innn Invert PWM (I1), disable fan (I-1), or normal mode (I0, default) (not supported in RRF3, use M950)
- Fnnn Fan PWM frequency (not supported in RRF3, use M950)
- Lnnn Set the minimum fan speed (0 to 255 or 0.0 to 1.0) when a non-zero fan speed is requested.
- Xnnn Set the maximum fan speed (0 to 255 or 0.0 to 1.0) when a non-zero fan speed is requested. (supported in RRF >= 2.02)
- Bnnn Blip time - fan will be run at full PWM for this number of seconds when started from standstill. Default is B0.1 which means that there is a 100ms burst after starting the fan.
- Hnn:nn:nn... Enable thermostatic mode and select heaters monitored. H-1 disables thermostatic mode. (In RRF3 relates to the sensor number(s) created by M308, not the temperature sensor pin number on the board)
- Rnnn Restore fan speed to the value it has when the print was paused (R1) or the last time the fan speed was set and no P parameter was provided (R2).
- Tnnn or Tnn:nn Set thermostatic mode trigger temperature, or temperature control range
- C"name" Set custom name for this fan (supported in RRF >= 2.01)
- Ann Logical pin number that this fan is connected to (supported in RRF >= 2.02) (not supported in RRF3, use M950)
- M106 S127
- M106 P1 T45 S0.7 H1:2
- M106 P1 T40:50 H1:2
- M106 P2 T45:65 H100:101:102
The first example turns on the default cooling fan at half speed. The second example sets the second fan to a thermostatic fan for heaters 1 and 2 (e.g. the extruder heaters in a dual-nozzle machine) such that the fan will be on at 70% PWM when either hot end is at or above 45C. The third example also sets up a thermostatic fan, but this time it runs in proportional mode. The fourth example sets up an electronics cooling fan that starts to turn on when the MCU temperature (virtual heater 100) reaches 45C and reaches full speed when the MCU temperature reaches 65C or if any TMC2660 drivers (virtual heaters 101 and 102) report that they are over-temperature
RepRapFirmware 3 Notes
- The A, F and I parameters are no longer supported. Instead, specify the corresponding parameters in the M950 command when you create the fan.
- The P parameter relates to the fan number created by M950, NOT the fan pin number on the board as in RRF2.x.
- The H parameter relates to the sensor number(s) created by M308, not the temperature sensor pin number on the board.
- If you were using the PB6 tacho input, you must declare this in a M950 command for the fan concerned.
Example - old code:
M106 P2 I1 F25000 ; fan 2 is a 4-wire PWM fan so invert it and use high PWM frequency
M950 F2 C"!Fan2+exp.pb6" Q25000 ; fan 2 is a 4-wire PWM fan so invert it, use high PWM frequency, tacho connected to PB6 on expansion connector
Notes - all firmware versions
The parameter 'S' declares the PWM value (0-255 or 0-1.0). M106 S0 turns the fan off.
If an S parameter is provided but no other parameter is present, then the speeds of the print cooling fans associated with the current tool will be set (see the F parameter in the M563 command). If no tool is active then the speed of Fan 0 will be set. Either way, the speed is remembered so that it can be recalled using the R2 parameter (see below).
If no S parameter is given but the R1 parameter is used, the fan speed when the print was last paused will be set, this allows the pause.g macro to switch off the fans and have them resume when the print is resumed. If the R2 parameter is used, then the speeds of the print cooling fans associated with the current tool will be set to the remembered value (see above). R2 allows the configured fan speed to be passed between tools which is useful on multi extruder printers where the slicing software may not specify the fan speed on tool change and the tool change macros shut down fans when not in use.
The F parameter sets the fan PWM frequency, in Hz. The default is F250, which works with most fans, Try F100 or lower if you find that you can't control the speed of your fan. This parameter is ignored for fans connected to the fan outputs of a Duex 2 or Duex 5 because those outputs don't support variable PWM frequency. The F parameter is not supported in RRF3, use M950 instead.
The T and H parameters allow a fan to be configured to operate in thermostatic mode, for example to use one of the fan channels to control the hot end fan. In this mode the fan will be on with the PWM set by the S parameter (subject to a minimum of 0.5) when the temperature of any of the heaters listed in the H parameter is at or above the trigger temperature set by the T parameter, and off otherwise. Thermostatic mode can be disabled using parameter H-1.
In firmware 1.19 and later, the T parameter may be of the form Taaa:bbb where aaa is the temperature at/below which the fan should be fully off and bbb is the temperature at which the fan should be fully on. The PWM will be set proportionally if the temperature is between these limits.
In firmware versions 1.19 and later, fans can respond to virtual heaters (which have heater numbers 100 upwards) as well as real heaters. If a fan is configured to trigger on a virtual heater whose sensor represents TMC2660 driver over-temperature flags, then when the fan turns on it will delay the reporting of an over-temperature warning for the corresponding drivers for a few seconds, to give the fan time to cool the driver down.
The B parameter sets the time for which the fan will be operated at full PWM when started from cold, to allow low fan speeds t be used. A value of 0.1 seconds is usually sufficient.
The L parameter defines the minimum PWM value that is usable with this fan. If a lower value is commanded that is not zero, it will be rounded up to this value.
The X parameter defines the same for a maximum PWM value. If a higher value is commanded, it will be rounded down to this value.
The I parameter causes the fan output signal to be inverted if its value is greater than zero. This makes the cooling fan output suitable for feeding the PWM input of a 4-wire fan via a diode. If the parameter is present and zero, the output is not inverted. If the I parameter is negative then in RRF 1.16 and later the fan is disabled, which frees up the pin for use as a general purpose I/O pin that can be controlled using M42. The I parameter is not supported in RRF3, use M950 instead.
The A parameter can be used to assign a fan to a different output pin, for example a spare heater output (use a M307 command to disable the heater and free up the pin first). The F parameter is not supported in RRF3, use M950 instead.