Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    Wait for passive thermistor temprature to stabilize

    Scheduled Pinned Locked Moved
    Gcode meta commands
    5
    12
    476
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • garethkyundefined
      garethky
      last edited by garethky

      Do you have a passively heated chamber? Maybe one of those thick Rail Core beds with the secondary thermistor on top? Wouldn't it be cool if you could wait for that temperature to stabilize before starting your print?

      I'm talking about something like this:
      Screen Shot 2021-01-29 at 10.25.26 AM.png
      Top Bed Temp takes ~6 minutes to stabilize after the bed reaches temperature. That's going to cause the bed to change shape as it heats through, possibly messing up the mesh bed leveling. Also the temperature or the print surface is supposed to be 90 degrees, but at the point when the bed heater reports that it has heated its barely 60.

      The trouble is generally we don't know what temperature we are waiting for. There is going to be some thermal loss and the temperature will change with the environment's temperature, airflow etc. Really we don't care about the exact value, we just want to know its not changing before printing. So instead of a fixed temp, we can look at the rate of change of the temperature (delta T) and wait for this to fall below some desired value.

      ; wait for the top bed sensor to stabilize
      G10 L2 P9 Y0 ; keep the loop counter here because it can't be used in sub-expressions
      while true
          ; Store the current temperature reading from the Top Bed thermistor:
          G10 L2 P9 X{sensors.analog[5].lastReading}
          
          ; Dwell for 500ms
          G4 P500
          
          ; if the temperature increase is less than 0.01 C over that time break the loop
          if {sensors.analog[5].lastReading - move.axes[0].workplaceOffsets[8]} < 0.01
              echo "Top of bed temperature stabilized at ", sensors.analog[5].lastReading, "C in ", move.axes[1].workplaceOffsets[8] / 2, " seconds"
              break
          
          ; if 5 minutes has passed abort with an error
          if {{move.axes[1].workplaceOffsets[8] / 2} > {5 * 60}}:
              abort "Bed temp stabilization failed after 5 minutes"
      
          ; increment the loop counter
          G10 L2 P9 Y{move.axes[1].workplaceOffsets[8] + 1}
      

      (source in my printer repo)

      When the temperature stabilizes it prints a message to the console:

      Top of bed temperature stabilized at 74.865C in 18.5 seconds
      

      The script will wait for up to 5 minutes before it gives up. You can extend the waiting time, the sensing interval and the threshold to suit your application. With variables it will become possible to do a better job by saving more temperature history, but this works OK for now.

      Even without variables I still need to store the loop counter and the last temperature reading. I'm using workplace offsets 9 as my temporary variable storage area. Be careful this doesn't conflict with with your printer's configuration.

      o_lampeundefined dc42undefined 2 Replies Last reply Reply Quote 2
      • o_lampeundefined
        o_lampe @garethky
        last edited by o_lampe

        @garethky
        I have a bit of programming experience, but I'm relatively new to the RRF conditionals.
        To me it seems, your routine breaks when the momentary value is close enough to the target value?

        That doesn't tell you the temp has stabilized, it's just a coincidental match.
        The real temp graph could be in a wild overshooting phase and you won't notice.

        What really tells you the temp has stabilized, is the difference between momentary max. temp and min. temp.
        If this difference is smaller than your threshold you're ready to go.

        1 Reply Last reply Reply Quote 1
        • garethkyundefined
          garethky
          last edited by

          This is not intended to run an active heater. This is for passively heated scenarios where an actively controlled heater is running at a constant temperature. Its usually the bed heater. So overshoot shouldn't be a concern here because the active heat source is being controlled. Does that make sense?

          It takes a temperature delta between now and 500ms ago. It will break if the delta is negative or smaller than the threshold value.

          The 500ms gap between samples is a substitute for sample smoothing. There might be momentary fluctuations or noise but over 500ms that should be dominated by real temperature change. Its crude but its works for this specific scenario.

          o_lampeundefined 1 Reply Last reply Reply Quote 1
          • dc42undefined
            dc42 administrators @garethky
            last edited by

            @garethky said in Wait for passive thermistor temprature to stabilize:

            Even without variables I still need to store the loop counter and the last temperature reading.

            There is a built-in loop counter, it's called 'iterations'.

            Duet WiFi hardware designer and firmware engineer
            Please do not ask me for Duet support via PM or email, use the forum
            http://www.escher3d.com, https://miscsolutions.wordpress.com

            garethkyundefined 1 Reply Last reply Reply Quote 0
            • o_lampeundefined
              o_lampe @garethky
              last edited by

              @garethky said in Wait for passive thermistor temprature to stabilize:

              Does that make sense?

              Yes, the chance to see overshooting is pretty low in that case.
              I was focussed to understand the way you misused the workplace offsets, I've missed this detail.

              Phaedruxundefined 1 Reply Last reply Reply Quote 0
              • Phaedruxundefined
                Phaedrux Moderator @o_lampe
                last edited by

                @o_lampe said in Wait for passive thermistor temprature to stabilize:

                I was focussed to understand the way you misused the workplace offsets, I've missed this detail.

                Clever workaround for lack of variables.

                Z-Bot CoreXY Build | Thingiverse Profile

                1 Reply Last reply Reply Quote 1
                • garethkyundefined
                  garethky @dc42
                  last edited by garethky

                  @dc42 I wanted that to work and I tried it first. Maybe this is an SBC thing but this program gives me an error when I try to use iterations in the echo statement inside the if statement:

                  while true
                  	echo "Iterations: " ^ iterations
                  	if iterations > 5
                              echo "Final iteration: ", iterations
                  	    break
                  

                  Console output:

                  1/29/2021, 9:59:44 AM 	M98 P"0:/macros/test-iterations.g"
                  Iterations: 0
                  Iterations: 1
                  Iterations: 2
                  Iterations: 3
                  Iterations: 4
                  Iterations: 5
                  Iterations: 6
                  1/29/2021, 9:59:44 AM 	Error: Failed to evaluate "iterations": 'iterations' used when not inside a loop in line 4 of test-iterations.g
                  
                  dc42undefined chrishammundefined 2 Replies Last reply Reply Quote 0
                  • dc42undefined
                    dc42 administrators @garethky
                    last edited by

                    @garethky, which firmware and DSF version are you running?

                    Duet WiFi hardware designer and firmware engineer
                    Please do not ask me for Duet support via PM or email, use the forum
                    http://www.escher3d.com, https://miscsolutions.wordpress.com

                    garethkyundefined 1 Reply Last reply Reply Quote 0
                    • garethkyundefined
                      garethky @dc42
                      last edited by

                      @dc42 3.2 Final

                      === Diagnostics ===
                      RepRapFirmware for Duet 3 MB6HC version 3.2 running on Duet 3 MB6HC v0.6 or 1.0 (SBC mode)

                      dc42undefined 1 Reply Last reply Reply Quote 0
                      • dc42undefined
                        dc42 administrators @garethky
                        last edited by

                        Thanks, I've asked @chrishamm to take a look.

                        Duet WiFi hardware designer and firmware engineer
                        Please do not ask me for Duet support via PM or email, use the forum
                        http://www.escher3d.com, https://miscsolutions.wordpress.com

                        1 Reply Last reply Reply Quote 0
                        • chrishammundefined
                          chrishamm administrators @garethky
                          last edited by

                          @garethky Thanks for reporting this, I can reproduce this problem. It's caused by break which doesn't wait for pending codes to finish, so it terminates the while block before it can evaluate iterations.

                          You can work-around this problem by adding an empty while-loop for now:

                          while true
                          	echo "Iterations: " ^ iterations
                          	if iterations > 5
                                      echo "Final iteration: ", iterations
                                      while false
                                                  ; nothing
                          	    break
                          

                          Duet software engineer

                          garethkyundefined 1 Reply Last reply Reply Quote 0
                          • garethkyundefined
                            garethky @chrishamm
                            last edited by

                            @chrishamm Thanks Chris!

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Unless otherwise noted, all forum content is licensed under CC-BY-SA