QUOTE(andrea @ Mar 6 2008, 03:28 PM) [snapback]66068[/snapback]
Are there any better ideas?
Now I can see what you are doing. How do you know that 10 seconds is the right amount of time to be on or off. That can be too long depending on the time constant of your system. Do you know the time constant of your system? Does your system have a dead time?
What you are doing is somewhat of a kludge. There is an alternative approach to PID control that works well when the output is on or off. It is called Sliding Mode Control or SMC. The basic idea is similar to what you already have. If the Error= SP-PV > 0 then the heater is on otherwise it is off. You already know the problem with this technique is that the temperature WILL over shoot the SP because the heater is on until the PV > SP. This is not good so we need a way of turning off the heater even though the PV is below the SP. This is done by taking the error rate into account. It should be obvious that the faster the PV is approaching the SP the sooner you want to turn off the heater to keep from over shooting the SP. Now the condition for turning on the heater changes to:
Error(n)=SP(n)-PV(n)
ErrorRate(n)=(Error(n)-Error(n-1))/TimePeriod
Now if
tau*ErrorRate(n)+Error(n) > 0 then turn on the heater.
Tau is a time constant. If must be equal to or longer than the time constant of the system. I like to keep the TimePeriod short relative to tau ( time constant ) or the plant time constant. I would do these calculations every second in a interrupt.
Here is an example
ftp://ftp.deltacompsys.com/public/SMC/smc%20rs500.zipDon't be intimidated. Most of the code is for the simulator. Yes there is a simulator and trends!!!! Talk about a gift.
The advantage of SMC is that it is very robust and easy to setup. Load changes do not affect SMC control as much as load changes affect PID control. SMC will tend to turn on and off the heater more often than in your example because it is doing its check every second instead of every 10 but this isn't a problem if you are using solid state relays. The ML1500 LRP must have mechanical relays because I could here it click on and off as the simulation progressed.
If the control overshoots then just make tau ( the time constant ) longer.
SleepyWombat made a SMC simulator in Excel so you can see what it does and how it does it.
http://www.plcs.net/downloads/index.php?PH...3ad43284fd22a74See the Sliding Mode Control.xls