Go Down

Topic: PID library multi relay output (Read 3035 times) previous topic - next topic

HansF

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.

Code: [Select]
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.

Any suggestions?

johnwasser

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.

You could use 'Output' as Watts:
Code: [Select]

if (Output > 2000.0)
     {
     digitalWrite(Heater1200Pin, HIGH);
     digitalWrite(Heater800Pin, HIGH);
     }
else
if (Output > 1200.0)
     {
     digitalWrite(Heater1200Pin, HIGH);
     digitalWrite(Heater800Pin, LOW);
     }
else
if (Output > 800.0)
     {
     digitalWrite(Heater1200Pin, LOW);
     digitalWrite(Heater800Pin, HIGH);
     }
else
     {
     digitalWrite(Heater1200Pin, LOW);
     digitalWrite(Heater800Pin, LOW);
     }
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

HansF

Thank you, simple and elegant!

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. . .
Code: [Select]
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?

Will the output ever be 100?

This is still confusing me, please help!

PeterH


Will the output ever be 100?

This is still confusing me, please help!


I don't understand your confusion. You've configured the PID to output a value between 0 and 100 so it will output a value in that range.

Code: [Select]

  //tell the PID to range between 0 and 100
  myPID.SetOutputLimits(0, 100);

I only provide help via the forum - please do not contact me for private consultancy.

johnwasser


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).
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

johnwasser


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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

HansF

The relay I will use is a 8-channel opto-isolated relay. http://arduino-direct.com/sunshop/index.php?l=product_detail&p=156.

To PeterH (and others): 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?

johnwasser


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.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

wwbrown

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.

wade

terryking228

Hi Hufza,

What is the "Time constant" of what you are heating?  How often will the relays be turned on and off??

You might want to use optically isolated Solid State Relays like this:
http://goo.gl/qnW6k

Another advantage: These relays switch at the zero-crossing of the AC waveform and so have less spikes and EMI.. 


DISCLAIMER: Mentioned stuff from my own shop...
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

HansF

The application is a beer homebrew system.

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.

#12
Oct 01, 2012, 06:21 pm Last Edit: Oct 01, 2012, 06:57 pm by ChuckJaxFL Reason: 1
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.








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.


Have you looked at these?

http://www.auberins.com/index.php?main_page=index&cPath=2_30&zenid=b8a7a93e908b3e3d9a7dbaf38e9f50c4

Go Up