Shop OBEX P1 Docs P2 Docs Learn Events
Closed loop temperature control — Parallax Forums

Closed loop temperature control

KenBashKenBash Posts: 68
edited 2010-01-05 21:21 in Propeller 1
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. )
····································

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-01-05 02:58
    Tuning any kind of controller depends a lot on the circumstances surrounding your system. For example, when it comes to heating an oven, if your temperature sensor is far away from the heat source, you might have a large lag time and overshoot your target temperature. On the other hand, if your temperature sensor is too close to the heater, your controller might cut off power before you have reached your target temperature. Heat sources might have "thermal inertia" of their own, which means they will take some time to heat up and then continue dumping heat into your system even after they have been powered down. The thermal characteristics of your oven walls might also act as "thermal capacitors", sucking up heat on the upswing, etc. So you really have to look closely at your entire system and think about thermal mass and insulation and location of heat sources, sensors, etc. to get a decent idea of where to place sensors and what sort of time lags you can expect. PID control helps the system "anticipate" some of the effects of these elements and tuning it can be something of an art.

    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

    smile.gif
  • kwinnkwinn Posts: 8,697
    edited 2010-01-05 03:49
    You might try a simple proportional control to start with. If you overshoot by 5 degrees try decreasing the on time from 100% at 5 degrees below the setpoint to 0% at or above the set point. Make the 100% and 0% points variable and automatically adjust them based on the over/undershoot. Simple to program and usually fairly quick to stabilize.
  • LeonLeon Posts: 7,620
    edited 2010-01-05 03:54
    A dead-band is often used to stabilise bang-bang servos. I used one once for a simple motor speed controller and it worked very well.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-01-05 05:04
    kwinn has a very good point: a lot of temperature control situations do fairly well with just proportional control. So in other words you can use the PID control but just edit out the I (integrator) and D (derivative) parts. It might still take some experimentation and adjustment of gain to get the behavior just right, however.

    hope you have fun,
    Mark
  • pgbpsupgbpsu Posts: 460
    edited 2010-01-05 15:47
    Ken-

    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
  • KenBashKenBash Posts: 68
    edited 2010-01-05 21:10
    Hey! Thanks everyone. ( specially you Peter, I haven't tried the code yet, but will do so later )

    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. )
    ····································
  • pgbpsupgbpsu Posts: 460
    edited 2010-01-05 21:21
    Ken-

    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
Sign In or Register to comment.