Calibrating your new hotend

## How do hotends work?

Hotends have a little heater in them. The heater is turned on and off by the computer board, either a ramps or an MKS. The hotend has to maintain a temporary very closely. It does this by using a PID algorithm. This means that it thinks it knows how fast the hotend heats when it turns the heater on for a certain time period and how much it continues to heat after the heater turns off before it starts to cool. It can also use PWM to turn the heater on partially.

Using this algorithm, it can maintain the temperature very accurately. But if you change anything about the hotend, use a different heat break, move the hotblock relative to the finned heat sink, the parameters change and you need to retune the pid.

## How do I retune the PID parameters?

You need a way to send commands to the printer and a way to see the responses. I personally would Repetier-Host, but Octoprint's console is a good alternative.

If you send an **M205** command, the Repetier software will dump the EEPROM values. Near the end, it gives the parameters for the extruder. These are mine:

```
Recv: EPR:0 216 3 Extr.1 heat manager [0-3]
Recv: EPR:0 217 230 Extr.1 PID drive max
Recv: EPR:0 245 40 Extr.1 PID drive min
Recv: EPR:3 218 7.0000 Extr.1 PID P-gain/dead-time
Recv: EPR:3 222 2.0000 Extr.1 PID I-gain
Recv: EPR:3 226 40.0000 Extr.1 PID D-gain
Recv: EPR:0 230 255 Extr.1 PID max value [0-255]
Recv: EPR:2 231 0 Extr.1 X-offset [steps]
Recv: EPR:2 235 0 Extr.1 Y-offset [steps]
Recv: EPR:2 290 0 Extr.1 Z-offset [steps]
Recv: EPR:1 239 1 Extr.1 temp. stabilize time [s]
Recv: EPR:1 250 150 Extr.1 temp. for retraction when heating [C]
Recv: EPR:1 252 0 Extr.1 distance to retract when heating [mm]
Recv: EPR:0 254 255 Extr.1 extruder cooler speed [0-255]

```

Note that my heat manager is manager 3 - this is a special algorithm that uses dead time - the time that you turn the heater on until it starts to heat. My dead time is 7 seconds. You can learn how to set it at this web page. It is important to check it if you are going to use heat manager 3 and you have changed your hotend.

0 is bang-bang, on when the temperature is below the target, off if above the target. Simple.

1 is PID control

2 is slowbang. Not sure how that works; I found it in the source,

3 is dead time. The algorithm knows how long it takes changes in the heater state to propagate to the thermistor, and uses that exclusively to try and maintain temperature. The hotend temperature management scheme is currently set to this. It seems to always run a few degrees cool when printing. I want tu tune my extruder and switch to PID control.

If your power supply is off, use an **M80** command to turn it on.

Now you have to make a decision how to tune - because tuning has to be done for a temperature. In fact, it would be reasonable to tune for, say, 190C for PLA and 240c for ABS and to switch parameters when you switch materials. I am going to pick a compromise, 220C. I will send this command:

```
M303 S220 C10 X0

```

This means that the software will heat the extruder to about 220C, and will heat the extruder, let it cool and do it again. It will repeat this action through ten cycles. Eventually it will finish and produce this message:

```
Recv:  bias: 161 d: 93 min: 218.84 max: 226.67
Recv:  Ku: 15.13 Tu: 19.46
Recv:  Classic PID
Recv:  Kp: 9.08
Recv:  Ki: 0.93
Recv:  Kd: 22.09
family:Monaco,Menlo,Consolas,"CourierNew",monospace;white-space:pre-wrap;">
Recv: Info:PID Autotune finished ! Place the Kp, Ki and Kd constants in the
Configuration.h or EEPROM

```

\
**X0** puts the changes into the EPROM automatically.- It also changes the type for heat manager to 1. You can see the result by issuing another **M205.** Here is the relevant part:

```
Recv: EPR:0 216 1 Extr.1 heat manager [0-3]
Recv: EPR:0 217 230 Extr.1 PID drive max
Recv: EPR:0 245 40 Extr.1 PID drive min
Recv: EPR:3 218 9.0782 Extr.1 PID P-gain/dead-time
Recv: EPR:3 222 0.9328 Extr.1 PID I-gain
Recv: EPR:3 226 22.0884 Extr.1 PID D-gain
Recv: EPR:0 230 255 Extr.1 PID max value [0-255]

```

You can see that the numbers are the same with the exception of rounding.

Just for the heck of it, I ran the extruder at 220C for a few minutes. Here is the temperature graph: