### A Time Out for Documentation

I coming back from 2 weeks of vacation and trying to get back into the swing of things. I decided now would be a good time to post some documentation of where thing are on the reflow oven. I have decided to use a joystick and an RGB LCD for the menu system. Right now the goal is to be able to select from different reflow profiles stored in EEPROM and run them. Here is a flow diagram of the menus system as of today:

While I am at it, I decided to document the schematic. Here it is as of today:I may still add in an air stirring fan, and a servo and fan that opens the door and blows air  to help cool the PCBs. I’ll be trying these things out once I have all these parts integrated into one sketch. I know these are a bit rough but I thought I share some things now and clean them up later as thing progress.

### Reflow Oven PID

Progress
Wow, it has been a busy week but not without something to show for it. I have working on the reflow oven project on two major fronts. The first was to create a python plotting interface such that I could plot out the PID varibles over time. The second was tuning the PID for the reflow oven. I had pretty good success on both accounts. This post will just be talking about the success of the PID and some of the non conventional stuff put in place to make it that way.

PID
The PID algorithm didn’t depart too much from the classic model.The PID now is in the main loop() of the Arduino code. It will be in it’s own subroutine later. Here is the heart of the code:

```int error, pid, diff, ingr, prop;
...
//calculate PID
time = millis();
reference = SnPbProfilePoint(time);
//reference =500;

for (i=0;i<4;i++){
temperature /= 2;
}
```

In order to keep the calculations for SnPbProfilePoint(time) and the PID variables in integer math (avoiding floating point math) temperature is left in its native scale of 1/4 degC per count. I added a method called readQtrCelsius() to the MAX6675 class to read back this raw data. Time is left in milliseconds to keep as much accurracy as possible. I averaged the temperature with four readings to help with noise. I tried up to eight but anything over four didn’t seem to make a difference.

```	error = reference-temperature;
prop = 32*error;
diff = 128*(temperature-temp_last)-256*(reference - ref_last);

ingr = error/24+ingr_last;
if (error>0){ingr+=1;}
if (error<0) {ingr-=10;	}

ingr = constrain(ingr,0,1000);

pid = prop + ingr - diff;
```

P
The prop was scaled to a non oscillation value once I thought the diff scalers were good.
D
The differential variable is generated with a couple of twists. Instead of basing it off of the difference in error it is calculated with a change in temperature reading and the change in reference. Doing it this way helped it keep up with the changing reference. It is also weighted heavily when compared to the P and the I variables.

I
The ingr was the wimp of the three. I found that turning the scaler down so low most of the time resulted in a 0 contribution. So to keep some in there I added or subtracted some based on the sign of the error. For a constant reference, this will still zero out error over time. Since the oven is quick on the rise in temperature but slow on the fall (no active cooling) it was give a faster integration in the negative direction. Finally it was constrained between 0 and 100% duty cycle because beyond these extremes would add response delay.

```
pid = constrain(pid,1,1000);
// turn on pwm
digitalWrite(pwmOut, HIGH);
delay(pid);
if (pid<1000) {digitalWrite(pwmOut, LOW);}
delay(1000-pid);
ingr_last = ingr;
temp_last = temperature;
ref_last = reference;

//update Plot then loop again
```

PWM
The duty cycle is proportional to pid. pid =1000 is 100% pwm. pid was constrained between 1 and 1000. The minimum of 1 was because delay(0) turns out to be a very looooong delay.

Results

I am quite pleased with the results! Next I will tackle the LCD and the menu system and then start putting all these pieces together into a complete system.

### Reflow Plot Profile

Lately I have been working on the reflow plot profile and how it could be implemented within the arduino controller.

I have consolidated the reflow profile information so I could wrap my head around what the oven needs to do. My plan right now is to have the Arduino hold a number of different profiles in EEPROM. These stored profiles will be user selectable and adjustable using the LCD screen and user input.

I have made a function that outputs a waveform of this shape.  All of the twists and turns are built with adjustable parameters.

```//###############################################
int SnPbProfilePoint(unsigned long theTime) {
// each count is 1/4 degC, time count are milliSeconds
// pre-heat, flux activation, reflow, cooling
// profile for SnPb (Tin-Led)
// wetting time is duration spent above 183degC

// Pre-Heat: 0-110sec
// raise the temperature up from 25degC to 110degC over 100sec
// preheat = Time*(110-25)degC/100+25 =
// Time*(phMaxT-ambT)/phTime+ambT
unsigned long  phMaxT = 440; //4 * 110
unsigned long  ambT = 100; // = 4 * 25
unsigned long phTime = 100000; //=100*1000

// Flux Activation: 100-160sec
// raise the temperature up from 110degC to 125degC over 60sec
// =110+(125-110)*(Time-100)/60 =
// phMaxT+(faMaxT-phMaxT)*(Time-phTime)/faTime
unsigned long  faMaxT = 500; //(4*125)
unsigned long faTime = 60000;//(1000*60)

// <a class="zem_slink" title="Reflow soldering" href="http://en.wikipedia.org/wiki/Reflow_soldering" rel="wikipedia">Reflow</a>: 160-250sec
// raise the temperature up from 125degC to 240degC over 90sec
// = 125 + (250 -125)* (Time -100-60)/90
// faMaxT + (rfMaxT-faMaxT)*(Time-phTime-faTime)/rfTime
unsigned long  rfMaxT = 960;//(4*240)
unsigned long  rfTime = 90000;//(1000*90)

// Cool Down: 250sec+ 6deg/sec max rampdown
// 240-5deg/sec*(time-90-100-60)
// rfMaxT - cdSlope*(Time-rfTime-phTime-faTime)
unsigned long  cdSlope =16;//(4*4)
unsigned long sp;

sp = 0;
if (theTime < phTime){
sp = ambT + (theTime*(phMaxT - ambT))/phTime;
}
else if (theTime < (phTime+faTime)){
sp = phMaxT + ((faMaxT-phMaxT)*(theTime-phTime))/faTime;
}
else if  (theTime < (phTime+faTime+rfTime)){
sp = faMaxT + ((rfMaxT-faMaxT)*(theTime-phTime-faTime))/rfTime;
}
else if (theTime < phTime+faTime+rfTime+1000*(rfMaxT-ambT)/cdSlope){
sp = rfMaxT - (cdSlope*(theTime-rfTime-phTime-faTime))/1000;
}
else {
sp=ambT ;
}
return int(sp);
}
```

With a lot of head scratching and some luck I was able to alter the python code to accept both  X and  Y values (instead of just Y). This allowed me to output a plot from the arduino through the serial port.

There are some issues with the plotting code that I need to address before I get into trying to tune a PID for the oven. The software is very heavy on my laptop. I don’t think it should be but it is. I think it might have something to do with the threading going on involving the serial port. Also, sometimes I can’t get the plotting software to stop and close. It just likes to take over all of the CPU cycles. That’s not very efficient considering that I am sending one point a second. I would like to configure it to detect and accept multiple traces based on what the Arduino sends it. I have some ideas on how to do this but will take some additional python research as I am not a programmer by trade.

### Reflow SSR and Plotting Solution

Plotting
My search for a plotting solution lead me to look into Python matplotlib and pySerial to plot the temperature and see some internal variable such as the PID in action. I found this via the Arduino Play ground. I’ll be looking into this to see if I can fit it to my needs. It would be a handy interface for future projects as well.
blendedtechnologies

Solid State Relay
I have this one on order: Foteck SSR-40 DA

http://www.amazon.com/25A-Solid-State-Relay-SSR/dp/B004HZLMTW/
this one had “free” shipping for me because of Amazon Prime.

### Reflow: Maximum Burn

I managed to get the Thermocouple Amplifier (MAX6675) breakout board – v1.0 from Adafruit working without issue. I downloaded the library they had stashed at GitHub and everything went according to plan. I played a bit with the ‘bake’ and ‘toast’ settings of the oven. Bake only powers the bottom heating element while toast powers both. The heating slew rate  needed to follow the reflow profile would only be supported by the toast setting so I went with that.

# The Setup

I had the end of the K-type thermocouple fastened to a piece of pcb material with kapton tape and placed that about is the x-y center of the oven. The oven was set to maximum (no regulating yet). The blue plot was just wire rack shelf closest to the bottom of the oven. The red plot was with the broiling pan on top of the wire rack. You can see the one with the pan was slower to rise and fall. The sudden change in the downslope is where the door was opened and the tray pulled out.

# Thank you Coolterm!

At first I was unable capture data for plotting. It was frustrating when I went to go copy and paste it out of the terminal window. For some reason the Arduino IDE doesn’t do this.  After cruizing the web for solutions I found a good one. I was able to record time and temperature by printing them out with the serial command and capturing the output with CoolTerm. Cool Term is a very nice terminal program that allows you to copy & caste captured serial data as well as capture it to a file.

Maximum Burn

Plotting

Now that I had the data I wanted to plot it out so I could see how fast the temperature was changing. I tried Google and Open Office spreadsheet programs to do this. I don’t know what I was doing wrong but it was difficult to get the temperature on the X-Axis. All columns wanted to be on the Y axis and I couldn’t find an option to change this. Then I remembered that I had MathCad on an old laptop. I was able to import the data and make a graph comparing the 2 runs.

# Results

It looks like this toaster oven will work.  For small boards, some sort of aluminum tray or plate will be needed to prevent the boards from falling through the wire rack.  I don’t think the broiling pan will do as it has an uneven surface.

# Next Steps:

• Buy a solid state relay
• Write the Arduino code for the temperature profile
• Find a better plotting solution for looking at the temperature vs time.

### The Island of Misfit Toaster Ovens

So I went by “Wally World” and looked at toaster oven that may fit my project. I found this one:

Reflow Toaster Oven

Dented

It was the last of it’s kind in the store. The box was crunched and opened previously. The price was right- only \$20 after tax. The next one up was \$60 and was twice the size and had a fan inside. This one said 1000W so I snagged it. It is in sad shape. It was probably headed to the island of misfit toaster ovens. The back is all dented up as seen in this photo. The cord is only about 2ft long. A bunch of the screw were loose and some don’t have any bite into metal.

I plugged it in and power it up. It has plenty of heating capability. It has a few different settings that I will try out and an always on position on the timer switch.

I have a Thermocouple Amplifier (MAX6675) breakout board – v1.0 that I will be using to sense the temperature with the arduino. I guess I should get that built and working next.

### Reflow Oven

I think a good first embedded project would be a reflow oven. I’m sure that I will learn a bunch on this project.

I hope to make the reflow oven out of a cheap but capable toaster oven where the temperature will be controlled to follow a reflow temperature profile.

As I see it now will be composed of the following major components:

• Toaster Oven
• Arduino controller
• Temperature Sensor
• Solid State Relay
• LCD display
• User Interface buttons (as required)
As I become more project savvy I’m pretty sure this lis will change but I need something to aim at to begin with.
Here are some links that inspired this project:
http://www.instructables.com/id/Toaster-Oven-Reflow-Soldering-BGA/#step1
http://www.elektor.com/news/elektor-presents-new-professional-smt-reflow-oven.1930324.lynkx
http://www.apsgold.com/reflow-ovens
http://www.sparkfun.com/tutorials/60
http://www.seattlerobotics.org/encoder/200006/oven_art.htm