Graphing Temperatures from the MAX6675 on PIC32

Turns out graphing temp data is pretty simple.

Using the standard Graphics Library from Microchip just to display the output right now. Ultimately it’s working pretty much as necessary to show temperature graphically. I need to be able to adjust the top/bottom a little better using some formulas to come up with a scaling percentage dynamically to make it fit the minimum and maximum possible temperatures into the display without squishing it too much. Additionally I need to decide how quickly to scroll from left to right and possibly a way to redraw scrolling backwards to see starting graphs and archive the raw data to be reanalyzed later possibly zooming etc.

The input to the system is using a development board by Ryan J McLaughlin (dot com). The board was designed to be connected up to Arduino microprocessors but I figured out it could be plugged up directly to a PIC32 too. I decided I needed an easy to interface board with a thermocouple socket already on the board and this one fit the bill nicely.

image

Right now it blinks the status LED every time it makes a reading which is somewhere around 2-3 times per second.

MAX6675 with PIC32MX795F512L

As I mentioned earlier I’m using the USB Starter Kit II, the PIC32 Expansion Board, the SSD1926 PicTail Plus board, and a Truly 3.2″ 320×240 LCD display board to develop the roaster system. This has resulted in some “fun” trying to figure out which pins are really going where on the board and the PicTail cards that you can build your own circuits on. Occasionally some of the pins are not exactly labeled the right way or else there are a few pins that are wired together on the circuit boards making you unable to use one of the pins that are wired together or in some cases both cannot be used etc.

I’ve been working through various demos and trying to understand some of the libraries and still trying to identify all of the pins on the expansion board that are already attached to the LCD / graphics chip. So far I have not found any that involved the SPI1 Pins, which I’m sure is incorrect now.

I’ve now managed to get real time readings to occur while using SPI2 instead of SPI1. Originally I was using pins B2 (SS1), C4 (SDI1) , and D10 (SCK1). to communicate with the MAX6675 thermocouple. When the system launched it would begin to read temperatures from those pins properly but only while in animate debug mode. As soon as I would let it run in full speed to get to a break point later it would be partially or completely erroneous in the received readings. I’ve now switched it to the SPI2 pins and using G9 (SCK1), and G7 (SDI1). (The MAX6675 does not use the SDO pins since it only transmits readings and does not receive using SPI data)

I’m now opening the SPI port to communicate with the MAX6675 using 16bit word mode:
OpenSPI2(SPI_MODE16_ON | SPI_SMP_ON | SPI_CKE_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_HIGH | SEC_PRESCAL_8_1 | PRI_PRESCAL_16_1, SPI_ENABLE);

[After I clean up all the “Dead code” that I’ve been testing various things with I’ll insert some additional SPI stuff HERE]

Which appears to work properly talking to the MAX6675. Further I’ve gotten the text to display on the screen of the current temperature where it runs a rolling average of the last 3 readings updating the screen after each additional reading. At the moment it flips on one of the starter kit’s LEDs based on the temperature when it needs to heat and turns it off when it’s reached a preset temperature.

I need to work more on getting the LCD display to show the activity that is going on in terms of heating/cooling and run a timer to begin estimating what stage the roast would be in based on temperatures and time-wise. Additionally I’ll need to figure out how to graph the temperature across the bottom of the screen too. I’m thinking screen real estate is somewhat limited so I may want to upgrade the LCD to the wider board to move some of the data to the side leaving a larger graph area to represent the roast curves.

I’m not dead… And finally having SPI progress.

So with all the holidays and other things going on I didnt get to spend much time working on the roaster. In addition due to the complications with the SPI not working all this time I wasn’t feeling very motivated.

Last night after spending hours over many days reading blogs of people who regularly participate on Microchip’s forums I finally managed to get the MAX6675 to start transmitting actual temperature data to the PIC32. I’m not entirely sure why it works now but need to emphasize that it only works OUTSIDE my prototype roaster programming. In other words it is literally a single purpose program that reads a single temperature value from the MAX6675 chip.

It seemed almost reliable by reporting similar temperatures most of the time for each reading for air temperatures and then goes up when I press the thermocouple against my hand and then drops significantly when I press it against a cold soda can. There was a rare spike to 120 plus degrees here and there but infrequently. Otherwise the temperatures appear to be pretty close.

When I return to my roaster program there appears to be something significantly wrong with the speed it communicates with a potential “shift” to the left. If I drop off several of the rightmost (0) bits the resulting numbers are what they are supposed to be with a random wrong bit mixed in. About 60% of the time the results are completely erroneous no matter what. I’m pretty sure now that there is a setting somewhere affecting the communication speed that I’ve lost track of that is disrupting things.

I’ve found that adding some longer delays around the CS changes seems to make the temperatures returned significantly more stable eliminating the 100 plus degree spikes and need to try them out in the roaster code too.

Ugh… they really should sell a manual for this thing.

On my way through the I2C problems I downloaded the PIC32 Family Reference Manual from Microchip. I was looking things up and it wasn’t so bad due to it being broken into different sections. There was one section on I2C so I mainly focused on it. I then started figuring out that perhaps it would be nice to search around for things across the whole manual. At that point I discovered that you cannot join each chapter/section together to form a big master PDF file.

I then started considering actually just printing it out instead but realized it was kind of big. I then decided I wanted it to be bound together and began looking at Staples to have them just do the whole binding thing into a single book with a stiff cover on it. I started uploading files one at a time (because they don’t have a bulk upload function)… and then discovered that they don’t have all the chapters/sections written yet. There is probably like 4-5 sections that simply don’t exist. You have no idea what they talk about because there is no master index yet. Reading through the manual there are sections that have been revised in 2007, 2008, 2009, etc. They’ve been working on writing the manual for almost 4 years now and STILL are not done yet.

I decided if it wasn’t complete I wasn’t going to take it to Staples and have them bind it together. Instead I’ve now been printing it out for the past few days on my laser printer and binding it using those plastic coils. I’ve now made it to section 20 printing duplex pages. I think there’s about 10 more sections to go. It’s getting pretty close to a ream of paper it looks like. I’m going to do the 5/6/7xx family data sheet too I think since I reference that a lot. That’s another 230+ pages (130ish double sided… not sure the exact number of pages it is off the top of my head)

I’m also considering getting the pin out graphic (or making my own) and colorizing it and having it blown up to print on a wide 30-40 some inch color plotter. It’s really difficult to program all these things without looking up which pins are being used on the starter kit. It’s FURTHER complicated not knowing how the starter kit hooks to the header pins and the various accessories. There also seems to be several pins that probably do not connect at all making things even more fun!

I’m “taking a break” from coding for the moment. I’m trying to use SPI to get it talking to one of the temperature sensors. I’ve got it initializing the SPI area and it SEEMS to be talking to the sensor. I had worked on another sensor earlier and it downloaded calibration data from the eeprom but none of it seems to mathematically make sense. Everything seems to be off pretty significantly. The only thing I can think of is I’m off a few decimals or something somewhere in the process. I think I really need to start printing out more sensor data sheets and start comparing them side by side with the manuals for the PIC32. There is something wrong with the reading process where it seems to hang sometimes and not others. The eeprom read comes back with the same numbers each time when I randomly bounce around in any order so it SEEMS to work but I can’t really get anything usable out of it yet.

I also discovered another problem at the end of last month. Apparently on the 30th and 31st of the month the real time clock doesnt show the right date. I can set it into the clock chip and back out. When it goes into the PIC32’s clock it converts it back to a 1. It is my guess now that there is some sort of Decimal / Binary / BCD / Hex conversion problems.

Further shipping… I2C problems

So I received my new order with a few more sensors, memory sockets, and a new set of cables that were Female/Female. Not only did I have problems with the shipping involving the first order going to the wrong city and being REALLY slow…. THIS TIME I purposely switched to FedEx and bumped it to Next Day delivery because I was tired of waiting for things. My package “went walking in Memphis” or perhaps went on safari in the Jungle Room or something. Apparently FedEx had mechanical problems and as a result my package did not leave the Memphis hub until after the time it was already due to be delivered to my door in California. It was thus NOT next day.

Once I finally received it I figured I’d start off with attempting to read the real time clock chips I have using I2C. The PIC32 has built in hardware commands for accessing I2C so normally this shouldn’t be too difficult following the address strings and writing/reading according to the patterns required in the datasheet. This even further so since I managed to get it working on a PIC24 in the past so I’m not completely clueless in the I2C (or SPI or One Wire) world.

I tried a few things making adjustments and generally did not get anywhere. I’ve checked the voltage on the bus and I do indeed have 5 volts. At first I had only 4.8 volts due to the LCD backlight sucking most of the power off the USB port. I dug out the AC adapter I ordered and plugged it into the system and brought the power up the rest of the way and all was normal voltage wise. As I change the resistors and play with the speed of the bus I go from having NO responses to 0x00 responses to 0xFF responses… to 0x01 responses. ONCE I managed to get some numbers out of it that made absolutely no sense at all. They were returning things like 80 for the seconds and some 140 something for other things… 12 for others that should have been something else. It was just all over the place.

I don’t have an oscilloscope to try to look at anything closer and one of my co-workers said he had an old scope but no leads anymore. Since I knew I’d need to order some new leads if I borrowed his scope I started digging around to see what’s out there to see what I wanted to do. I have since that expedition ordered a logic analyzer that supposedly I can decode/time/process/log/graph/whatever all the various I2C channel data. I’m not entirely sure how exactly I do this still since documentation is a bit rough to come by properly on the internet the is explicitly involving I2C and the capabilities. It generally just mentions these things in passing and shows a screen shot.

In addition I run into a possible problem having Windows XP x64 bit and having had to host my PIC32 development work out of a virtualized XP 32 bit with USB pass through and trying to get some drivers installed so this should be fun.

I’m still waiting for the logic analyzer to ship. I ordered it on the 9th (here and at the seller’s location during their business day). The seller has updated the order status to “processing”. They indicate they typically ship within 1 to 3 business days. They are located in China so it’s “tomorrow” there now. It was ordered with UPS Worldwide Express delivery so it is SUPPOSED TO be “next day” delivery. I’m not sure how the next day works exactly in terms of time zones. Is it next day shippers time zone? Next day from calendar time/date between both of us? I just don’t know how that one works since I’ve only had the one package from Bulgaria and a couple more from Thailand in this project and neither was the spendy UPS.

I’m guessing if it ships “today” in China it will ship Thursday the 12th China time while it is still Wednesday the 11th here. It will then arrive to me Friday the 13th (sheesh) US time giving them about a day and a half for delivery. I could be entirely wrong though…. doubt it. I just don’t see how they could get something from China to Northern California that quickly. I mean they have what appears to be a 3 hour flight inside China to another airport and from there straight on to San Francisco for 12 hours. With time zone differences etc it appears that flights leaving there around 4 PM China time arrive in the US in San Francisco at 11:30 in the morning “the same day” Pacific Time. From there it would be a normal in the US “overnight” delivery. Actual flights are probably 4-8 hours later. It would catch a smaller flight to Sacramento overnight and then continuing onwards up to where I live for delivery the following day since they seem to fly UPS packages into the local airport whether it’s ground or next day air etc from Sacramento.

Guess we’ll see what happens. I’m guessing I’ll need to sign for it since it’s an international delivery. Everything I’ve gotten international so far required a signature. Other people I’ve talked to said the same things with their international deliveries. Perhaps there is some sort of rules saying someone needs to sign for stuff coming from out of the country. I won’t be here because they’ve quoted around 10am as their delivery time guarantee. I’ll have to sign for it and leave the “door hanger/sticky” for Monday I guess unless I can pick it up after work at the airport when I get the sticky at lunch time when I’m home.

Arrival, sort of.

I finally received the package after the carrier redirected it up here. I’m happy to finally have my stuff but I had a problem. So one of the drawbacks to SparkFun’s website is when you put stuff in your shopping cart they… don’t always stay there. As a result I added and added and added the jumper cables I needed time after time and apparently on the umpteenth time adding it to my cart due to indecisiveness about the other components I ended up adding the Male to Female cables. I needed Female to Female. I didn’t double check F/F on the jumpers after it was in my cart and now I have 100 female to male cables.

I ended up using some jumpers off old circuit boards and hard drives to link the two cables together on the male end to hook one of the sensors up with the female ends. I’m having difficulty getting the information off the first sensor to appear on the LCD due to the way it converts the text for display… I need to rethink this a little more and spend some time experimenting on it but I THINK it’s working getting the data. I could be wrong but some of the logic tests seem to show it getting data. I’ve just been rather tired the past few days and havent been able to fully think about it in between working and other things so I hope to do so this weekend.

I ordered several other sensor boards from SparkFun and a few other parts that can be used in the project at some point in addition to the RIGHT jumper cables so I don’t have to connect 2 of them together. In addition I can probably use these jumpers for something else later as a sort of extension cable or something.

THIS time SparkFun shipped my package on the same business day they got the order. I bumped it to Overnight shipping because I want to be sure I had it this weekend. It shows it having been picked up in Boulder and due for arrival by 3 tomorrow. I won’t be here so as long as I don’t need to sign for it it’ll be here when I come home. Guess it’ll be 1 day this time rather than 6 business days or something.

Let me tell you about the time….

So I’ve ordered a plethora of stuff lately. Yesterday the 5×7 magnifier came. I’m figuring out I have no place to work on this stuff properly so it’s sort of wedged on my desk, and then today a box from Mouser showed up. In it I’ve determined I purchased the wrong AC adapter…. so now I need to order another one but this is for a slightly later stage so it can wait a little. Plus I believe I have a power supply I used on a fan to keep the air moving in my indoor orchid tray and lights area that is not being used currently due to a different setup that I’ve already stripped the ends off that I could then use with the relay board I received from Bulgaria. I’ll probably find something else to use that power supply for later anyway.

Anyway, TODAY the Mouser box arrived. In it were a variety of 0603 sized capacitors. For those that don’t know what that means… they are .06 inches by .03 inches or approximately 1.5mm by .77mm give or take a few hundredths of a milimeter.

Today I learned that fluxes are awesome when soldering SMT devices. I managed to mount my 32.768 6pF crystal and some of the 11pF 0603 capacitors from the selection but it was an adventure. I’ve lost approximately 4-5 of them into the rug somewhere now. Two are now securely attached to the board. I got the first one out ok but lost the second one immediately. I got a third one out but it didnt make it to the table and went straight for the rug. I recovered one of them from the rug and then tried to get it soldered onto the board. Two of them blew away using the hot air system. Once I got a corner tacked down properly it went much smoother. After allowing things to cool off I mounted the USB II Microchip board back into the IO board and connected to my LCD and fired it up. Immediately the clock on the display started ticking off seconds.

I had quite a bit of difficulty getting the soldering stuff going. I looked up temperatures for things on Wikipedia and ended up grossly under heating things up. I ended up looking up the soldering station’s manual on the internet since I couldn’t actually find it right now due to the bags and bags and boxes of parts and shipping materials everywhere. Once I finished looking that over things melted much more easily and started acting more normally. Once I started packing the parts away into boxes I discovered the real manual buried in the pile.

As mentioned the timer is running just fine. I am waiting a few hours to see how far off the time is from my computer to get an idea of whether this has a slight or a significant drift. So far it looks quite good. Time will have to tell. ULTIMATELY being REASONABLY close over a few minutes is fine. In the final project I will be using a DS3232 I think it is as a time source to populate the microchip “RTCC” after powering the system down and then turning it back on. Microchip for whatever reason built a system that has marketing towards it having a Real Time Clock built in. The problem is it doesn’t keep time when you turn it off due to having no backup battery of any kind. As a result it needs to be set every time you apply power to the system and then take it away when you turn it off.

Since I intend to hook this to the internet / router eventually I will try to implement a NTP client to set time into the DS3232 and then from there into the Microchip PIC32 while it runs. I’ve now manually adjusted the clock to be in sync (visibly anyway) with an atomic clock synced clock I have here immediately next to it. I set it at 10:12 so I will check it again in a few hours. The longer it seems stable the less I’ll have to make it lookup from the Dallas chip…..

I believe tomorrow I will be getting some ambient temperature, humidity, and barometric pressure sensors as well as a few other sensors I may or may not be experimenting around with too in this and other projects. So far 10 minutes in the clocks still seem synced so we’ll see what happens over the next few hours and overnight.

Oh… and Microchip never replied to my “technical support” request to get an idea what they suggested. I think the details I’ve found on the internet meant several different options of crystal and capacitor combo were ok and what they DESIGNED it with was not very common to find. I managed to find what it sounded like it was designed for though and so far so good.

I should start mounting the header pins this weekend and start hooking things to some of the external sensors to start getting readings into the programming. Once that happens I can start porting my PIC24 code over making a few adjustments and then start programming the roast curve tracking portion.

More ordering

I have now ordered a series of parts from Mouser. This includes some lead free solder (ouch that stuff is expensive), flux, several different crystal oscillators and what I THINK to be matching capacitors, as well as a ton of headers for jumper cables. I entered a ticket for Microchip more than a week ago and have received no response whatsoever from them regarding the oscillator. Reading the instructions there was no mention of a type of crystal to use beyond 32khz. They mentioned 11pF capacitors of 0603 size. From what I can understand it SOUNDS LIKE in a properly designed board if you have a 6 or 7pF crystal you install an 11 to 14pF capacitor when it has short runs for the wiring etc. HOWEVER yesterday I found on the ethernet board they explicitly defined the crystal as a 12.5pF crystal. In my observations it appears that if you use 12.5pF crystals you should use 22-27pF capacitors, though.

The unfortunate problem is some people report using 11/12 capacitors with 12pF crystals and other report needing to use 27 etc. I’m thinking it MAY depend on the manufacturer of the crystal as to how sensitive it is and needing more or less power from the caps to be held up to trigger the oscillations of the crystals in addition to the variables of the individuals circuit layout. In other words some times it works no matter what and others it does not.

I still need to get some solder paste in addition to the rolled wire solder. I had issues identifying this on the Mouser website in the search except for a couple versions that had more than five tubes as a minimum. I do not have need for / ability to consume more than one syringe/tube right now so I need to find a vendor to procure some from that does one at a time. I stumbled across one a few nights ago that sells one at a time but I’ve not had time to dig through the browser history to find my way back there yet.

Once I have the solder paste and after the parts arrive mid week I can solder in the crystal and caps to see if they work for the timing functions and continue my efforts at programming the interface. Most of my programming is going to wrap around being able to gauge time changes happening so I need to wait for that to happen.

Currently I have a thermocouple breakout board that I will be attaching to some of the IO lines. I also have on order a relay board that has not arrived. Once the relay board arrives I can attach it to the development board and configure it to turn on the fan when the program run starts and not to turn it off until after the heat drops to a safe level. The heat will trigger on and off to maintain the desired ramp at this time. I will eventually replace it with a variable “dimmer” once I work out the other kinks in the system to give it finer control.

Early July Update. Observation on SR500.

Having been offered full time employment starting the middle of July after approximately 2 years of unemployment things are looking good for getting some progress on this project. LOL! While this may sound odd this is actually good due to the fact that I’m building (if all goes properly) a somewhat professional-esque coffee roasting computer. It takes a lot of money and resources to design this thing. I’m already into the project around $300-400 worth of circuit development kit gear and need a lot more stuff. In the end I’ll have a complete system that will be significantly cheaper to build but still have all the development kits to make other projects. I chose that route because of the “other projects” for down the road instead of only buying the things I need right now. While having full time employment will limit my available time it DOES however allow me money to keep purchasing all the parts.

Most projects you find on the internet for a coffee roaster use something like a Basic Stamp or some other very limited processor. It also usually involves hooking together a few things someone finds off eBay hooked together with some various wires and connectors salvaged off some old computer equipment and other devices abandoned in the garage. By the time it’s done you get a picture on the internet of some “finished” popcorn popper that looks like it’s about 30 seconds from taking out a corner of your house into a huge crater or like it’s some sort of industrial wiring project of conduit and electrical boxes.

I’m intending on making this thing as small as I can make it and sealing it up inside a electronics case with a single cord or perhaps a cord and a sensor wire that plugs into the back of the case that leads to the roaster. I don’t want 50 million little cords and sensors and clunky switches and other doo-dads spread across my counter. I also want to be able to pick the whole thing up and move it somewhere else without accidentally cracking off a wire and needing to re-solder it. I don’t know about you but I love my coffee. I don’t love having to re-solder the wiring just to roast some more or being unable to use my kitchen for anything else.

My Kitchen is not that big. It cannot accommodate a lot of “stuff” strewn around it. so the entire thing will need to be compact. As a result I intend on having a case that has a LCD touch screen installed. It will probably have a LED or two and at most probably a single power switch on the front edge or side. I will likely try to design the circuitry so that it fits onto one or more circuit boards stacked on top of one another. The LCD will be mounted on top with various connectors and other items stacked below it. I’m reasonably sure I can shrink the majority of this down into a space about 4″ by 6″ and about 1.5 to 2″ tall.

As mentioned I recently purchased the PIC32 development gear. At the moment I’ve been working on the GUI. This is a lot more complicated programming than I’m used to. Additionally I’m having a few “weird” situations where LED’s on the starter kit are lit that I don’t seem to understand why. When I turn on an LED that is normally off things work fine but then when I programmatically turn that one off the LCD turns off too though they shouldn’t be connected at all. The other LED works fine turning it on and off the same way. One of these LEDs simply stays on all the time no matter what.

At the moment I now have a “splash screen” functioning. I touch the screen and it continues to a “Home” menu. From there it offers several buttons to run the manual or the automatic roasting menu. There is also a provision for a Setup menu. I am still waiting for the ethernet to arrive that will allow me to download roasting data out of the system or pre-configure a roast from a web page. It currently draws temperature onto the screen from some “made up numbers” I have the thermocouple and the chip that will convert the sensor reading to numbers but need to solder it to a board that I can connect to the processor. I also need to do the same with the clock chip that I have as well. The processor has built in clock routines but they only work while the system is turned on. As soon as you cut power that clock loses it’s data. As a result I will program the system to read the clock chip every time the system turns on.

Over the next few days I will program the roasting screens to change certain display areas based on the simulated temperature numbers and then integrate the “control” portion where it then stops the increase in temperature and then tries to increase it appropriately. I still need to figure out the timer stuff… it doesnt seem to run on the demo and I was thinking it had to do with an oscillator being missing but this seems to be related to USB stuff in the documentation for the starter kit. This doesnt seem right though. I need to figure that out and then the next step is to start ordering all the pin headers and not included on some of the other boards. I’ll try to figure out a few more of the parts that I’ll need and order those in the next few days as well so I can keep working on this. Assuming I’m right that the crystal is required apparently Microchip decided to save 83 cents by not including the oscillator.

Also as a side note. Due to the job offer I completed a move to Northern California from Central California which has kept me from messing with the coffee much until now. A variety of coffee that I roasted here with the Fresh Roast +8 took approximately 6 minutes to hit second crack. Using a SR500 where I used to live took about 6 minutes as well while running the fan at half speed for the first two minutes. To do the same thing here with the SR500 appears to take around 7-8 minutes with a lot more slowing down the fan to around the 25% setting once movement starts to flow more easily and first crack was reached.

Parts received some not…

As mentioned some of the items had later ship dates than others. As of June 16th I have received the IO board, the prototype boards, the LCD graphics w/LCD kit, and a power supply.

In addition to the development kit I have on order a few engineering samples for a few parts to test out before I pick vendors to program things based on and start purchasing real parts. These engineering samples will be mounted on “prototyping” boards that will either be custom built or ordered off the internet pre-made. Occasionally chips are used in a variety of ways so I will simply build a board to solder them down to and install pin headers to attach to on the board. These will also serve as “test” printed circuit boards as I learn to make boards on my own.

The ones I have received so far are a chip that has a real time clock/calendar in it and a chip that reads temperatures from a thermocouple probe. I still have requests out for a few ambient air temperature sensors and a few other things that will be used in additional projects that will eventually connect to/from the roaster computer.

The surprising part is that the clock chip is more or less around the size I expected (about guy little/pinky finger nail sized) BUT that the temperature chip is significantly smaller than I expected. It’s REALLY small. It’s so small that you could literally put at LEAST 16 of them on top of a single computer laptop keyboard key.

I am still waiting for the “brain” starter kit to arrive. This is where things get funky. When I ordered it the availability date for it and the ethernet card were listed as June 28th with an estimated delivery date of June 30th. This is good because I’ve got some free time from then until the middle of July so that arrival date was going to be good to let me work on things some. Today, though, I get this email. It now says that the ship date is changed to July 30th. My online invoice still shows the ship date as June 28th. The microchipdirect.com website says the availability date is July 2nd. So I’m thinking my chances of seeing this anytime soon are completely random and probably not likely.