Thermocouple & picaxe

edmunds

Senior Member
Dear all,

I'm into thermostats now.
I have two simple thermostats from Velleman (http://www.velleman.eu/products/view/?country=fr&lang=en&id=347925) controlling 3D printer heat-bed and hot-end. All well, works, but checking the temperature with a handheld thermometer all the time is kind of not first class :). So I have been dreaming to upgrade to a display that would show target temperature set by a potentiometer and actual temperature read from thermocouple in one case and thermistor in another.

Some of you might have noticed I tinkered with some crazy complicated displays and asked for some advice. While I had marginal success with them, due to the time investment needed to take even a small step anywhere, I'm now expecting 4x20 OLED display from this very site in my mailbox any day.

I feel pretty confident with the code as such and the necessary electrical connections after studying the related chapters in the manual. What is a mystery to me is calibration. I have a big table for both, the thermocouple and the thermistor with resistance values at certain temperatures. Is there a mathematical way to set this table into a picaxe chip somehow? Or do I have to measure and calibrate? In theory, I only need a couple of temperatures, not by degree setup ability so the latter is also a real option. It feels, however, there should be a "smarter" way and test measurements would only be needed for fine-tuning.

Thank you for your time,

Edmunds
 

binary1248

Senior Member
For thermistors I used a lookup table to linearize the thermistor curve. Depending on the range and how accurate the output reading needs to be establishes the size of the lookup table.
Yes, there is a formula for thermisters, but it is rather complex for a PicAxe application I would guess.
As for thermocouples, don't they have an extremely low output voltage ?
 
Last edited:

binary1248

Senior Member
Here is the equation for thermistors.
{1 \over T}=a+b\,\ln(R)+c\,(\ln(R))^3
where a, b and c are called the Steinhart–Hart parameters, and must be specified for each device. T is the temperature in kelvin and R is the resistance in ohms.
.
.
What I used to do (many years ago) would be program the equation in Windows then print out the table, select certain values and use them in the lookup table. It was for assymbly language pics and worked quit well for my application.
.
EDIT: You didn't specify the temperature range required, but thermistors are limited to 200 Deg C to 300 Deg C depending on the manufactures type. Obviously thermocouples work at a much larger range of temperatures.
 
Last edited:

Goeytex

Senior Member
Depending upon the application either a thermocoupole or thermistor will work. With a thermistor you can use a lookup table as has been mentioned or even attempt to use the Steinhart-Hart Equation. PH Anderson developed a nifty bit of code that works quite well and can be found HERE . I have tested this and it works nicely.

Most thermistor manufacturers can provide a charts of resistance vs resistance for various thermistors.

With a thermocouple you will need a thermocouple Amplifier board. These come in different flavors, but Adafruit has a good selection. With these there is only very simple calibration needed.

If you can tell us the temperature range you need to measure,,what resolution you need, what kind of response time is required, and the sampling rate you need, then folks can offer you more informed advise. The more you can tell us about the project/application the better. I have absolutely no experience with 3D printers and the temperature requirements, but it may be that you need proportional even PID temperature control, This can be a bit tricky but can certainly be done with a Picaxe.

While doing this with a Picaxe can be a lot of fun if you're on of those that enjoys a challenge and does not get frustrated easily, another option is to get an expensive PID Controller from Ebay, if you can get shipping to your area.
 
Last edited:

edmunds

Senior Member
Thank you for your replies.

Will try to complete the gaps in information.

Heater 1.

A so called hot-end heater. The idea is to melt the plastic that is pushed through the heated area of the extruder into a 0.2-0.5mm nozzle. The rest of the printer tech is then applying this heated plastic sausage in layers to make a 3D print. The heater in my case in nichrome wire wound around cylindrical aluminium part and an thermocouple wound somewhere close with the help of caption tape. There is some error that the distance of the thermocouple from the nichrome wire causes, but let's say this is marginal. The temperature to sustain varies from the type of plastic being printed, but I'm aiming for a reasonable range of 150-250C. In reality, today I have between 70 and 230, which is fine, really. As for accuracy - 5C makes a lot of difference to the print quality when you come close to the right melting point temperatures for the plastic. So I have kept the hysteresis of my thermostats low and they toggle the relays noticeably and a lot. I would say accuracy within 1C would suffice.

Heater 2.

A so called heat-bed. This is something you put on the "table" of the printer and heat up to make the part stick and to try to prevent it from cooling too fast and thus wrapping during the print with some plastics. The later I still need to improve at :), but this requires between 50 and 120C, so a normal thermistor works just fine. The heat-bed itself is an aluminium plate with some copper traces on it (I believe) and isolation material on top. I assume the copper gets heated up in a result of what looks like a short to an average person. I have not teared it up to actually see what's inside, since this thing was expensive :). So assumptions only. Thermistor is sitting on a side of the thing, so of course there is some deviation. There is as much as 5C deviation from centre to corner of the heat-bed, but there is not much I can do about it. Again, holding a given temperature within 1C would suffice.

Both thermostats are the same vellman kits. One runs fine with a thermocouple and the other one with thermistor. And there seems to be no difference in calibration principles (altering the values of voltage divider (?) resistors).

I'm put off by ebay option, because I want a single device that does a number of things more than the thermostat thing. Also I like to do something interesting. Sometimes it is fine to buy something interesting instead, but this is not the case. On top of that, I want it of a reasonable size. If you look at what is available on ebay, the boxes are close to the size of my whole CNC console where the current thermostats sit and the new one should sit, but it does a whole lot more than thermostats - 12V and 48V PSUs, stepper controllers, spindle controller, manual control buttons and relays, laser controller to name a few.

I was thinking I would need to do the following steps to have a basic program:

0) Say "hello!" on a display if somebody gave you some power;
1) Loop until somebody switches heater1 or heater2 on;
2) In case somebody did that, check the difference on the POT1 or POT2 pin (or both, sequentially) against some ref voltage and compare that to some place where it says, how many C this means;
3) Show this number with a prefix "target temperature: ";
4) Go into loop of checking the difference on the sensor (thermistor or thermocouple) pin against some ref voltage and compare that to some place where it says, how may C that means;
5) If this is less than target temperature, take a pin high to heat more;
6) If this is the same or less, take a pin low to stop heating;
7) display the temperature found in step (5) on the display with a prefix "actual temperature: ";
8) Go back to (5) as long as somebody switches the relevant heater off;
9) Go back to (1).

This can be made more advanced with temperature setting by means of buttons under the screen, which I plan to add, but the above would be good for starters. The only unfamiliar area to me is the voltage comparison, but that seems pretty clear from the manual. I will just stick some stuff into a breadboard right now :). The truly unknown is the lookup table. Where do I put it and how do I extract a value from it as needed? EEPROM maybe?

Or am I totally off course here?


Regards,

Edmunds
 

Puuhaaja

Senior Member
I have made ultimaker clone by myself using ebay stuff. Ultimaker uses ad597 board for it's thermocouple: http://www.reprap.org/wiki/Ultimaker's_v1.5.3_PCB#Add-ons
Ad 597 gives 10mV/C so you have to make your own conversion formula like 20 Celcius = 0.2Volt, 120 Celsius = 1.2Volt etc..
I have also thermocouple ic's from linear technology(LTKA 01 6N8 and LT 1025) but I haven't used them yet.

I think that your project can be easily done with Picaxe. Durin next few weeks I will do my own project where I will use 3d printer's heating cartridge and thermocouple. In that project temperature can be controlled with potentiometer. So...It's gonna be really much similar than your project and I will write back about that.
 

geoff07

Senior Member
The truly unknown is the lookup table. Where do I put it and how do I extract a value from it as needed?
Check out the TABLE command and the scratchpad area (PUT/GET). Either might be useful. Or you could consider eeprom (READ/WRITE)

Speed, capacity and how to load it are the issues. An additional eeprom is also easy but probably unnecessary unless your table is huge.
 

edmunds

Senior Member
Check out the TABLE command and the scratchpad area (PUT/GET). Either might be useful. Or you could consider eeprom (READ/WRITE)

Speed, capacity and how to load it are the issues. An additional eeprom is also easy but probably unnecessary unless your table is huge.
Thank you, I have a table now :).

Now I have the "compare to" values from the pots in and also displayed on LCD. Now starting to dig the thermistor/thermocouple part. Seems I have found all the necessary formulas, learned about how ADC works and how to interpolate what I get to temperature reading. However, I need the A, B and C coefficients for the thermistor and thermocouple. Or sometimes referred to as b0, b1 and b3. How do I locate these numbers in the data sheets? Are they coded or hidden in some way?

http://www.murata.com/~/media/webrenewal/support/library/catalog/products/thermistor/ntc/r44e.ashx
http://www.mouser.com/ds/2/261/ntc_radial_glass-369675.pdf


Thank you for your time,

Edmunds
 

edmunds

Senior Member
Here is the equation for thermistors.
{1 \over T}=a+b\,\ln(R)+c\,(\ln(R))^3
where a, b and c are called the Steinhart–Hart parameters, and must be specified for each device. T is the temperature in kelvin and R is the resistance in ohms.
Dear binary1248,

What are "\,\" in the formula?


Thank you,

Edmunds
 

binary1248

Senior Member
What are "\,\" in the formula?
I guess it didn't exactly copy and past that well.
.
If you use a table lookup to linearize, if your range required is limited you should be able to get good results. Say 100 degree range ( like 150 to 250) would only require 100 bytes table for a correction of every degree. Or 1/2 degree corrections would require 200 bytes.
Speed may be a problem but in this case I don't think you need anyspeed. Here would be my first crack at this using table lookup.
1)Read the A/D value (uncorrected temperature)
2)Scan the table for the closest A/D equivalent value stored
3)The temperature value is stored at that location.
Anyway, sounds like you are having success :eek:
 

edmunds

Senior Member
I guess it didn't exactly copy and past that well.
.
If you use a table lookup to linearize, if your range required is limited you should be able to get good results. Say 100 degree range ( like 150 to 250) would only require 100 bytes table for a correction of every degree. Or 1/2 degree corrections would require 200 bytes.
Speed may be a problem but in this case I don't think you need anyspeed. Here would be my first crack at this using table lookup.
1)Read the A/D value (uncorrected temperature)
2)Scan the table for the closest A/D equivalent value stored
3)The temperature value is stored at that location.
Anyway, sounds like you are having success :eek:
Thank you for your reply.

This is how far I am:

1) I have decided to start with 8-bit resolution, since I do not understand 10-bit resolution code as of yet and this would add one more thing I don't quite understand to the puzzle. Not what I need right now :).

2) I have calculated the corresponding thermistor resistance values for each ADC position from 1 to 255 using the formula Rt = (256/ADC -1) x 10.000. What is interesting with this number, is that it shows that I will never be able to measure anything below 50C, since Rt@255 is 416'666 and my thermostat table says 432'530@50C. I can live with that, but I was just wandering if I could change that with changing the balancing resistor in the voltage divider to something other than 10k?

3) I have researched and I think I understand the most important parts of P.H.Anderson's code and two level approach to finding the temperature match. By intuition, I have used similar code to get my potentiometer readings working.

4) I have found two online calculators for the coefficients. Both produce different coefficients from the same three sets of resistance/temperature figures. Puzzled.

5) I have tried to use those coefficients to get some meaningful T result using different versions of the formula mentioned earlier in this post. No luck at all so far. I get a way too small number. Like ^-5 too small.

Maybe there is some proven route to success that somebody can share? I will keep trying, here, of course. Much of the weekend left :).


Thank you all for all the help so far,

Edmunds
 

AllyCat

Senior Member
Hi Edmunds,

2) I have calculated the corresponding thermistor resistance values for each ADC position from 1 to 255 using the formula Rt = (256/ADC -1) x 10.000. What is interesting with this number, is that it shows that I will never be able to measure anything below 50C, since Rt@255 is 416'666 and my thermostat table says 432'530@50C. I can live with that, but I was just wandering if I could change that with changing the balancing resistor in the voltage divider to something other than 10k?
I'm not sure that your maths is correct, but I don't really understand the 416'666, for example. I've not written code specifically for thermistors myself, but the principles are fairly straightforward:

The "formula" will give the resistance at a specific temperature, but you are putting the thermistor (together with a fixed resistor) in a "potential (i.e. voltage) divider chain" and then measuring the voltage with an A-D Converter. Typically, you would make the fixed resistor value similar to the thermistor resistance at the temperature you want the best resolution (i.e. accuracy). This gives an ADC value of about 128 (i.e. half of "full scale"). When the temperature moves away from this point, the resolution falls, but it will need a large change of tempertature before the ADC gets to values of > 250 or < 5, let alone 255 or 0 (where the formula is probably not valid anyway).

For convenience, you can put the thermistor in the top of the divider chain (i.e. fixed resistor to Earth) so that the ADC value rises when the temperature rises. But sometimes it may be preferable (or even necessary) to "ground" one side of the thermistor and in this case the ADC value will fall as the temperature rises. That's still usable, but one more complication in the learning curve.

Most of these "non-linear" issues can be solved using "piecewise linear" curve fitting in the program, but I'm afraid that's one more issue to add to the learning curve. Also, if / when you find that the PICaxe Basic divison isn't accurate enough, then I may be able to help. ;)

Cheers, Alan.
 

edmunds

Senior Member
The "formula" will give the resistance at a specific temperature, but you are putting the thermistor (together with a fixed resistor) in a "potential (i.e. voltage) divider chain" and then measuring the voltage with an A-D Converter. Typically, you would make the fixed resistor value similar to the thermistor resistance at the temperature you want the best resolution (i.e. accuracy). This gives an ADC value of about 128 (i.e. half of "full scale"). When the temperature moves away from this point, the resolution falls, but it will need a large change of tempertature before the ADC gets to values of > 250 or < 5, let alone 255 or 0 (where the formula is probably not valid anyway).
That is one worthy piece of advice. I have useable numbers by now, but with not enough "resolution" where I need it. Just got stuck and decided to check back to forums to see if there was a clue. And there it is :). Thank you. Will experiment with this now.

Most of these "non-linear" issues can be solved using "piecewise linear" curve fitting in the program, but I'm afraid that's one more issue to add to the learning curve. Also, if / when you find that the PICaxe Basic divison isn't accurate enough, then I may be able to help.
Could well be there already :). I will probably run with +/- 5 degree accuracy for now then, but I'm curious what direction shall I look for a better solution?


Regards,

Edmunds
 

Goeytex

Senior Member
Could well be there already . I will probably run with +/- 5 degree accuracy for now then, but I'm curious what direction shall I look for a better solution?
Proportional only, or PI, or PID control.

This can have relatively high resolution within the proportional band of perhaps 10 degrees. Below this band the heater is full on, above the band the heater is full off. Within the band the heater power (PWM) is proportional to the difference between the setpoint and process value (actual temperature).

A good place to start ===> http://www.controlguru.com/ (See Chapter 2 )
 

edmunds

Senior Member
Voila!

Too late (or early :)) to check the actual temperatures now, but seems to work for the hot-end thermocouple. Code and data for the heat-bed thermistor, calibration and some niceties still due, of course.

Did not want my code pasted (probably for a good reason of being too long) so I attached a file.

Update: the good news is after making the real connections it seems to be somewhat related to temperature readings after a few bug fixes :). The rest of the news I'm working on.

View attachment Thermostat.bas

Regards,

Edmunds
 
Last edited:

AllyCat

Senior Member
Hi Edmunds,

... I'm curious what direction shall I look for a better solution?
A spreadsheet program (such as Excel) can be a useful method to test the fitting of a "piecewise linear" curve to a measured or calculated data set. You can calculate the error (or error-squared) in a column and / or use the graph facility to examine the results.

If / when you get to use 10-bit ADC data, you might find the PICaxe divison facility is rather inadequate. If so, I posted a "double-word" division subroutine in the "code snippetts" section of he forum, some time ago, which might be useful.

But for dividing by pre-calculated scaling factors, the ** operator can be very useful. For example w1 = w1 ** Constant is the same as w1 = w1 * Constant / 65536 . Thus w1 = w1 ** 32768 is exactly the same as w1 = w1 / 2 (which is of course a better way to do it). But ** 32767 is equivalent to dividing by 2.000061 . With this method it's usually possible to calculate and use a scale factor with as much accuracy as needed.

Cheers, Alan.
 

edmunds

Senior Member
Dear all,

Have been stuck for many hours, now. Please help me to become unstuck :).

I have put my dual thermostat together and it worked well on AXE091 with 18M2+. I went for some compromises with the design, since never really got PHAnderson math to work for me. Still, it looked good enough to try to hook up to the real thing. For this, I tried to put everything together on a separate, clean breadboard. Connections are not rocket science, so I was done in some 15 minutes or so and moved my 18M2+ over. It did display something, but very erratically. Like I have seen with serial in not properly pulled down. However, this was not a problem on my board. I checked it over and over again. I suspected poor decoupling performance, so I improved that, but with no success. I have done it successfully before, so I know what I have should work. Finally, I moved everything back to AXE091 and it was that erratic behaviour as well. Suspected the chip and moved everything to spare 40X2, which is the target chip for the project anyway. Same result. Tried simple code with a few lines only reading adc channel with a pot attached and debugging the variable - works like a charm. Started to add some code. It worked to some point and then started flapping all the wings again. Started to remove some code and now had to go back to the very basic few lines to get it stable again. By now I can only think of a ghost of some kind to blame. Here is the code with comments explaining the electrical connections as well.



Thank you for your time,

Edmunds
 

Attachments

edmunds

Senior Member
:mad: :mad: :mad:

"On X2 parts you must use the ADC channel, not the pin number, in the readadc command (e.g. readadc 0,w1 NOT readadc A.0, w1)."

:) that would explain a few things. It is back to where it was before the ghost entered the picture. Will try to move to the real thing again.


Edmunds
 
Top