Sunday, November 9, 2014

Reflow Toaster Oven - Part 8 - MAX6675

Just playing around a bit with the MAX6675 chip. I noticed that the temperature jumps up and down a bit, but never bothered to look into it. So I did a bit of testing.

I did three runs of 200 samples. The first run had a 1000ms pause between each sample, the second 500ms and the third 250ms. The top graph is the raw data, the bottom one is the average of 10 samples.
In order to compensate for actual temperature fluctuations I tried to visualize the standard and average deviation over 10 samples:
Just to put these numbers into perspective: the raw sample data is in centidegrees Celsius; that's one hundredth of a degree. So an average deviation of 25 means 0.25 degree.
If I look at the average of the average deviation for each of the runs then I can note the following:
1000ms has an average average deviation of 18.5
500ms has an average average deviation of 20.8
250ms has an average average deviation of 16.6

Long story short: 500ms seems to cause the most noise, but the total amount of noise does not seem to be very significant. The sample rate does not seem to have a direct relation with noise. Good. 4 samples per second it is!


And now for something completely different: driver software.
Until now I had been using an Arduino library in order to communicate with the MAX6675. After looking at its code and the datasheet I decided to ditch it and write my own. The library I used handles everything in software; it generates the clock signal in software using digitalWrite calls and reads the dataline using digitalRead calls. Furthermore it contains quite a few delays and handles the result in floats (ew).
The MAX6675's protocol is pretty similar to SPI, and since the ATmega328/2560 has hardware for that, why not use it? All you need to do is configure the SPI hardware by setting a few values in the SPI control register (SPCR) and set the pin mode for a couple of pins. Then, when you want to read the data you pull the chip select line low and start a SPI read (by writing a value to the SPDR register). Then you wait until a flag in the SPI status register is set (SPSR) and you read the received value from the SPDR register. Repeat this to get the second byte and drive the chip select line high again to start the next sample. Then it's a matter of combining the two received bytes and processing it. Easy! Just make sure to wait at least 220 ms before pulling the CS line low again.

The result is 6 lines of setup code and 10 lines of read code. Nice.

No comments:

Post a Comment