Control loop

Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum

Help Support Homebrew Talk - Beer, Wine, Mead, & Cider Brewing Discussion Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

bitteritdown

Well-Known Member
Joined
Nov 12, 2017
Messages
147
Reaction score
41
Coding a control loop for step mashing.

The obvious is a PID loop.

How well does a basic loop work:

while true

delta = desired_temp - measured_temp;

if delta > 0
set ssr on
else
set ssr off
end if

delay 20ms

end while
 
This is going to sound ingenious considering I offer a control system with PID algorithm, but I try to speak honestly at all times...

The reality is, for heating liquid, a simple hysteresis algorithm like yours (though the window is zero) will work well. You will get no overshoot if the liquid being measured is uniformly heated. And that’s the challenge... as you cannot physically uniformly heat it. But you can get close, and in doing so will minimize overshoot/undershoot cycles, or more properly described: oscillation.

The key is very fast recirculation. If you are doing RIMS this is tricky. If you are doing HERMs, then pump the water in the HLT as aggressively as possible. Which is it?
 
Coding a control loop for step mashing.

The obvious is a PID loop.

How well does a basic loop work:

while true

delta = desired_temp - measured_temp;

if delta > 0
set ssr on
else
set ssr off
end if

delay 20ms

end while

that psuedo-code you have there is the P (proportional) part. It's a PID loop with I and D set to zero. That will work fine, but you will have overshoot if you don't have good water flow. So, make sure you are running a circ pump when heating whatever and it'll be fine.
 
Yes, thank you both, I thought as much but just needed verification from those who have gone before me.

It will be single vessel Brew In A Basket (solid walls), 5500w element, constant recirculation, temp probe on mash cap input (top side). Though I've been eyeing a two vessel system (HLT/boil kettle and BIAB mash tun).
 
Yes, thank you both, I thought as much but just needed verification from those who have gone before me.

It will be single vessel Brew In A Basket (solid walls), 5500w element, constant recirculation, temp probe on mash cap input (top side). Though I've been eyeing a two vessel system (HLT/boil kettle and BIAB mash tun).

I have some pretty complex PID loops for motor control. Tuning is tricky, and things like integral windup will eat your lunch unless you handle them. It gets a little crazy with fast stuff like that. Working on it this week in fact.
 
RE: Integral Windup - yes, I can certainly believe working on motor controls you would encounter physical limitations that need to be handled, etc...

It's an interesting exercise to implement the rest of the PID algorithm and I may just do it for fun... (well fun for a software guy anyway).
 
This is widely known as bang-bang control.

It’s not a PID control, although a PID controller with a very high P gain and no I or D would give equivalent results.
 
i currently use an A419 for my temp control and with quasi-vigorous recirculation i can pretty easily stay within 2 F Degrees, at a glance it looks like the code there will be doing almost exactly what my little controller does so id bet on it being successful:)
 
The A419 will invariably have some hysteresis built into it. This is there to protect downstream electromechanical devices from cycling too frequently. The logic above has none, though the A-D circuit measuring the temp might introduce some. It could also respond to noise, meaning right near the target temp, the heater is turned on and off frequently and aberrantly.

Again, this is strictly academic - build it and see what results you get! I am confident the temps held will be good enough for beer!
 
Can better made SSR's handle a 20ms switch cycle? Does it shorten their life span? I would guess a normal PID implementation also switches faster as it approaches the set point (though not constantly like this bang-bang).
 
Can better made SSR's handle a 20ms switch cycle? Does it shorten their life span? I would guess a normal PID implementation also switches faster as it approaches the set point (though not constantly like this bang-bang).

Heating applications are typically extremely slow to respond so switching at 50 Hz is completely unnecessary and in fact won’t even give you any noticeable difference in performance.

For applications that require precise power delivery over very short durations, such as in a light bulb dimmer, you would use a TRIAC. It is much more precise at chopping the AC waveform. It does come at the expense of significant electrical noise though.

The normal PIDs we use generate an output percentage which is then scaled into a percentage of a cycle time. The cycle times are typically from 2 to 10 seconds. This would mean for example if you wanted 50 percent power and you had a 10 Second cycle configured it would be on for five seconds and then off for five seconds.
 
Yes, absolutely agree that 20ms resolution for heating applications is unnecessary and won't provide a noticeable difference in performance. The output percentage / cycle time makes sense and gives me a hint as to how to code the entire PID algorithm.
 
20 ms is crazy fast. In fact the SSR will not functionally switch since the AC waveform is 60 Hz, especially if it is not a random cross type. As @schematix said there is no reason to do this. He is also correct the PIDs convert the net error percentage into a duty cycle for binary power applications. PIDs can also generate a variable or analog signal assuming the power components can accept such.
 
Yes, absolutely agree that 20ms resolution for heating applications is unnecessary and won't provide a noticeable difference in performance. The output percentage / cycle time makes sense and gives me a hint as to how to code the entire PID algorithm.
I would start by looking at the PID library in the arduino playground. It's simple implementation is easy to follow. I have modified it to add a max integral setting to limit the integral windup you get otherwise.

A simple on/off algorithm won't work very well with BIAB. You cannot recirculate fast enough to have uniform heating throughout the entire mash, so you would get overshoot and oscillations.
 

Latest posts

Back
Top