RepRap Firmware heating

From RepRap
Jump to: navigation, search


On all printer firmwares, you find heating loops, mostly controlled with PID algorithm. All self-build printers and a lot of commercial printer suffers from heterogeneity in temperature displayed values. This does have many sources.

Calibration is needed for the heating loops and its code shall be written in config.g:

  • G-code for thermistor and ADC calibration is M305 (was M304 on old firmware version)
  • G-code for PID loop is M301 (alternatively M304 could be used for BED PID)

Note that if there is no code in the config file, defaults values are used.

As for most RepRap Firmware documentation on this wiki, some details of this page apply only to recent Firmware version of DC42 or Chrishamm forks (1.10 or later).

Temperature measurement

Due to very low sensor cost and simplicity of the electronic, most printers are using thermistors for temperature measurement. The resistance of a thermistor with "negative temperature coefficient" (NTC) reduce while its temperature increase. This is not linear and for the type of thermistor used in printers, the resistance became fairly low when approaching 300°C, decreasing the precision in this range. In addition, 300°C is the maximum temperature usable for most thermistors and they tend to failed if used over this temperature.

In the simplest approximation method, 2 parameters are used to qualify a thermistor: first its resistance at a fixed temperature, generally 25°C then the rate of resistance change for a temperature modification named "Beta". It is an approximation and so this Beta coefficient is only valid for a reduced range of temperature. This is the method used in RepRap Firmware. Other firmware may use tables instead of this formula, which may be more precise but the tables are not always available.

Common resistance for printer thermistors is 100 kOhm at 25°C, sometimes 10kOhm thermistors are used for Bed.

Typically for 100k NTC thermistors the Beta coefficient vary from 3800 to 4200.

Unfortunately, for a same reference, the parameters varies for each manufactured part.

Analog converter

Duet schematics for thermistors.
VSSA is analog ground

For thermistor, this is a voltage which is measured by the microcontroller. A current flows through the thermistor and the voltage drop in thermistor is measured. To limit the current flow, a fixed resistor is installed. The value of this resistor have an important effect on the measure. On the first batches of Duet 0.6 boards, these resistors were 1kOhm and later this was modified to 4.7kOhm. It shall be noted that Replikeo clone boards v0.6 are in principle, still using 1kOhm resistors. All 0.8.5 boards are using 4.7kOhm resistors. The electronic circuit measuring the voltage in the micro-controller is called an Analog to Digital converter, ADC in short. The values given by these ADC have also significant variation for each manufactured unit, and for all ADC within the same controller.

The parameters of M305 command are :

  • Pnnn ;heater number: 0 is bed, 1 is extruder 0, etc.
  • Tnnn ;thermistor resistance at 25°C, typically T100000 (100k), sometimes T10000
  • Bnnn ; beta coefficient , shall be defined for the usable range, typically B4200 for a 100k thermistor
  • Rnnn ; value of the board resistor 1000 for old 0.6 boards, 4700 for others – see your board documentation.
  • Lnnn ; ADC low offset – shall be measured according below method
  • Hnnn ; ADC high offset – shall be measured according below method
  • Xnnn ; Heater ADC channel . Sensor remapping – mostly used if the thermal sensor is not a thermistor. See other sensor type

Typical example :

M305 P1 T100000 R1000 B4200

Heating power

Most heaters use resisting material which heats while current flows. The resistance varies somewhat while the material is heating, but a measure of resistance while cold gives a valuable element of comparison within different units.

Again, there is significant manufacturing variability of power for a given model of heater.

The power (often noted W) of a resistive heater is equal to = Resistance * Current^2.

The current is : Voltage / resistance, so W = Voltage^2 / resistance. So the power rise very quickly with voltage.

RRF allow power limitation for heaters in M301/M304 codes. If your voltage exceed the nominal voltage of the heater or if the heater resistance is lower than expected, You may want to limit the power, which can be done with a coefficient limiting the PWM ratio. This coefficient default to 1 and is names S. So S0.8 will cap the PWM ratio to 80% of the time.

This also may be used if your power supply power is a bit insufficient, however this only will work if your power supply have high capacitors on their output to limit the pulse due to the PWM. The power of an heater increase as the square of the voltage, so the limit shall be approximately the inverse of square of the extra voltage. e.g. if you are using 14V power supply for a 12V cartridge, the coefficient shall be (12/14)^2 = 0.735, entered as S0.735.


To compare temperatures, you need to calibrate the equipment. This is especially important for a multi head printer to have the same behaviour within all the heads. For measure, two thing shall be calibrated :

  • The Analog to Digital converter (ADC)
  • The Thermistor
  • A third element is of utmost importance for calibration, this is the board resistor value, you shall rely on documentation or board inspection to confirm it.

Sometimes, at room temperature, the temperature indicated by the software is -273 °C (absolute zero), which indicates the measure temperature is out of the range, due either to wrong parameters or ADC variability in excess of what can be measured. If you get this temperature, if your parameters are correct and the thermistor is properly wired, you shall calibrate the ADC (see below), as software will not start the heating loop without a temperature measurement.

ADC calibration

Duet ADC calibration.jpg

Parameters for thermistor and ADC are handled by M305 code. DC42 fork of RepRap Firmware added parameters for ADC calibration since v 0.57u (march 2014) For ADC calibration, you will need two resistors, one of 220 Ohm (1%) and one of 100kOhm (1%). It is practical to connect these resistors to Dupont connectors, which may help to avoid false contact while measuring.

  • Connect the 100K resistor at the thermistor pins and adjust the H parameter to get a reading as close to 25°C as possible (you probably won't manage exactly 25°C because the ADC quantum is about 0.6°C at this temperature).
  • Then substitute a 220 ohm 1% resistor and adjust the L parameter to get a reading of 260.1°C.
  • Change the resistor back to 100K, check you are still getting a reading close to 25°C, and fine-tune the H parameter if necessary.

This shall be done for each ADC of your board, as there could be more than 10°C variation within different ADC on the same board.

Note: Software will indicate a temperature of 2000°C for a shorted thermistor.

Thermistor calibration

While buying a thermistor, check that either the exact model or NTC coefficient is supplied. You may check a thermistor by measuring its resistance at known temperatures if you have the appropriate tools. The room temperature resistance is easy to check and you also can easily check 100°C (boiling water at sea level) , which is nice for a bed thermistor, but far from the used range for a hotend thermistor. If you have a trustable thermometer for comparison, you can test with a hot oil bath (dangerous!). Then you can enter the measured resistances in this calculator or this Libre office sheet which will give you the Beta coefficient. It shall be noted that the beta parameter is an approximation which is only valid in a given temperature range.

Remember water boiling temperature change with altitude, e.g. you will have 90.5°C boiling temperature in Quito (Equator). You already have 99°C at 305m altitude.

Control loop PID parameters


PID algorithm is the most used control method for closed loop system. It stand for Proportional, Integral and Derivative and is described in details in many web pages. It does exist algorithms which can test the feedback of the heating loop and evaluate automatically the PID parameters. However (as of May 2016), there is not yet any auto-tuning algorithm in RepRap Firmware and you have to adjust parameters manually. RRF DC42 fork added a few parameters to improve the control (command M301 and M304).

Tuning a PID loop is not an easy task. Some are using a mathematical method named Ziegler-Nichols, which may be long to undertake and may not give convincing results. One manual strategy is defined Here

The RRF default values are a good starting point.

M301/304 parameters

  • Hn : Heater number (only for M301) H0: bed, H1: E0, H2: E1…
  • Pnnn : Proportional coefficient
  • Inn : Integral coefficient
  • Dnn : Derivative coefficient
  • Wnnn : Maximum value of the integral ‘accumulator’. Limit the effect of integral after long heat/cool phase
  • Tnn: Percentage of PWM (scale 0:255) to maintain 1°C temperature rise. To get it, run a few times M573 to get the average percentage, then T value shall be : (M573 result)*255/(temperature rise over ambient, by example 215-20=195). This parameter is specific to RRF, but when properly adjusted, it will improve notably the control.
  • Bnn : When measured temperature difference with the set-point temperature exceed this value, control is on/off

Hotend parameters

Hotend default parameters are reasonably accurate on all metal hotends and others (e.g. RepRapPro hotends).

Default parameters :

M301 Hn P10 I0.1 D100 T0.4 W180 B30 ;n being the heater number: 0 for bed, 1 for hotend 0, etc.

For an hotend with low inertia and high power as the Fisher delta hotend, other parameters were used (with a heating block insulated with Kapton and no part cooling).

M301 H1 P12 I0.25 T0.21 D70 W150 B20 S0.7; power is limited as the cartridge is 50~60W

It shall be noted that if you insulate your Hotend with polyimide tape or use a part cooling fan, that will modify the loop feedback, and you may modify its parameters. Try first to re-evaluate T parameter (which is linked to the thermal loss).

Bed parameters

Bed control is set by default to ‘bang-bang’ control, which is just an on/off switch while measured temperature exceed a given difference with the setpoint. It is quite unstable with oscillation within 10/15°C range, so it is recommended to use PID control. It shall be noted that for bed control, the PWM frequency is lowered to 10Hz (on recent firmware) and so is compatible with SSR.

'P-1' proportional coefficient is used to indicate bang-bang control so there is no default proportional coefficient for a PID loop, but a starting point is setting the proportional coefficient to 85.

With this proportional coefficient, the default for bed PID control became:

M304 P85 I5 D500 T2.7 W255 B5

These default may be reasonable values for relatively high inertia bed (Glass bed or thick aluminium).

Another example with a top surface which create insulation on the top of the bed (printbite) with 280W for a bed of 700 cm2.

M301 H0 P85 I0.25 D750 T1.3 W200 B5; 'M301 H0' is equivalent to M304

Using Ziegler-Nichols method

  1. Set S to 1.0, P to 20, B to 30, and I, D and T to zero.
  2. Command the hot end to a high temperature, say 250°C. As soon as it reaches 160°C, command it to 0°C. Watch the temperature to see how much it overshoots. Set the B value to about 5 to 10 higher than the amount of overshoot.
  3. Command the temperature to 250°C and wait. It won't ever reach 250°C because of the zero I and T terms. When the temperature has stopped increasing, read it off, also use M573 P to get the average PWM.
    Set the T value as follows:
    . T = average_pwm*256/(temperature_reached - room_temperature)
  4. Now follow classic Ziegler-Nichols tuning. With the temperature set to e.g. 200°C, increase P up to the point at which the temperature shows regular oscillations. Call this value Posc.
    Measure the period of the oscillations, call this Tosc. Then:
    . P = Posc/3 (increase/decrease this if desired to increase/decrease the overshoot)
    . I = 2P/Tosc
    . D = Tosc * P/3

Maximum temperature

There is a maximum temperature for hot-ends which will stop the heating loop and trigger a default if it is reached, even for a very short time.

This maximum temperature is defined by code M143 and its default is now 260°C (from V1.12) while its used to be 300°C.

Heating timeout

There is a safety which stop the heating and trigger a default if the temperature setpoint is not reached within a given time.

This timeout is defined by M570 and the default value is 150 sec. This timeout is not activated for bed and chamber heating (from v 1.12).

If you get this default, you may question the power of your heating cartridge, but this is also often related to poor PID adjustment. Insulation of the heating block will help.

Evaluating instant heater power

There is a code M573: Report heater PWM which gives you the PWM ratio currently in use for heating, on a scale from 0 to 1.

The PWM ratio varies permanently with the loop control, so you may run this code three or four times and calculate mean value to get accurate result.

This helps you evaluate your heater power (which is proportional to the PWM ratio) at the operating temperature and may help evaluate if difficulties to reach a temperature are related to poor PID adjustment or insufficient power. This is also used to adjust M301 T parameter.

Controlling temperature

Other sensor type

Why using other sensor

Due to the limitation of thermistors, other type of thermal sensors may be used. They need external small conversion boards with serial communication (SPI) to the main board. You shall be cautious not using boards with 5V level shifters, which may kill your main board (maximum signal voltage is 3.3V on Due processor).


Thermocouples are the most frequently used sensor type in industrial environment. They are rugged and can stand high temperature. They produce a very low voltage while submitted to temperature. They are reasonably precise even when not calibrated (~2°C). The terminals and cables metallurgy shall be specific and related to the thermocouple type (most frequently ‘K’ type). These constraints explains why they are less frequently used than thermistors in printers.

However, some are using them because of their better reliability at high temperature.

See Using_thermocouples_with_the_Duet_and_RepRapFirmware.


Pt100 is another type of resistive sensor.

The name stand for Platinum (Pt) resistance of 100 Ohm at 0°C.

It can be very precise and is usable with higher temperatures than thermistors (max ~600°C), but it is sensitive to parasites if connected with only two wires.

See Using_PT100_temperature_sensors_with_the_Duet_and_RepRapFirmware.

See also

In addition to site licence GFDL1.2, this page is also released under license CC BY-SA 4.0