05-13-2014 03:27 PM
I have a simple PID script running inside of a timed loop to control a heating process. It works perfectly except that I cannot find a clean way to start the timer when it reaches the setpoint.
Right now, the loop just runs for a set amount of time (e.g., thirty minutes). I want it to run for a set amount of time after the heating reaches the setpoint. I can think of several ways to fudge this, for example with a couple of shift registers and a case structure or with a second loop, but these options seem very clunky.
I am sure there is a better way. Can I somehow create an event within the loop that only happens once, for example, to give a timer value one time when a boolean value changes and never rewrite it?
Thanks in advance for your help.
05-14-2014 06:58 AM
You could keep the boolean value in a shift register or a feedback node. You then need a little bit of logic to check to see if the boolean changed from false to true. From there, you can put in your get timer inside of a case structure.
05-14-2014 11:51 AM
05-14-2014 02:21 PM
@stephencox wrote:
I decided to just initialize a shift register at 0 and increment it every time the process value equals the setpoint.
I probably would not use an equal comparison. What is the datatype of the value?
05-14-2014 02:24 PM
Ok, it's not actually an equals comparison. It increments the dummy value everytime the setpoint is within an acceptable range of the setpoint. Anyway, datatype is integers, so equals would work--I'm using a cheapo USB thermocouple reader that outputs integer temperatures, which is fine because we can easily tolerate +/- 2 degrees during the run. The important thing for us is to avoid overshoot, so we require a modified PID routine that heats very conservatively.