PWM vs Time Proportional PID Heating Control

The forum for discussing all kinds of brewing paraphernalia.
brewzone

PWM vs Time Proportional PID Heating Control

Post by brewzone » Sat Jan 13, 2018 9:42 pm

I have been working on a PID system based on the Arduino PID libraries.

Reading all I could on the subject of PWM vs Time Proportional Heating Control I decided to do some comparison runs.

I created a simulation routine to save Me having to run the tests in a real world environment.

This helped speed the whole process of tuning the PID settings Kp Ki and Kd.

Auto Tune worked with several degrees of overshoot.

In the end I went for a step test tuning method.

Creating graphs from the output of the Arduino serial.print command over Bluetooth and recorded using Minicom on the RPI3.

I eventually got the overshoot down to 0.04C in simulation and 0.67C on a 33L test system.

I am working on removing the slight overshoot due to lag and will post the results when I achieve the 0.04C on the 33L system.

Here is the PID system.

Image

Here is a graph of the Time Proportional run.

Image

Here is a graph of the PWM run.

Image

The Blue line is Set Point, Red is Process Variable and Black is the Output from the PID compute command.

I used the same Kp Ki and Kd values for each run.

Time Proportional reached a steady state very quickly with the Output settling at 2.35% and maintains the temperature at exactly 63C.

PWM has the Output ringing anything between 0.1% and 47% and maintains the temperature at exactly 63C.

Exactly the same code albeit for the analogWrite(RelayPin, Output); vs digitalWrite(RelayPin, HIGH/LOW);

I am hoping to get the PWM runs to settle to steady state of 2.35%

PID sample rate is 1000ms.

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Sat Jan 13, 2018 11:11 pm

I have run the PWM system again with Kp Ki and Kd adjusted to reflect the Output limit of 255 rather than 10000 for Time Proportional with a 10000ms window.

It now settles to steady state exactly as I wanted.

Will be testing on the 33L system one day next week after I do the decorating I promised I'd do.

User avatar
Kev888
So far gone I'm on the way back again!
Posts: 7701
Joined: Fri Mar 19, 2010 6:22 pm
Location: Derbyshire, UK

Re: PWM vs Time Proportional PID Heating Control

Post by Kev888 » Sun Jan 14, 2018 8:24 pm

Interesting comparison, thanks for posting it.

I suppose ultimately it is the process/red line that matters, and they both seem fairly similar. But do you have any idea how the two methods compare for things like longevity of heating elements and perhaps minimising risk to enzymes?
Kev

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Mon Jan 15, 2018 1:18 am

Kev888 wrote:
Sun Jan 14, 2018 8:24 pm
Interesting comparison, thanks for posting it.

I suppose ultimately it is the process/red line that matters, and they both seem fairly similar. But do you have any idea how the two methods compare for things like longevity of heating elements and perhaps minimising risk to enzymes?
My understanding of the stresses on a heating element is this:

240VAC at 50hz is at 0 volts twice for each cycle ?

So the element is being pulsed at least 100 times a second anyway?

Using an SSR which is switching at zero point is switching the power off or on depending on the clock frequency of the Arduino and also by the PWM value.

I am still trying to get My head around that last bit.

I have no official data regarding the wear and tear any particular element suffers.

As far as enzyme activity goes then I reckon the closer to Set Point We can keep the Process the better.

As for using this in a Herms or Rims I imagine it all depends how much hotter the wort gets in an attempt to maintain the temperature in the mash tun.

If the PID Output is being maintained at 2.35% of total then do We need 4.7% output to keep the temperature in the mashtun at 65C ?

User avatar
Kev888
So far gone I'm on the way back again!
Posts: 7701
Joined: Fri Mar 19, 2010 6:22 pm
Location: Derbyshire, UK

Re: PWM vs Time Proportional PID Heating Control

Post by Kev888 » Mon Jan 15, 2018 11:21 am

Yes, the elements normally run at 50Hz (in the UK), which is fast and smooth enough that their internal gubbins don't change massively in temperature between the cycles.

With on/off pulsed methods of control, unless the controller is synchronised with the AC frequency (e.g. like phase control), then the time-base for creating pulses is usually comparatively slow, and the element wires can cool down more during the 'off' state. So larger temperature cycles are created, which cause greater expansion/contraction and so more fatigue.

It need not be terrible, as has been demonstrated by people successfully using PIDs over the years. But the effect depends quite heavily on the duration of pulse widths/gaps involved, so I wondered if you had any feel for how much your methods may compare WRT an element's lifespan. Time proportional control is very similar to PWM, in fact arguably it is a type of PWM, so there may be little difference in how the Ardinuo runs them, but equally you may be choosing quite different time bases?
Kev

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Mon Jan 15, 2018 12:41 pm

I've supplied hundreds of elements over the years.

Using the high range thermostats I have seen anything between 1 day and still running 7 years later life spans.

The 1 day assumed to be due to boiling dry.

I haven't got enough data in regards pwm vs proportional as yet but I suspect that proportional might allow the element wires to cool down more than pwm.

PWM acting more frequently but smaller changes.

I wouldn't be surprised if they were very similar life spans.

Be nice to speak to a Carlton Element engineer for Their input.

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Tue Jan 16, 2018 5:49 pm

Kev888 wrote:
Sun Jan 14, 2018 8:24 pm
Interesting comparison, thanks for posting it.

I suppose ultimately it is the process/red line that matters, and they both seem fairly similar. But do you have any idea how the two methods compare for things like longevity of heating elements and perhaps minimising risk to enzymes?
Been away and had a think about the enzyme part of this question.

In a RIMS system where the element is in direct contact with the wort the issue is more relevent than in a Herms where the wort is inside a coil.

The point at which the wort is in contact with the element has to be somewhere between 100C and the maximum temperature the element can actually reach in a predominantly water based medium.

If the PID has been set at say 65C and the PT100 etc is fitted into the RIMS tube/pot then a lot depends on the % of time the element is off or on and how much heat is being lost in the mashtun.

A purist might say mash in a well insulated mashtun for the required amount of time with no loss of enzymatic action other than what would normally be expected assuming strike temperature has been calculated correctly etc.

Daab always made this point during the various spats that went on at that time on the forum.

If We are simply topping up the heat on an occasional basis then enzymatic action should not be effected too much.

But if We are doing say a stepped mash then there is more chance the element is going to be on for 100% of the time required to raise by x number of degrees and potentially more chance of degrading the enzymes.

User avatar
Kev888
So far gone I'm on the way back again!
Posts: 7701
Joined: Fri Mar 19, 2010 6:22 pm
Location: Derbyshire, UK

Re: PWM vs Time Proportional PID Heating Control

Post by Kev888 » Tue Jan 16, 2018 7:31 pm

Yes, the demands on the controller are going to be greater for higher powered systems, all else being equal (and particularly if recirculation rates can start to slow, due to grain compaction). A less responsive controller may still achieve the same average heating effect, yet allow temperatures to swing more greatly immediately around the element.

Pulse duration can be a factor in that, if it becomes long enough to cause significant overshooting. Whether or not that has any (meaningfully) greater detriment on the enzymes depends very much on the context. But as this is one of the things that may differ between your two methods it seemed worth considering in the comparison.

TBH though I have no feel for the type of pulse lengths you are using. In practice PWM usually employs a reasonably rapid time-base, whilst time-proportional control tends to vary more, but both methods could be very short or very long; they needn't be particularly different - its perhaps less a question of which works best but more of how you (or the controller) choose to implement them.
Kev

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Tue Jan 16, 2018 7:45 pm

I have seen a project for a basic oscilloscope using an arduino somewhere.

Ive got a 320*240 TFT screen spare on another Arduino Mega which I could use to make one and perhaps measure the frequency and gain a better idea of the deeper workings of PWM.

The thing I love about the Arduino platform is it tends to slowly move You from one project to another.

Yet to use a Photon etc but no doubt will buy one eventually and try porting a PID over to that.

User avatar
Kev888
So far gone I'm on the way back again!
Posts: 7701
Joined: Fri Mar 19, 2010 6:22 pm
Location: Derbyshire, UK

Re: PWM vs Time Proportional PID Heating Control

Post by Kev888 » Tue Jan 16, 2018 8:37 pm

Ah yes, one thing always leads to another - especially if you need to build test equipment as well as the actual equipment!

But the relative durations we are talking about here are only going to be very important if they are quite different. If this is a test of how the Arduino works with its own implementation of the two methods (rather than the methods more generically) then maybe all you need to know are the rough parameters within which its output works. Measuring actual, slight differences for your own particular setup may not be especially useful.
Kev

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Tue Jan 16, 2018 11:24 pm

I used this system to try out Sous Vide.

The original code has been rewritten as it was designed for a 16*2 LCD screen and I wanted a 480*320 Touchscreen.

The steaks I tried were nice, but I found I enjoyed a simple pan fried steak finished in butter equally delicious.

The eggs were nice though.

Never had a yolk like that before.

User avatar
themadhippy
Even further under the Table
Posts: 2951
Joined: Tue Dec 08, 2009 12:53 am
Location: playing hooky

Re: PWM vs Time Proportional PID Heating Control

Post by themadhippy » Wed Jan 17, 2018 2:08 am

I have seen a project for a basic oscilloscope using an arduino somewhere.
plenty of free sillyscope software for the pc using the sound card for the input,for example https://www.zeitnitz.eu/scope_en
Warning: The Dutch Coffeeshops products may contain drugs. Drinks containing caffeine should be used with care and moderation

JabbA

Re: PWM vs Time Proportional PID Heating Control

Post by JabbA » Wed Jan 17, 2018 5:11 pm

Interesting stuff.

I currently use time proportional control with my Arduino based controller and get ±0.1°C once settled, with minimal overshoot. I've nether thought to try PWM.

With the brewery / sous vide running in the shed I notice the lights in the house dim ever so slightly when the element fires every few seconds! I'll give it a try and see what effect it has.

Cheers,
Jamie

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Wed Jan 17, 2018 7:20 pm

My original reason for modifying the PID code to use PWM was the hope that as the PV reaches SP there was less chance that the 10 second window size used in Time Proportional might allow the PV to go over SP before the PID compute command had time to shut down the relay.

As You can see from the graphs above there was what I describe as a bit of bounce in the Output as it hits SP, but that was due to the Kp Ki and Kd values not having been modified for PWM.

Once I changed those values the Output is virtually the same as for Time Proportional with an immediate drop off to 0% and around 60 seconds later a small oscillation around 2.35%

brewzone

Re: PWM vs Time Proportional PID Heating Control

Post by brewzone » Wed Jan 17, 2018 8:25 pm

JabbA wrote:
Wed Jan 17, 2018 5:11 pm
Interesting stuff.

I currently use time proportional control with my Arduino based controller and get ±0.1°C once settled, with minimal overshoot. I've nether thought to try PWM.

With the brewery / sous vide running in the shed I notice the lights in the house dim ever so slightly when the element fires every few seconds! I'll give it a try and see what effect it has.

Cheers,
Jamie
Are You using a UNO or Mega2560?

I switched to a MEGA2560 for the additional PWM pins it offers.

Post Reply