April 14, 2013

Sous Vide Part 2: The Early Version

In part 1 of this post I talked about what sous vide is and a little about how it can transform foods. I'm not going to delve into the world of opinions on how fantastic it is, unlocking unheard of flavors, tenderness beyond belief, etc etc. I assume that if you've come this far on the internet you've already read a lot about all that, so I don't need to convince you. Instead, I'll lay out my experience tinkering with my homemade controller, how I did it, and how you can do it, too.



My first attempt at sous vide was actually a sort of pseudo sous vide. I would throw the meat in a zip-lock bag, suck all the air out and put in in a crock pot full of water. The results were a small step above boiling the meat, but really weren't all that great. Curious what temperature I was actually cooking at, I placed my thermocouple in the water and logged it over time.


In about two hours the temperature hits a corner and levels off just below boiling. This test was done about 4500 feet above sea level, so that's why it's not quite 100 C. I did another test with the crock pot dial set to low and found that the same temperature is reached, it just takes about three times as long to reach steady state. Clearly my crock pot wasn't going to get me very far in the world of sous vide.

Around the time of these experiments I was taking a class on classical control systems and decided to apply my education to the problem at hand. Armed with the theory behind closed loop control, I decided to try and implement a simple PI (Proportional-Integral) feedback controller in the crock pot setup. I won't get into the theory of such controllers here, but will save that for a later post. For now I'll just say that the controller reads the temperature, computes the error between the set point and current temperature, and runs that through an equation to determine what power output is required to reach the set temperature.

I wanted to keep the setup free of any necessary modifications to my crock pot, so I decided the best way to control the power to the crock pot would be something I could plug into the wall and then plug the crock pot into that.

A basic requirement for closed loop control is that you have analog (or pseudo analog) control of the output (output of the controller, which is input to the system). Since the crock pot runs on 120V AC (it could just as easily run on DC, but I didn't want to add that much complexity to the circuit), getting continuous control of the power is tricky. Using a variable resistor is out of the question because they are horridly inefficient and produce A LOT of heat if your pulling a lot of power through them. For a 190W crock pot running at 50% power through a variable resistor, it means 95W of power is being dissipated by the resistor!

PWM seems like an obvious choice here, but it's hard to modulate an AC waveform at PWM frequencies without first rectifying it. But since the response time of the crock pot is on the order of minutes, an extra slow PWM frequency is acceptable. Ultimately I decided on a 1Hz PWM-esque switching controller using TRIAC's as the switch (essentially a home built Solid State Relay (SSR)). This means that once every second the controller reads the temperature, computes the required output, and turns on the power for a percentage of that second.


There it is, my first sous vide controller. There's a lot of extra stuff on the breadboard left over from the last circuit I had hooked up to the Arduino. The only things actively connected to the arduino are the temperature sensor (a waterproofed DS18B20), it's required pull-up resistor, and the long red and green wires headed to the TRIAC daughter board. There's also an LED connected in parallel with the TRIAC board so I can see when the crock pot has power. The TRIAC circuit is identical to the one described in this post, but the two TRIAC's are different part numbers: MOC3023 for the little guy and BTA20 for the big one. (That BTA20 is capable of switching 20A with an appropriate heat sink!)

The first version of software was pretty simple. I set up a 1 second timer interrupt, and in the ISR (interrupt service routine) I read the temperature sensor, computed the controller output, and set the PWM output (on a 1Hz frequency).

#include "TimerOne.h"

int potPin = 9;       // pin the crockpot is connected to
float setTemp = 57.5; // desired temperature

void setup() {
    Timer1.initialize(1000000); // 1 second in microseconds
    Timer1.attachInterrupt(control); // call the controller every so often
    Timer1.pwm(potPin,0);
}

void loop() {
    // controller is taken care of in timer interrupt function
}

void control() {
    static float kp = 200;
    static float ki = .08;
    static float err_integral = 0.0;
    // retrieve temperature
    float temp = getTemp();
    // calculate error
    float err = setTemp - temp;
    // calculate error integral with integral anti-windup
    if (pwm < 1023 && pwm > 0) {
        err_integral += err;
    }
    // calculate PI output
    int pwm = kp*err + ki*err_integral; 
    // constrain the output
    pwm = constrain(pwm, 0, 1023);
    // set the output
    Timer1.setPwmDuty(potPin, pwm);
}
I've left off the getTemp() function for clarity, you can use your own for whatever sensor you're using.

A couple of things to note here.

  • Everything is done in the control ISR that gets called once per second by Timer1 (lines 16-34)
  • The controller gains, kp and ki (lines 17-18), are not trivial to set. If you're using a crock pot these numbers will get your pretty close, but you may have to do some tuning on your own (don't worry, I'll cover that in a future post)
  • Integrator anti-windup, i.e. preventing the integrator from integrating if the PWM is at it's limits, is necessary, especially when the system is slow to respond (lines 25-27)
  • Once the gains are set, the controller equation is quite simple (line 29), but make sure it's constrained to within valid PWM numbers (line 31)
In the end this setup performed pretty well. Once the temperature got close to it's set point the controller kicked in and started modulating the power line to keep the temperature at the correct level to within a fraction of a degree.


Part 3 Teaser

This crock pot setup proved to me that Sous Vide cooking is pretty much the most delicious thing imaginable. But the setup fell short in several ways. First, if I wanted to change the temperature or controller gains I had to pull out my computer and reprogram the arduino. Second, every time I wanted to cook sous vide I would have to remind myself how to connect everything since my arduino was constantly project hopping. Third, with the low power crock pot it takes a long time to get up to temperature and a long time to recover after dropping in a big chunk of cold meat. Fourth, the crock pot was pretty small and couldn't hold a lot of food since there is the requirement that the food be completely surrounded by water.

My solution to the first two problems was to design a stand alone circuit board complete with a user interface.



For the third and fourth problems, remember how I said the BTA20 TRIAC can switch up to 20 amps? This 1500W water heater element only draws 12.5 amps....




1 comment:

  1. Treatise numerous is typically obligatory if you don't how to knob it in series to elsewhere. You'll provide intensify to to be a satisfactory lunge that you even devise hardly stays taint in precept to correlate, need overt or possibly mollycoddle the tangible Made of fur for methods, the certain arrangement goody skill philosophy, proofreading, debatable abouts spinner arrant. Infrared repeater

    ReplyDelete