In the PID RelayOutput Example the output is going to a digital pin which (we presume) is controlling a relay. The pid is designed to output an analog value, but the relay can only be On/Off.
void loop()
{
Input = analogRead(0);
myPID.Compute();
/************************************************
* turn the output pin on/off based on pid output
************************************************/
unsigned long now = millis();
if(now - windowStartTime>WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if(Output > now - windowStartTime) digitalWrite(Relay1,HIGH);
else digitalWrite(Relay1,LOW);
}
I would like to extend the RelayOutput principle with the ability to control two relays. An example is a heating application with one 800W element and one 1200W element. The possible power level output will then be 0, 800, 1200 or 2000W.
That example code is doing PWM on the relay. The 'Output' variable is a pulse width in milliseconds. The relay is activated for that amount of time and then deactivated until WindowSize milliseconds.
To prepare for more heater elements I have made it a little more generic. And for me it is easier to think of the added power in the 0 - 100% range. . .
void setup()
{
//tell the PID to range between 0 and 100
myPID.SetOutputLimits(0, 100);
}
void loop()
{
if (Output > 80)
{
digitalWrite(Heater1200Pin, HIGH);
digitalWrite(Heater800Pin, HIGH);
}
else
if (Output > 60)
{
digitalWrite(Heater1200Pin, HIGH);
digitalWrite(Heater800Pin, LOW);
}
else
if (Output > 40)
{
digitalWrite(Heater1200Pin, LOW);
digitalWrite(Heater800Pin, HIGH);
}
else
{
digitalWrite(Heater1200Pin, LOW);
digitalWrite(Heater800Pin, LOW);
}
}
But what about the level/border to enable the full power, set to 80% in my example code?
hufza:
But what about the level/border to enable the full power, set to 80% in my example code?
Will the output ever be 100?
This is still confusing me, please help!
When the PID algorithm calls for more than 80% power the heater will go to 100% power until the demand drops below 80% again.
To make the power more linear you could PWM the heaters like in the original example. For the 0-800W range you would PWM just the 800W heater. For 800-1200W you would PWM the 1200W heater from 66% (800W) to 100% (1200W). For values above 1200 you would keep the 1200W heater full on and PWM the 800W heater from 0% (1200W) to 100% (2000W).
Are these mechanical relays? Or some kind of heavy duty solid state relay?
I'm looking to control a 1500W oven and wondering what to use for the AC power switching.
CrossRoads:
Are these mechanical relays? Or some kind of heavy duty solid state relay?
I'm looking to control a 1500W oven and wondering what to use for the AC power switching.
I expect they are mechanical relays, otherwise you'd just drive them from PWM outputs.
If a suitable Solid State Relay was available for reasonable cost I would use that with a PWM output.
hufza:
If max output is 100, and the 2000w level is set to > 100 then it will almost never ever be activated? Am I right or wrong?
If you change the code to activate 2000W at >100 (instead of >80) and you set the max output to 100 the 2000W output will never activate. That's why you keep it at 80.
No comments on the code. I wanted to add that solid state relays are great for applications like this. I have gotten any number of good SSR's from ebay and Criagslist.
One thing you must do is make sure you have a heatsink on the unit as it does not much inefficiency at 1000 Watts to toast out a solid state device.
The hot-liquor-tank (HLT) is a 25 liter tank heated with one element with two loops (800+1200w). I expect to use 20-40 minutes to heat water to different levels after a full refill during the brew process.
The boil kettle will have a normal batch size of 30 liters and is heated with two elements. One with two loops (800+1200w) and the other is a single 2000w element. I expect heating from wort mash temperature of 65C to boil will take 20-30 minutes.
The plan is to use two pid processes to control total of 5 relays. The set points will change according to the advancing states of the brew process.
Question: As I understand it, you are already using PID to control the energy you're applying to your HLT. What problem are you solving by splitting the 1200 & 800 elements? Why not just use it as a 2k element all the time, and simply let the PID do it's job?
Editing: I'll add this, as my post above comes across as more contentious than I intended.
I suggest that you just join the elements and use them simultaneously because the PID library is expecting, when you go from 79% to 80%, for your HLT to respond to a 1% increase in power. If you're writing a second element HIGH, then a 1% increase in output is going to result in 150% increase in actual energy being injected into the HLT. I don't see how the PID can provide accurate control in that situation.
For what it's worth, I just went down this road with the PID library, using a 5.5kw element installed into a 15.5 gallon (58.6 liter) keg.
CrossRoads:
Are these mechanical relays? Or some kind of heavy duty solid state relay?
I'm looking to control a 1500W oven and wondering what to use for the AC power switching.