Need help with G-code temperature control

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.

So you have the M140 S40 in your machine end G-code ?

Maybe this will work.

M140 S40 ; set bed to 40c
G4 P60000 ; wait 1 min add or remove as needed
G4 P60000
G4 P60000
G4 P60000
G4 P60000
G4 P60000
G4 P60000
G4 P60000
G4 P60000
G4 P60000
M140 S0 ; turn off bed

Also you can disable the ;M140 S0 in end g code and keep the bed at 40c might work for you just remember your bed will be on until you power down or run some end G-code with M140 S0 active.

I have only seen the opposite behavior (on the X1C): If waiting for heating to 230°C, it seems to move on at 220 or 225 already, which is not a problem because whatever it then does will take some time anyway so the actual target will be reached in time. Maybe that’s a deliberate off-by-5 or whatever. But this would not explain what you’re seeing.

I did notice the Marlin reference has “M190 Sxx” as “set temp to xx and wait (if heating)”, while you would need to use “M190 Rxx” if you want it to wait even if cooling. Apparently Bambu has “S” waiting for cooling as well and I’m not sure they even support “R”, they never use it.

BTW what happens if you set it to wait for 47°C? I’d try that just for curiousity.