# Getting the most out of PID Control - Modelling HLT/1V, RIMS and HERMS



## Adr_0

Hi all,

A lot of people add a PID controller to their rig as they offer awesome potential for controlling your temperatures. There are a lot of configurations and applications: 1V BIAB (internal) and HLT only; RIMS with temp control in mash or in tube (becomes the same whether 1V or 2V); HERMS with HLT, controlling HLT vs mash return; and HERMS with a small (e.g. 2L) vessel.

I'm a chemical engineer by trade and have been lucky enough over the last 10 or so years to work in some cool places, including LNG plants, gas compression/treatment facilities and gas pipelines and facilities. I have been brewing through most of the time as well, but my process control experience has mostly been on distillation columns, gas supply skids for gas turbines and general level/pressure/flow applications. Sometimes you see very complex (and elegant) solutions to problems, sometimes you see complex and poorly applied solutions, sometimes you need very aggressive control because of very fast changes in process conditions but you generally end up recognising that simple controls with some philosophy adjustments can end up being extremely effective, and often the wrong application of technology and/or lack of understanding of the process can cause some issues.

So, a segway to brewing...

This topic is not meant to be about which configuration (BIAB, HERMS, RIMS, etc) makes the best beer as we all know the answer is two cans of lager extract, 3kg of sugar and ferment at 30°C. We should (myself included) recognise that while industrial process control is great and all, some principles do apply to beer but some do not.

I hope some people (myself included) get something out of it and can go away and try things, can learn a few things (myself included), take some of this with a grain of salt (i.e. a sweet-controlling rig does not, believe it or not, guarantee shit-hot beer; and likewise I do understand that a couple of degrees overshoot will too, not ruin beer) and hopefully it's at least interesting reading.

I did these models in Matlab/Simulink and applied principles of how volumes of water/wort behave but I didn't include things like heat loss and dead time. I can easily model heat loss, but I can't actually model dead time which is a bit weird. Anyway.

At this point I've modelled a HLT on its own which will hopefully be useful to people, RIMS with temperature measured on the tube, and RIMS with temperature measured in the mash. I will of course get to HERMS but it might take a couple of weeks.


----------



## Adr_0

In each case I am just using a 30L HLT/mash tun with a 2400W element, which is hopefully pretty normal. In all cases I have modelled a step from 55°C to 65°C, which is nice and neat at 10°C change but is also hopefully something that people do.

HLT Setup:
View attachment HLT Only Model.pdf


HLT:



This is the response you get with integral set to 10min and P set to anywhere from 0.5-5 gain. Because temperature tends to climb when you apply power, any integral control tends to accumulate error which just results in overshoot and doesn't actually help you. Integral over 15 seconds will be horrible but even 10min (as above) gives you really bad overshoot.

Similar setup with just P only, same gain:


This is the response with a gain of 1 and no integral or derivative control at all. It is basically just what you'd see with the element on full but controlled pretty well.



This is the element response with just Proportional control.

So hopefully from this you can see that generally P is only required, PD will also work (not really necessary) and PI is going to give you a world of hurt when the probe is in the HLT - still TBA how it goes with HERMS.


----------



## pcqypcqy

This is gold. I like it when a bit of rigour is applied to things. I too have an engineering background (not process though), and I'm always tempted to run off and buy gadgets to go high tech, but have to restrain myself and remind myself that the outcomes won't necessarily change. Especially when gadgets cost MY money (as opposed to CLIENT'S money )

KISS rule applies as ever.


----------



## Adr_0

Let's try this again. Few cosmetic changes required.

For the element sizing, it's probably not a bad idea to try an equation like this:

[Water mass x heat capacity x 1°] / 60 which should give you the power you need in W to get 1°C/min

30 kg x 4180J/kg.K x 1K / 60s = 2090W so a 2200W or 2400W would be a good choice for this setup.

Some cosmetic changes:


So this is PI control on the HLT. As I was saying, the way the integral control works is that it keeps on building up error and adding this to the output (a % of 2400W) but then it's suddenly at the setpoint, but has all this extra output it thinks it needs to get the setpoint. An integral time of 600s (10min) is not particularly aggressive, but there is still a pretty bad overshoot.

This is the same gain used with the above, but with the Integral term not included in the PID:



Better. 

Realistically, the temperature of the PI controller would stay a lot higher as there is no negative power coming out of the element, but the power response goes negative. I should put heat loss into these models so that it will at least eventually settle, but that's one reason overshoot is annoying - not so much that the enzymes might be slightly different from what you wanted, but the fact that it can take 30min to settle down to the planned temperature.


----------



## Adr_0

pcqypcqy said:


> This is gold. I like it when a bit of rigour is applied to things. I too have an engineering background (not process though), and I'm always tempted to run off and buy gadgets to go high tech, but have to restrain myself and remind myself that the outcomes won't necessarily change. Especially when gadgets cost MY money (as opposed to CLIENT'S money )
> 
> KISS rule applies as ever.


Yeah, you're spot on. My existing setup is a 2V which works well for me, but I would appreciate some autonomy (walking away without concern for temperature) and flexibility doing step mashes. I too just went straight for the PID, but in a lot of stuff an on-off controller will work - not sure what the cycle life is on STC relays, but it's probably comfortably within a few years of brewing.

It's good to be able to model some ideas, for e.g. different pump rates back into the mash tun. A higher pump rate will have a lower gain from the element, because it has less time to get temperature. It should however be able to cycle over volume in the mash tun faster. 7.2L/min vs 5L min knocked 3min off the ramp time, with exactly the same heating element. That's pretty cool.


----------



## Cervantes

Way out of my league......................... :unsure:

Are you saying that and STC1000 would do a better job of controlling mash temperature than a PID?


----------



## Adr_0

So, here we have a RIMS setup.

Specs:
2400W element
Tube is 0.6L volume, RTD right on the tube
PID is controlled in the middle of the mash tun
LBP at 5L/min



So you can see that the mash tun response again hits what you would expect from a 2400W element, with about 75W of heat loss from the mash tun.

The only catch is that the tube (shown by the purple trace) gets quite a bit hotter, 72°C in this case, or 7°C hotter than the setpoint. Is that bad? I don't think so, but it might give you dramas if you went to a 71°C step for example.

So this is the same example as above, with 7.2lpm vs 5lpm. I figure this is probably the most you actually get out of an LBP:



And here is the same example above, but with only 2L/min:


So up around 83°C, or 18°C above the setpoint. Enzymes being deactivated there I'm sure - there's 7.5min where the temp in the tube is above 76°C. Probably not good.

So what did we learn? High pump flows are very good for RIMS systems, and likely for HERMS as well. Go as high as you can without compressing your bed.

The PI values that came out of the Simulink tuning were:
Gain 0.9
Integral seconds - 3600s (1hr), so to be honest you might as well set to zero. Interesting. So here, with RIMS and PID measuring in the mash, high pump flowrate and just proportional control does the trick.


----------



## Adr_0

Cervantes said:


> Way out of my league......................... :unsure:
> 
> Are you saying that and STC1000 would do a better job of controlling mash temperature than a PID?


I hope it's not out of your league, I will try and put a few summary points after each bit and maybe a table at the end.

An STC1000 would control better than a badly tuned PID. I don't want people to spend hours with autotune, or putting in integral times that are way off and get massive overshoot as a result.


----------



## MastersBrewery

The rims tube getting hotter than setpoint IS bad. The enzymes you are trying to affect are in the wort not just the grain, the grain bed will catch up in a short time. So in the example above your wort over shot 7c for the period of the ramp, this is why for herms and rims the thermo is located at exit of the heat exchange. Otherwise liking the data.


MB


----------



## Adr_0

So, here are a couple of RIMS with PID measuring from tube:



So this is Simulink tuned to be quite gentle (very low gain, long integral action) and gives a fairly good response. There is about 2°C of overshoot in the tube, the mash gets to within 1°C in 10min or less and there's less than a degree overshoot in the MT. Looks very graceful.

This is my rough tuning with 5lpm. Good that there's no overshoot in the tube, but the mash response says it needs more flow:



So at 7.2lpm there is 0.8°C overshoot in the tube, is within 1°C in under 10min but still takes 13-14min to get within 0.1°C of the setpoint.


----------



## Adr_0

MastersBrewery said:


> The rims tube getting hotter than setpoint IS bad. The enzymes you are trying to affect are in the wort not just the grain, the grain bed will catch up in a short time. So in the example above your wort over shot 7c for the period of the ramp, this is why for herms and rims the thermo is located at exit of the heat exchange. Otherwise liking the data.
> 
> 
> MB


Yeah, spot on... while I would say it's risky to get too aggressive on the tuning (keep the gain fairly low, e.g. 0.8-1.2) you can get away with it with a very high flowrate. Essentially you can do anything, but you need to understand the implications. Measuring in the MT is possible, but you need to not get too aggressive on the gain and keep your flowrate as high as possible.

Summarising...
- If you have RIMS with measurement in the mash tun, you need high flowrate to protect your wort from overheating. Great, I really needed to do Matlab models to figure that one out.
- If you have RIMS with measurement in the tube, you have much greater control over your wort temperature (better protected) but you need high flow to not lose too much time getting to your setpoint. You can fiddle a bit more with tuning, see what you have on your display and look at when your power drops to a couple of percent to know that your mash is at temperature, unless you use another probe.
- If you are just controlling a HLT, stick to P only control (set I and D to zero), something like 0.8 to 3 would be fine. Stir it well. If you have BIAB, keep the pump flow high and you should be laughing with just P control. Any feedback from people who have done this?
- If you have HERMS, I'm going to take a gamble and suggest that P only would be the best here too... we'll see in a week or two.


----------



## Adr_0

Here are the HLT response graphs:
30L water in the HLT
75W of loss to atmosphere (probably not unrealistic)
2400W element
Step change from 55-65°C
Assumed stirred vigorously

Response with P set to 2, I for 10min (sensible numbers):


Overshoot is 2°C, element switches off completely and takes however long to get back down to the setpoint. Stirring would help this.

And Proportional control only, P set to 2:



Interestingly, you can see the power flatlining after it hits setpoint - at 75W I'm guessing. If you work out the % your controllers sits at maintaining a temperature (e.g. 1-5%), I guess that would be your loss to surroundings, i.e. 2% of a 2400W element would be 48W.

For 50Hz power it's probably best to set your SSR duration on the PID controller to 3s to get as in phase as possible - most have a minimum 'on' time of 30ms and PID's probably only have a 1% output resolution, so 100 x 30ms = 3s.

Anybody want to try P-only control on a HLT and give me some feedback?


----------



## Adr_0

Hmmm..... think I need to work on some of the factors:



I will see how I go through the week. I think the model is ok but some of the heat transfer factors are likely wrong. Ah well, a work in progress...


----------



## TheWiggman

Didn't you just have a kid Adr_0? Is your wife off at the inlaws?
Love your work. When I have a tunable PID one day I'll refer back to this thread.


----------



## Adr_0

TheWiggman said:


> Didn't you just have a kid Adr_0? Is your wife off at the inlaws?
> Love your work. When I have a tunable PID one day I'll refer back to this thread.


Managed to get a few windows through the day, and I travel on a bus for three hours a day so plenty of time for drawing function blocks and transfer functions.  

I'm impressed you went with on-off control for your HERMS,as proportional is shaping to be the best for controlling HLTs, and with a n element the on-off can be close to proportional anyway. 

I'm really curious to look at sensitivity to flow, coil length, HLT volume and controlling tube temp vs HLT. hopefully some of these cases ring a bell for someone "Hey, that's exactly what my system does..." and they get something out of it.


----------



## TheWiggman

Note the operative word - 'programmable'. My controllers are Jap made Shinko units from an old printing machine built in '87. They're quality, robust and simple PID units with only SV and alarm adjustable. K-type only unfortunately but at this stage I can't justify the cash for new controllers when these units are very effective. The trade off is sloooow settling; they will ramp fairly quickly and not overshoot, but take about 30% of the ramp time in steps for the last 2°C. Increasing flow rates has worked in my favour, once the grain bed is well settled it's full throttle from then on. 
The most interesting point you've made here I think is the P only control for a HLT. Hopefully that will change some minds.


----------



## husky

Awesome, this is right up my alley! I play with control loops at work all the time, usually flow and level but also heating from time to time. I have recently taken to trying to tune the control loops during commissioning before the automation engineer gets involved(im process). I can tell you that when tuning these loops in real world applications I use P and I and have only once had the need to use D. I can't answer any of your questions yet however I am part way through building a new 1V brewery with PLC control where I will be playing around with these exact parameters during commissioning.
I have always found that with my 1V RIMS I needed a high flow rate to get good performance(as you have indicated) however grain bed compacting has been an issue. My new system will have a return to the top of the grain bed and also a return to beneath. I'm also fitting a VSD to the pump so I can play around with flow rate more predictably and test what effect all these same parameters have.
I'll check back when the new brewery and PLC are up and running and I can run some loop tuning(my PID does not have autotune so it will be trial and error tuning to start with). 
Generally speaking I think you always want your temperature transmitter close to your heater as overshoot is not ideal.


----------



## Adr_0

That's cool to hear Husky. Another point a long with high flowrates and keeping the sensor close to the element, is insulating lines. If there is a long uninsulated length of line between your sensor and mash tun, it will result in a drop/gap in temperature. 

I'm keen to hear from HERMS brewers, a few questions:
-what is the size of your mash tun (mash volume actually) and element? 
-does your HEX water boil, assuming you control your outlet temp? 
-what is the volume of water in your HEX? 
-how long does it take to make a 10°C step, and do you get any overshoot?


----------



## klangers

Oh man, I spent countless hours on Simulink for my thesis. I haven't used it since. Would you be willing to share your models?

This is great stuff, I'm going to have to come back and read through this in detail.


----------



## TheWiggman

Adr_0 said:


> I'm keen to hear from HERMS brewers, a few questions:
> -what is the size of your mash tun (mash volume actually) and element?
> -does your HEX water boil, assuming you control your outlet temp?
> -what is the volume of water in your HEX?
> -how long does it take to make a 10°C step, and do you get any overshoot?


1. 36l, typically 3l/kg liquor:grist. 2kW element. For a 4.5kg about 15l including losses.
2. Not during normal operation. Accidentally close a valve however...
3. 2 l I think. Can double check.
4. I haven't actually timed but this will vary depending on controller settings obviously. No to overshoot. Will get back to you on next brew day provided my wife hasn't arranged other activities during mash time.


----------



## Adr_0

klangers said:


> Oh man, I spent countless hours on Simulink for my thesis. I haven't used it since. Would you be willing to share your models?



Sure - it will be good to have someone check my numbers. It will also be good to set the variables to your system and see how close it gets. 



TheWiggman said:


> 1. 36l, typically 3l/kg liquor:grist. 2kW element. For a 4.5kg about 15l including losses.
> 2. Not during normal operation. Accidentally close a valve however...
> 3. 2 l I think. Can double check.
> 4. I haven't actually timed but this will vary depending on controller settings obviously. No to overshoot. Will get back to you on next brew day provided my wife hasn't arranged other activities during mash time.


Ok, so when you say you could accidentally close a valve, you circulate water through your HEX I assume? Does that water go back to the HLT to cool off a bit?


----------



## TheWiggman

Basic process is -

Fill MT to mash-in volume, set temp on controller and turn pump on.
Dough in: turn off pump, controller and HEx outlet valve.
Wait 5 mins, turn on pump and _just_ crack outlet valve. Set controller to first step temp (i.e. 52°C)
Gradually open valve every few mins until full flow is achieved
Go through mash cycles
FLY SPARGE - reconnect pipework so
HLT > Pump > HEx > MT
MT > Kettle

For the sparge I open the drain valve for the MT so it's trickling into the kettle, aiming for a 45 min - 1h sparge. I then open the HEx discharge valve to match that flow which as you can imagine, is hit and miss. It's a balancing act for about the first 15 mins. Now if I'm dumb enough to accidentally leave the discharge valve closed then there is no flow past the thermowell and the controller will simply leave the heating element on.


----------



## Adr_0

Ok, think I understand. I was curious if the WATER in your HEX boils. I can understand if you have the wort return closed this would overheat


----------



## mofox1

TheWiggman said:


> Will get back to you on next brew day provided my wife hasn't arranged other activities during mash time.


Sounds more entertaining than I assume was intended...


----------



## Adr_0

mofox1 said:


> Sounds more entertaining than I assume was intended...


Make sure a protein rest is done... 

I've done a few examples - using referenced and calculated values for heat transfer - and seem to be getting only 2-25W being picked up by the coil. That is examples with a few degrees temperature difference, 1 or 2m coil lengths and up to about 40-45°C (based on boiling water). This was based on 5lpm wort flow through the coil. 

So I guess what this suggests is that once the HEX ramps up to temp, most of the heat goes into the water around the coil rather than the coil itself, causing the water to continue heating (to boiling?) until the tube set point is reached. It's hard to say what the best control would be, but theoretically you should be able to match the coil output to the demand from the coil/mash. But at only a few watts (even with a 2m coil) it's not a lot of power going in, so the ramp rate would be slow. 

If the water in the HEX is boiling, this would really help the heat transfer and power, but the catch is that it would subsequently cause a lot of overshoot because your heat source is now at 100°C but your mash is at 65 or 76°C - with no way to cool it. 

I would just like to get a better idea of what goes on so that I can model it and try and get the best tuning/configuration out of it.


----------



## trevgale

I think the heat transfer into the coil is better than what the model is showing. I have a 2L HEX with a ~2m long 12mm diameter stainless coil. I haven't compared the temperature difference but I would not expect it to be greater than 20 deg C. I only get boiling in the HEX if I accidentally shut a valve in line with the coil or if I heat to over 85 deg C for cleaning. 

Hope this helps.


----------



## verysupple

:huh: "gluten" = "the"?

Kids been playing with your phone?


----------



## trevgale

Yeah, shortcut setting on iPad. I think my wife might be messing with me. Either that or my 1yr old is a genius.


----------



## Adr_0

This look a bit more realistic?


----------



## verysupple

trevgale said:


> Yeah, shortcut setting on iPad. I think my wife might be messing with me. Either that or my 1yr old is a genius.


Ha, I figured it was someone playing funny buggers.

And I should also say great work, Adr_0! I love this kind of stuff - someone with some know-how applying what they know and sharing. Keep it up.


----------



## fcmcg

Adr_0 said:


> I'm keen to hear from HERMS brewers, a few questions:
> -what is the size of your mash tun (mash volume actually) and element?
> -does your HEX water boil, assuming you control your outlet temp?
> -what is the volume of water in your HEX?
> -how long does it take to make a 10°C step, and do you get any overshoot?


1.Mash tun is a 100 litre keg...usuallu dough in with about 15 kg grain , thereabouts and 45 litres strike water ..2400watt element
2.Doesn't boil , usually...unless its been ramping for a while and the water level gets a bit low..( i must put a lid on it)
3.HEX is a 10 litre pot
4. 10 degree step usually takes 17 to 25 min depending on ambient temp , actuall mash volume.No overshoot

I'm usuing some old shimaden SR44 pids that came out of Generous Motors...
I don't even know how to program them as i have no manuals and they are at least 10 yrs old


----------



## trevgale

1.Mash tun is a 50 litre pot, dough in with about 11 kg grain , thereabouts and 27 litres strike water ..3000watt element
2.Doesn't boil under normal operation starts to boil if trying to heat I excess of 85 deg C for cleaning
3.HEX has a 2 litre volume
4. 10 degree step usually takes around 8-10 min.No overshoot

I'm using and Auber ramp soak PID.


----------



## Adr_0

Ok, one more go tonight and I might have a bit more of a play later in the week. This five days in a row of not drinking is making me do crazy things...

This is a bit better:
- Pulls power out of the HLT better (almost like the coil EXCHANGES heat with the HEX/HLT now... amazing)
- Less sensitive to coil sizing
- Seems to give about 10-12°C warmer in HEX/HLT which is what most people see



Tuning-wise, it looks like it's pretty flexible with a variety of gains and integral times, which is sweet.

However if the HEX is more than about 20-30% of the mash tun size, there is some nasty overshoot.


----------



## trevgale

Those results look like they match pretty well with what I see on my HERMS. We I was researching prior to setting up my system there were discussions about overshoot and poor response with larger HEX sizes. The consensus seemed to be the smaller the volume the better.


----------



## Adr_0

trevgale said:


> Those results look like they match pretty well with what I see on my HERMS. We I was researching prior to setting up my system there were discussions about overshoot and poor response with larger HEX sizes. The consensus seemed to be the smaller the volume the better.


Yeah, bingo. I was confident of that, but wanted to understand how coil length and P vs PI control would impact the response. 

I will put another comparison up in a few days. If people aren't convinced big HEX = bad response after all the threads and these response curves (coming in a few days), they deserve the overshoot headaches.


----------



## trevgale

Adr_0 said:


> Yeah, bingo. I was confident of that, but wanted to understand how coil length and P vs PI control would impact the response.
> 
> I will put another comparison up in a few days. If people aren't convinced big HEX = bad response after all the threads and these response curves (coming in a few days), they deserve the overshoot headaches.


It's always good when the modeling matches with the observed results. As an engineer I know it can be difficult to achieve sometimes.


----------



## mofox1

You've convinced me to take some measurements on my next brew day...

Mine is the "big hex" scenario.... So big you might call it a HLT. h34r:

Usually 70L water in there, my initial tests with 60L could ramp the HLT by about a degree every 45 or 50 sec, but that was without recirc thru the coil. Other (separate) tests showed no discernable difference between the coil out temp and the HLT, even with a 10 degree difference between the mash and HLT temps. But I haven't looked at overall system response wrt to overshoot...

For the greater good, I must brew!

So, mash in at 55, get everything stable, and ramp to 65... I can do that. Should probably also check what values the autotune set.


----------



## Adr_0

Sweet! I'm doing a brew this weekend too, to try a different set of PI values. 

The 'effectiveness' I was using was 2.5% which got pretty good results. I just realised I made a slight surface are a boo-boo on my original numbers, and I'm getting calculated values of 0.5% for a 2m copper coil, 2.3% for 10m copper and 3.6% for 16m copper. My original calculated effectiveness values were more like 0.005%. Sweet. Stainless numbers are about 80% of these. 

This means more power, but at the expense of time constant (time to get to this temperature). Curious to see the impact of the balance...


----------



## Adr_0

I think if you have a largely volume HEX and a long coil, your HEX temps will only be a couple of degrees above the coil outlet temp. 

I would say that Integral control would cause some overshoot in the HEX temp, but would say this would help the initial ramp rate and would hopefully even out by the time you got close to your setpoint. 

What is not yet clear is the impact that a time constant of 7-20s William have on overshoot. It might not be that significant by the time it gets to the mash. 

If your coil length is small on a big HEX, the HEX temperature will sit pretty highly normally, and will be exacerbated when using Integral control.

Anyway, I'll have a look at it all and see what comes out of it.


----------



## krausenhaus

Hey Adr_0, I haven't had a chance for a good read of this but can't you model dead time with a transport delay block?


----------



## Adr_0

krausenhaus said:


> Hey Adr_0, I haven't had a chance for a good read of this but can't you model dead time with a transport delay block?


Sort of... The transport delay is discrete though. There is no way to incorporate it continuously in a transfer function with gain and time constant (or for integrating processes like tank heating). The transport delay works but it doesn't look as pretty and probably isn't functionally correct either. I thought it was strange but that's how it seems to be.


----------



## Adr_0

krausenhaus said:


> Hey Adr_0, I haven't had a chance for a good read of this but can't you model dead time with a transport delay block?


Sort of... The transport delay is discrete though. There is no way to incorporate it continuously in a transfer function with gain and time constant (or for integrating processes like tank heating). The transport delay works but it doesn't look as pretty and probably isn't functionally correct either. I thought it was strange but that's how it seems to be.


----------



## krausenhaus

Are you sure you're not thinking of unit delay? Transport delay is a continuous function and is equivalent to e^(-d.s) in a transfer function numerator as far as I remember.


----------



## krausenhaus

Great work by the way!

One thing that's confusing me though, don't you need to include mass flow rate through the coil to get power? It looks to me like that quantity is just heat per unit mass. Sure I'm missing something though.


----------



## Adr_0

The mass flow rate and heat capacity are included in a transfer function within the Coil subsystem. 

Power / (mass flow x heat capacity) = dT which is essentially the gain, ie change in temp for a given power input. 

Its ends up being a gain of 0.00305 or so for 5lpm. The time constant is included in the transfer function as well. 

This spits out a coil differential temperature (temperature gain) which is added to the mash tun out/coil in temp.


----------



## krausenhaus

Cool, but what's bugging me is it looks like the power parameter going into the TF isn't in units of W.


----------



## Adr_0

Ah, you're right! 

The heat capacity is multiplied by the effectiveness, 0.025, which says how much of the potential power actually gets through but this should include a mass/flow rate to correctly represent power. 

These pretty well balance out though, as although the 3950kJ/kg.K is now 3950 x 0.05kg/s, the effectiveness goes from 0.025 to 0.467 or so, because the effectiveness factors this in as well.

Although the units were not correct in the model, the numbers were the same coming out. I will fix it though as it will be more accurate when varying flows.


----------



## krausenhaus

Adr_0 said:


> Ah, you're right!
> 
> The heat capacity is multiplied by the effectiveness, 0.025, which says how much of the potential power actually gets through.
> 
> These pretty well balance out though, as although the 3950kJ/kg.K is now 3950 x 0.05kg/s, the effectiveness goes from 0.025 to 0.467 or so, because the effectiveness factors this in as well.
> 
> Although the units were not correct in the model, the numbers were the same coming out. I will fix it though as it will be more accurate when varying flows.


I was getting confused because the results all looked good even though it seemed one parameter was out by a factor of 100! Strangely I was never taught to use/calculate effectiveness so I wasn't sure how that would be affected.

How did you choose the time constant values?


----------



## Adr_0

If you know all the temperatures coming in and out of a heat exchanger, you can use the log mean temperature difference method... But because we don't know two of the temperatures we can't use that method. 

Because two temps are unknown, you needs to use the Effectiveness/NTU method, which is essentially how effective the heat exchanger is based on UA, heat capacities and maximum theoretical power. You can then work out the temperature change on each side as you get a power output from this. 

The time constants were just volume/flow. It might nor be absolutely correct, but they should be close enough in lieu of measurements.


----------



## Adr_0

Ok, graph time.

In each of these, I had the same 2400W element, 30L mash tun, and modelled 3L, 10L and 30L HEX volumes.

First one is with a 5m copper coil, 5lpm pump flow, Proportional control only:




Second is a 10m coil, 5lpm pump flow, P control only:



Third is a 10m coil, 5lpm but using some Integral control - 10min in this case, which I wouldn't call aggressive:



Even with 1000s Integral (normally the most that they go up to, at least the Aubers) it's pretty horrible:



And finally with a 15m copper coil, 5lpm, back to P only control:




I did a comparison of time constants as well, using 11s vs 120s. Bugger-all difference. 120s is not realistic for a coil as it would need to be about 150m long. So that's sweet.

More good news is that as much coil as you can fit will help get more power from the element to the mash. It will help 'buffer' the HEX temperature and will have a direct impact on ramp time because it means more power is getting through. Just try to keep the HEX volume below 10L by the look of it.

There may be tuning parameters - e.g. with Derivative control - that don't have any overshoot and I might give the Simulink tuning a go again, but it is evident that a large volume HEX is best avoided if possible - assuming you are controlling on the coil outlet that is.

Cool.


----------



## Adr_0

I will repost with time scales in better ranges than 0.278 hrs... 

A few things look pretty clear if you have HERMS and control element power using coil outlet temp:
- stick to P control only, definitely do not use I (set to 0) and D is not needed
- for a 30L mash volume, HEX volume should not be bigger than 10L, and aim for about 10m of copper tube or 12-14m stainless. More than this has diminishing returns, as your ramp time only really improves by a tiny bit but it costs a lot and is more to fit in
- 3L HEX volume is ok, but I think you will struggle to get more than a few metres of tube in, and definitely won't get 10-12m. I would say a more powerful element will help, but you will need to be conscious of boiling the water, which could overpressure a sealed HEX or run an element dry. 

I will have a look an larger volumes and flow effects as well.


----------



## trevgale

Adr_0 said:


> I will repost with time scales in better ranges than 0.278 hrs...
> 
> A few things look pretty clear if you have HERMS and control element power using coil outlet temp:
> - stick to P control only, definitely do not use I (set to 0) and D is not needed
> - for a 30L mash volume, HEX volume should not be bigger than 10L, and aim for about 10m of copper tube or 12-14m stainless. More than this has diminishing returns, as your ramp time only really improves by a tiny bit but it costs a lot and is more to fit in
> - 3L HEX volume is ok, but I think you will struggle to get more than a few metres of tube in, and definitely won't get 10-12m. I would say a more powerful element will help, but you will need to be conscious of boiling the water, which could overpressure a sealed HEX or run an element dry.
> 
> I will have a look an larger volumes and flow effects as well.


Thanks for the undertaking the analysis and providing the results. It has led me to have a play around with the PID settings on my 4V HERMS system.

I had previously just auto tuned it, I wasn't bad but I did get some overshoot on the HEX output temp which would buildup and result in higher than desired MLT temps. Anyway I have just been playing around with setting I=0 and d=0 and using P only. Anyway with a bit of playing around I have ended up with just using P and a small d, this seems to have provided the best results with ramp time and minimising overshoot.

I have only been testing with water today, I'll see how it performs next brew.


----------



## Adr_0

Awesome, good to hear!

You have a 2L HEX and 2m coil, right? What is your element size and mash volume?

Interestingly with those specs, a 2400W element and 25L mash volume (assumes volume of fluid, not esky size) something like P of 0.2 seems to work best, while more than that gives overshoot and some steady state error. Still can do it without D, apparently.


----------



## trevgale

Correct on the HEX volume and coil length. I have a 3000W element and my mash volume is typically around 27.5L of water to 11kg of grain. I am using an Auber PID which I don't think use the typical Kp Ki Kd values. I ended using a P of 300 and a D of 25. Adding the D value seemed to hold the temperature a little better. Auber claim that their PID controllers have fuzzy logic, I'm not sure if this is true or has any effect. 

In addition to the 27.5L of water I added about the same amount of water as the grain I would normally have. I figured the increase in malt density would be approximately offset by the difference in specific heat capacity.


----------



## Adr_0

trevgale said:


> Correct on the HEX volume and coil length. I have a 3000W element and my mash volume is typically around 27.5L of water to 11kg of grain. I am using an Auber PID which I don't think use the typical Kp Ki Kd values. I ended using a P of 300 and a D of 25. Adding the D value seemed to hold the temperature a little better. Auber claim that their PID controllers have fuzzy logic, I'm not sure if this is true or has any effect.
> 
> In addition to the 27.5L of water I added about the same amount of water as the grain I would normally have. I figured the increase in malt density would be approximately offset by the difference in specific heat capacity.


Hey mate,

With the Aubers, P of 300 is a traditional P of 3. D of 25 is nothing to be afraid of, but it won't do anything to 'hold' your temperatures - this is purely done by the gain. I would steer away from Integral control as it will only cause you headaches. The disturbances are probably from cold pockets, stirring, or something like that.


----------



## Adr_0

So, below should be some hopefully good starting points:

1V:
Just use P control, e.g. P of 1 to 5, or on the Aubers use P of 100 to 500. Keep the pump circulation up, or stir as much as you dare during the step changes. 1V will give you the value out of your element.

RIMS with T in the tube:
This is a pretty bulletproof setup and will give the second best ramp rates for a given element size. You should be able to set the P to 1 to 5 (100 to 500 on Auber) and that should be fine. Keep the pump circulation as high as you dare with your mash tun geometry. You can use a bit of Integral control with RIMS where you measure temperature in the tube, but don't make it less than 60s - e.g. 120 or 180s. This will cause you to overshoot a touch in your tube (a couple of degrees) and you need to decide if you're comfortable with that. KISS is probably best here.

RIMS with T in the mash:
This can be a dangerous setup. High circulation is your friend here and low circulation (e.g. 1-3lpm) will cause some serious dramas. Use P control only if you want to keep it simple (P of 0.2 to 0.5, 20 to 50 on Auber).
If you want to keep your wort safer, use P of 0.5 and some D control as well, e.g. 25 to 100. If you are losing too much ramp rate, check your in-tube temperature and drop this back a bit.

HERMS:
This is a graceful and handy setup but the ramp rates are inherently compromised unless you have a super-long coil and small HEX volume, and can open yourself to overshoot and very slow ramp rates if you have the opposite. You generally need PD control with HERMS, but if you have a relatively small HEX and/or a lot of coil you should be able to to just use P.
High flow, as with all setups, is best. 10-15lpm as long as you can stop your bed compacting is great.
Coil length, try to have it at least 3-5m of copper for a start. Check out page 73 of the HERMS guide for a bit on coils.
HEX volume... if you can have 5-10m of copper you should be ok up to 30-40% of your mash kg (e.g. up to 10L for a 25kg mash) but it can be dangerous (inherent overshoot, slow ramp rates) if you only have a couple of metres of coil. If you have 2-10L HEX this is probably ideal for a 25kg mash, and fit as much coil in as you can.
Big HEX, short coil: start with P of 1 (100 for Auber) and D of 100-200. If you are still getting overshoot, don't touch the P but increase the D, maybe 300 or 400. If it's too doughy, drop the D down to 50-100.
If you have a decent coil and a fairly small HEX you can probably try something like P of 5 (500), I of 0, D 0, 50 or 100 - see how you go and adjust as above: if it's doughy, reduce the D; if it overshoots increase the D.

Feel free to msg me if you want any pointers.


----------



## Adr_0

Forgot to say... 

If you have HERMS and measure temp in the HEX, just use P. It's pretty well impossible to get overshoot, but your ramp rates can be pretty bad. To compensate, you should stuff as much coil in as possible, and have the highest circulation rate possible. A bigger element can help, but you are potentially better off - if keeping 10A is important - measuring T in your wort return. You should generally get better ramp rates as you approach your set point, vs measuring T in your HEX.


----------



## Tex N Oz

I've spent many years tuning PID loops and it can be a PITA!!! Makes me wonder if I could use adaptive loop tuning software on a HERMS......


----------



## Adr_0

The biggest issues tuning PID loops - other than the hours and hours staring at control panels - is when you have a second-order process and don't know it - or somebody doesn't know it - and don't have the appropriate control structure for that (i.e. feedforward + feedback) and you're trying to control it with a single PID controller.

Luckily in the brewing world we don't have distillation columns, or sensitive multi-pass heat exchangers between multiple distillation columns....

Most auto-tune functions in PID controllers have an algorithm that will set P, I and D. Unfortunately, if you are trying to control tank temperature, where a given heat input/step will cause a continuous rise in temp (rather than the temp now settling out and staying steady), Integral control is the last thing you want. It's sort of like having a bucket of red hot coals next to your HLT, then just as you are approaching your setpoint, throwing them in. So you only need P or PD control for any BIAB, HERMS or RIMS setup.

If you have a big HEX in comparison to your mash volume (30% up to 100% of your mash volume) and a lot of coil length to back that up you can probably get away with just P control. If you don't have any overshoot you should be able to tick this up a fair bit until you don't get anything more out of it. If you have a relatively short coil (e.g. less than 6-8m in a 1:1 HEX:mash, e.g. 100L HEX, 100L mash; or less than 2m with a 1:3, e.g. 10L HEX, 30L mash or 30L HEX, 100L mash) you will need some D in there.

Simple is good. If you need to tune the crap out of a PID controller and/or need a massive element on a small system, check your system before blaming the element or PID controller.


----------



## mofox1

Adr_0 said:


> ...when you have a second-order process...


A second-order process...

...second order process...

Oh god. Now I'm remembering my control systems lectures... and now laplace transforms. Dammit. I thought I killed that with beer.


----------



## DJ_L3ThAL

Haha laplace were ok, fourier was the devil!!!


----------



## nala

Adr_0 said:


> So, below should be some hopefully good starting points:
> 
> 1V:
> Just use P control, e.g. P of 1 to 5, or on the Aubers use P of 100 to 500. Keep the pump circulation up, or stir as much as you dare during the step changes. 1V will give you the value out of your element.
> 
> RIMS with T in the tube:
> This is a pretty bulletproof setup and will give the second best ramp rates for a given element size. You should be able to set the P to 1 to 5 (100 to 500 on Auber) and that should be fine. Keep the pump circulation as high as you dare with your mash tun geometry. You can use a bit of Integral control with RIMS where you measure temperature in the tube, but don't make it less than 60s - e.g. 120 or 180s. This will cause you to overshoot a touch in your tube (a couple of degrees) and you need to decide if you're comfortable with that. KISS is probably best here.
> 
> RIMS with T in the mash:
> This can be a dangerous setup. High circulation is your friend here and low circulation (e.g. 1-3lpm) will cause some serious dramas. Use P control only if you want to keep it simple (P of 0.2 to 0.5, 20 to 50 on Auber).
> If you want to keep your wort safer, use P of 0.5 and some D control as well, e.g. 25 to 100. If you are losing too much ramp rate, check your in-tube temperature and drop this back a bit.
> 
> HERMS:
> This is a graceful and handy setup but the ramp rates are inherently compromised unless you have a super-long coil and small HEX volume, and can open yourself to overshoot and very slow ramp rates if you have the opposite. You generally need PD control with HERMS, but if you have a relatively small HEX and/or a lot of coil you should be able to to just use P.
> High flow, as with all setups, is best. 10-15lpm as long as you can stop your bed compacting is great.
> Coil length, try to have it at least 3-5m of copper for a start. Check out page 73 of the HERMS guide for a bit on coils.
> HEX volume... if you can have 5-10m of copper you should be ok up to 30-40% of your mash kg (e.g. up to 10L for a 25kg mash) but it can be dangerous (inherent overshoot, slow ramp rates) if you only have a couple of metres of coil. If you have 2-10L HEX this is probably ideal for a 25kg mash, and fit as much coil in as you can.
> Big HEX, short coil: start with P of 1 (100 for Auber) and D of 100-200. If you are still getting overshoot, don't touch the P but increase the D, maybe 300 or 400. If it's too doughy, drop the D down to 50-100.
> If you have a decent coil and a fairly small HEX you can probably try something like P of 5 (500), I of 0, D 0, 50 or 100 - see how you go and adjust as above: if it's doughy, reduce the D; if it overshoots increase the D.
> 
> Feel free to msg me if you want any pointers.


Brewed today with my revised PID parameters which you helped me with.
Great success...held the mash temperature witnin 0.2 degrees of target 66,no overshoot at anytime,ramp time 1 degree /75 seconds.
Decided to check the outflow wort temperature and suprisingly only 1.2 degrees lower that the inflow.
As you know I mash with 20 litres of water,I used 5.950 kgs of grain and mashed for one hour the HEX neon was cycling showing small inputs of power most of the time, never overshot once.
This has been one of the most rewarding exercises that I have done, appreciate your help very much.
I am attaching a picture of my controller showing the temperature of the wort.


----------



## Adr_0

That's awesome Alan, great to hear. It's all about making the brew day a little smoother and more consistent, and happy to help.


----------



## TheWiggman

Here's a curly one - what if you used the auto tune function and then changed the I to zero? Would that be worse than manually guessing the P and D values?


----------



## Adr_0

Ha ha, that is a curly one - try it. I would say you'd get a pretty doughy response. It depends what your response is at the moment, but with all things even and to get the same response, setting I to 0 you should raise the P a bit and drop the D a bit.

If it's still really doughy, raise the P more or drop the D a bit. If you are getting overshoot, drop the P a touch and raises the D a bit.


----------



## Tex N Oz

Hi Adr_0
I'm currently working on my HERMS system but I'm taking a very different approach to temperature control. I recognise that almost everyone is trying to perform a finite temperature control by modulating the temperature of a relatively large volume of medium and an unstable heat exchanger flow rate. In industry this is almost unheard of as the rate of change for this volume is too slow and compounded with an ever changing flow rate through the heat exchanger. One could greatly reduce error by introducing a second control loop operating a diverting or mixing valve and a simple bypass line.
The second control loop would need to have a proper sized valve for decent authority and real proportional controller (4-24mA, 2-10V,... blah blah). 
Alternatively, or additionally, you could add another process to control pump flow rates through a smaller heat exchanger. Initially it would be more difficult to tune but it's inherent stability would add incredible accuracy. If you controlled by variable flow rate then you'd never expose your wort to over-temperature as you would through a diverting/mixing process but I don't know exactly how that would effect your conversion.
If you added all of these controls together I'm thinking you could control maximum heat exchanger temperature and wort return temperature by varying flow and mix rates.
What are your thoughts on this? Am I way over-thinking the value of this level of accuracy?


----------



## Adr_0

Hey Tex,

What would you be bypassing, and what is your heat source? And when you say accuracy do you mean at all points of the wort circulation/grain bed or just good temperature response wherever you're controlling it? The proportional output of off-the-shelf PID's is time proportional. It's not as good as varying voltage or mA, but it's close enough. If you consider the output cycle is over 2-3s and we're interested in 15s, 30s or a couple of minutes order of magnitude it's acceptable anyway. I guess you could vary phase or amplitude on an element?

In terms of over-temperature, actually if you had a diverter (I assume one 'side' hot, the other is the mash?) and 'diverted' the hot wort away from the mash, this would still have an amount of hot wort somewhere, which would denature the enzymes or potentially scorch the wort. Switching/diverting hot wort is not how you avoid overshoot as it's complex as you're potentially controlling two things (diversion amount, heat input) when one (heat input) is absolutely fine. Overshoot is more a factor of capacitance (large volume of water) which can be offset by heat exchanger efficiency (coil length), which means that your water volume doesn't get that hot anyway, i.e. the energy efficiently gets into the coil rather than the water. I made this argument myself a little while ago, but some thinking and modelling turned me around.

In terms of accuracy through the grain bed and to temperature response, a system with a pump is best. So the accuracy is more down to system layout (short lengths of tube, high pump rates, good wort distribution and collection) than BIAB vs RIMS vs HERMS.

If you are worried about the inefficiency of a heat exchanger (coil), go RIMS - simple as that. You will essentially get all of your heat input directly into the wort. Get the RTD close to the element and have good wort distribution through your bed, etc.

If you're set on HERMS, the 'effectiveness' I've talked about is essentially how much of the heat you have in your HLT/HEX water vs how much actually gets into your wort. I've got a graph on page 73 of the HERMS guide that you should check out if you're curious - and surprise surprise the more coil the better (if you can fit it in, if you can afford it, if your pump can handle the increased back pressure). I haven't modelled pressure drop and 1/2" vs 3/8", sorry...

In terms of varying pump rate, high is best, but once you hit a certain 'gain' in your HLT/HEX and coil (i.e. HEX small enough and/or coil long enough), the overshoot and response profile start to look the same, and just the overall rate improves as the wort circulation goes up.


----------

