Closed loop temperature control
KenBash
Posts: 68
I have difficulty believing this hasn't been covered a couple of dozen times, but I've tried searching the forum and can't find any specifics on using the Propeller for accurate temperature control.
I have the DS1620 chip It has enough sensitivity for my application, but trying to use it in a BANG BANG ( on off) mode, my system wanders back and forth over about a ten degree range. I wrote a simple feedback loop that modifies a PWM output to zero in on a on/off time and I cut the temperature excursion down to about five degrees, but this is an industrial process that I would like to be able to hold to a couple of degrees.
PID loops are usually used for this type of control, and I will look into modifying the one in the obex for my application, but I was wondering if someone might have already written something that puts the two ( PID + ds1620) together for accurate control.
I know if I keep playing with my program and incorporate rate of correction into the PWM value modifier it should be able to self tune a bit better, but this seems like a control application that could easily have been done a hundred times by better men (or women) than me.
I will be needing to control an oven soon as well and will possibly be using the DS2760 thermocouple interface. I'm in the same boat with this one too, I can use it to read temperatures quite well, but the on/off control schemes aren't accurate enough for my application. If someone has done this before I'd love to hear about it. If not... I'll keep working and see about posting it as an object if it works out OK.
Thanks for any (pun intended) feedback
KB
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
" Anything worth doing... is worth overdoing. "
··············································· ( R.A.H. )
····································
I have the DS1620 chip It has enough sensitivity for my application, but trying to use it in a BANG BANG ( on off) mode, my system wanders back and forth over about a ten degree range. I wrote a simple feedback loop that modifies a PWM output to zero in on a on/off time and I cut the temperature excursion down to about five degrees, but this is an industrial process that I would like to be able to hold to a couple of degrees.
PID loops are usually used for this type of control, and I will look into modifying the one in the obex for my application, but I was wondering if someone might have already written something that puts the two ( PID + ds1620) together for accurate control.
I know if I keep playing with my program and incorporate rate of correction into the PWM value modifier it should be able to self tune a bit better, but this seems like a control application that could easily have been done a hundred times by better men (or women) than me.
I will be needing to control an oven soon as well and will possibly be using the DS2760 thermocouple interface. I'm in the same boat with this one too, I can use it to read temperatures quite well, but the on/off control schemes aren't accurate enough for my application. If someone has done this before I'd love to hear about it. If not... I'll keep working and see about posting it as an object if it works out OK.
Thanks for any (pun intended) feedback
KB
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
" Anything worth doing... is worth overdoing. "
··············································· ( R.A.H. )
····································
Comments
I really doubt anyone will have software that will automatically fit your specific application but the general PID object is probably a good place to start. Tuning the control will very much depend on the geometry of your system and what sort of materials are involved. So, in my humble opinion, you might just have to tinker with your control and see what kind of changes affect your output. Bang bang control is notorious for overshoots and instabilities, though, so if you really need a tight window of operation, you'll probably want to learn about PID.
my 0.002 cents worth, anyway
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
hope you have fun,
Mark
I'm using the prop to do just what you are. My set point is 23 degrees C and things seem to be working fine with the attached code. The hardware I have includes an exhaust fan for cooling and a heater plate that is wired up to 4 Prop lines. By turning on the heater lines (bits) I can control the amount of heating basically by using a binary sequence. I'm using a PID to decide which way the heating/cooling should go but I'm really only using the P and I parts. Furthermore, I multiplied everything by 1000 and just do things with integer math rather than floating point.
The attached code might give you some ideas. It's got more than you need because it logs a bunch of stuff to an SD card and serial port and controls a 4-digit 7-segment LED display. Just ignore those parts. The sections of interest are in the PID method, and the repeat loop in the Main method.
Let me know if you have questions about the code.
Regards,
Peter
After re-reading your post there is a difference between our systems. I'm using a DS18B20 temp sensor. But if you are getting correct temps into your code, the decision making process shouldn't be any different.
For a reason I don't understand my upload didn't work. Here it is a second time...
Post Edited (pgbpsu) : 1/5/2010 9:31:56 PM GMT
I had marginal luck with my program last night, trying to hold 160 degrees I got a fairly nice 2 degree span, (pretty close to the limits of the sensor) but when I changed the hold value to 180, I got about 6 degree fluctuations that seemed pretty random. It would hold steady for 30 - 40 seconds then start climbing/falling Probably related to the cold air here in my office.
Adding a deadband DID help substantially as well as picking a "Steady" point that the software would revert to each time the temperature hit's the deadband. Instead of continuing the PID function, it zeros the PID data and uses a preset PWM value. I found that I could "Pick" a value that would work pretty well for each temperature range, but when anything destabilized the setup, I had to pick another one. (I'm going to try to program something that gives "weights" to values that tend to work and modifies them as it goes )
What I would like to have is something that doesn't need to be hand tuned. The prop is smart enough to "Learn" what works and what doesn't if I can only be smart enough to figure out how to put it into code. I'd like some form of learning program that knows how to adjust itself for maximum stability. It will need to recognize "closure" rates and tune itself to slow down its rate of correction as it approaches the setpoint.
I'm going to look at Peter's code and see how it works for me if I come up with anything better, I'll try to share it.
Thanks again.
KB.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
" Anything worth doing... is worth overdoing. "
··············································· ( R.A.H. )
····································
Sounds like you are making progress.
My code won't be a drop-in replacement. I pretty much grabbed something I'd written for temp stabilization last year and sent it off for you to have a look at. That code, with our hardware (both heating and cooling capabilities), seems to work fine for our needs (no more than +/- 1 degree C). Moving it up to 180 degrees may not work. I will say I was surprised how little tuning it took, but I think that's because we have the ability to heat and cool our system. The exhaust fan you see referenced in the code basically has access to air well below 0Degree C that it can bring in to lower the temp. We also have a stable heat source in the box where we are trying to maintain temp.
Again, I'm not sure how valuable the code will be especially given that you've got something pretty close to working. Let me know if you have specific questions about the code. I can certainly help explain what's going on if it's not clear.
Regards,
Peter