View previous topic :: View next topic |
Author |
Message |
freesat
Joined: 08 Feb 2011 Posts: 32
|
Help needed on temperature algorithm |
Posted: Fri Dec 16, 2011 4:08 pm |
|
|
Hi Guys.. i want some help.
I will build a pwm temperature controller to keep temp starting in ambient temperature and stay on 75ºc. When temperature is low, I want to put 100% and decrease to necessary duty when is coming at 75ºc, but not with a fixed pwm table or code.
1-My hardware is ready, with analog LM35 on AN1, Triac PWM on RB4, and Zero Crossing on RB0.
2-Analog read is ready too, value in Celsius already on var named "temp".
3-Zero Crossing and PWM is ready, working.
I need an idea on how to compare analog read temp, and put it on duty cycle.
symbolic code...
Code: |
if ( temp < 65 ) { dutty = 100% }
else {
if ( temp == 66 ) { dutty = 80% }
if ( temp == 67 ) { dutty = 70% }
if ( temp == 68 ) { dutty = 65% }
if ( temp == 69 ) { dutty = 60% }
if ( temp == 70 ) { dutty = 55% }
if ( temp == 71 ) { dutty = 50% }
if ( temp == 72 ) { dutty = 45% }
if ( temp == 73 ) { dutty = 40% }
if ( temp == 74 ) { dutty = 35% }
if ( temp == 75 ) { dutty = 30% } /* on this example 30% is ok to keep temperature on 75ºc */
}
|
What is the best algorithm to do this without use fixed code or tables? any help will be apreciated.
Thanks
Rocha |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9255 Location: Greensville,Ontario
|
|
Posted: Fri Dec 16, 2011 4:24 pm |
|
|
There is no 'best' algoritm, really. I'd try what you have a see 'how it works' in the real world. Temperature controllers are generally slow devices,taking minutes to hours to get whatever it is to the right temperature.They also tend to cool down slowly as well.
It depends upon the mass of the object,difference in ambient vs. desired,and 'tightness' of control( 1*C or .01*C).What algorithm works for me in my solar panels might be ok for you or could just as easily be to 'slow' and 'rough' for your purpose.
I'd suggest testing a 100% until at the setpoint,turn off,let cool, recording time vs. temp. Repeat 3 times, average stuff out, then say test 100% on until say within 10* or setpoint, ramp back to 75%, recording all the data. It'll give you a 'feel' for the response of the heater,controller,etc.
You may be suprised that a simpler 2 or 3 'step' approach may be fine for your application.
It's all in the real world testing, gathering data and seeing how the 'system' responds. |
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
PWM code |
Posted: Sat Dec 17, 2011 4:03 am |
|
|
Your table reduces very approximately to
dutty = (81 - temp) * 5%
You may then need to restrict dutty to the range 0% to 100%.
Like temtronic says, give it a try.
Once you've got a feel for what happens you can adjust accordingly.
Your proposal looks like the P part of a PID control. It can work quite well for some systems. You manipulate the formula to get tighter control.
Mike |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 17, 2011 4:41 am |
|
|
The formula shown by Mike represents your table except for the gain increment above 70% d.c, as said it's a P controller. The P gain (now 0.05/degree) has to be adjusted for stable control system behaviour. If you increase it above a certain limit value, the temperature and duty cycle will show continuous oscillations, at worst swing over 0 to 100% duty cycle permanently.
The main disadvantage of a pure P controller is the offset between actual value and setpoint, varying with heating power demand. Many simple technical controllers are P controllers, like the mechanical thermostatic valves at a radiator or a temperature controlled mixer tap.
Electronical controllers are mostly of the PI or PID type. For temperature controllers without specific requirements, I would refer to PI. A PI controller adds an integral term that cancels the offset. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Mon Dec 19, 2011 1:43 pm |
|
|
If you have not played with PID controllers before, you may want to investigate this link:
http://en.wikipedia.org/wiki/PID_controller
for a basic understanding of what they are and how they work. I created one a while ago that was a PI controller (and limited the "I" contribution until it got up into the control range to avoid the "integral windup" problem).
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
freesat
Joined: 08 Feb 2011 Posts: 32
|
|
Posted: Wed Dec 28, 2011 2:14 pm |
|
|
I want to say thanks.
The answers helped me a lot!
Now, my temperature controler is working perfectly.
Thanks... |
|
|
|