I hope someone can help me understand the nuances of g-code execution in the firmware of my P1P.
I am using custom g-code to take an action based on bed temperature. My understanding is that there are two g-codes that control bed temperature.
- M140 S[bed_temperature_initial_layer_single] ; set bed temp
- M190 S[bed_temperature_initial_layer_single] ;wait for bed temp
The first variant (M140) sets the target temp and continues immediately executing the following code, while the second variant (M190) sets the target temperature and halts further execution of gcode until that temperature is reached.
Nozzle temp is controlled the same way. I have noticed that the temperature reading on the display does not always exactly match the set temp when execution continues. I do understand PID control and how with a given set temp that the temp will vary slightly up and down from the set point. However, I would expect the code execution after M190 to continue when the temp is exactly 190. Similarly for the nozzle temp, I would expect the code execution to continue when the nozzle temperature reaches the set point even if the temp varies a bit after than.
My issue is that I am using M190 S40 to wait for the bed to cool down to 40C in order to allow parts to release before pushing them off the bed. For some reason, code execution does not continue until the bed temp reaches 33C.
Why?
Observations
It is not a matter of polling speed for bed temp because:
- the temp changes very slowly
- code execution has been paused so there is nothing to interfere with constant monitoring of the temp
- the display is updating very quickly as indicated by the display of nozzle temp (which changes quickly) and the MQTT output which has a very high sample rate.
It is also not because temp is going down instead of up, because in the standard start machine code waiting for the set point may occur when the temp is going either up or down (waiting for the nozzle to be 140 or below before touching the nozzle to the bed when homing, or bed temp getting up to the required print temp before performing bed level calibration.