查看完整版本: K-Type Thermocouple PID Controller

liyf 发表于 2012-1-12 22:48:13

K-Type Thermocouple PID Controller

Worklog - The System overall (September 18 2011)http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313663507.jpg
My new Aoyue 968 hot-air SMD station
I plan to make a pre-heater for my SMD works, and i will need a controller for the air heater. From my job i know the PID controllers and how efficient they are, but i did not really know how they work. After some research i did, i sound the "secrets" of the PID systems (and i also wrote a theory for PID systems). So, now i feel ready to turn theory into product. Many will say again that i could spent $40 to get a PID controller... Yes, i know... But i DON'T want to. For me, making projects is not a chore, it is my hobby, i do it for fun.


The IdeaHere is what i plan to make. It will be a board with 2 rows of 3 7-segment displays. The top row will show the actual temperature and the bottom the set temperature. Like my soldering station, i will use the MAX6675 - Cold-Junction-Compensated K-Thermocouple-to-Digital Converter from Maxim. This chip converts a thermocouple pair temperature into digital readout, and also compensates the cold junction temperature.I plan to use a PIC 16F1937 or one of my new 16F1939 SMD chips. Most probably i will use the huge PDIP chip, because i have a lot of them still in my stock. There will be 2 potentiometers for setting the temperature and the air flow. So the controller will have a PWM output for controlling the fan speed. For the heater, i will use the same method as i use for my soldering station. A BT136D TRIAC can deliver enough current to control a 900 watts heater. A MOC3021 optocoupler will control the gate of the TRIACThis will be my first project that i will use more SMD components than through-hole components, so i'm very excited!






The CircuitI will do no prototyping for this project, so i need to be extra careful and double check everything. Here is the schematic diagram for the controller board (click to enlarge):

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313662556.png

The image is not very clear and i have used a lot of busses to simplify, so i have to upload the eagle files as well. I usually do not upload such files but this time i must. So, here they are:


http://www.pcbheaven.com/pics/attach.png K-Type Thermocouple PID Controller - Eagle Schematic V1.0



Bill Of Materials
Resistors
R1Resistor 220 Ohm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R2Resistor 220 Ohm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R3Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R4Resistor 220 Ohm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R5Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R6Resistor 220 Ohm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R7Potentiometer 5KOhm Linear Rotary 1/2W

R8Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R9Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R10Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R11Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R12Resistor 22 Ohm 1/4 Watt 5% Carbon Film

R13Potentiometer 5KOhm Linear Rotary 1/2W

R14Resistor 2.2 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R15Resistor 2.2 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R16Resistor 2.2 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R17Resistor 2.2 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R18Resistor 2.2 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R19Resistor 2.2 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R20Resistor 10 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R21Resistor 1 KOhm 1/4 Watt 5% Carbon Filmhttp://www.pcbheaven.com/pics/camera.gif
R22Resistor 3.3 KOhm 1/4 Watt 5% Carbon Film

R23Resistor 1.8 KOhm 1/4 Watt 5% Carbon Film

R24Resistor 870 Ohm 1/4 Watt 5% Carbon Film

R25Resistor 1.8 KOhm 1/4 Watt 5% Carbon Film



Capacitors
C1Electrolytic Capacitor 1000 uF 16 Volts

C2Electrolytic Capacitor 1 uF 50 Volts

C3Electrolytic Capacitor 1000 uF 16 Volts

C4Electrolytic Capacitor 1 uF 50 Volts

C5Ceramic Capacitor 0.1 uF 50 Volts

C6Ceramic Capacitor 0.1 uF 50 Volts



Transistors-Diodes
T1BT136D Sensitive gate TRIAChttp://www.pcbheaven.com/pics/pdf.gif
T2BC517 NPN Darlington Transistorhttp://www.pcbheaven.com/pics/pdf.gif
D71N4148 Switching Diodehttp://www.pcbheaven.com/pics/pdf.gif


Integrated Circuits
IC1PIC 16F1937 Microcontrollerhttp://www.pcbheaven.com/pics/pdf.gif
IC27805 Positive Voltage Regulatorhttp://www.pcbheaven.com/pics/pdf.gif
IC3MAX 6675 Cold-junction compensated K-Thermocouple to digital converter (0°C to +1024°C)http://www.pcbheaven.com/pics/pdf.gif
IC4CD4511BC BCD to 7-Segment Latch/Decoder/Driverhttp://www.pcbheaven.com/pics/pdf.gif
IC5ULN2003A High Voltage - High Current Darlington Arrayshttp://www.pcbheaven.com/pics/pdf.gif
IC6MOC3021 Random Phase Optoisolator TRIAC Driver Outputhttp://www.pcbheaven.com/pics/pdf.gif
IC7DF02M 1.5 Ampere Bridge Rectifiershttp://www.pcbheaven.com/pics/pdf.gif


Misc
L1100uH Inductor


liyf 发表于 2012-1-12 22:49:05

I am not going to prototype anything on a breadboard due to the complexity of the system. Instead, i decided to go directly onto a PCB. After all, there will be design errors and changes, so i can name this PCB as "prototype board" and save a ton of wires connected on breadboards. The procedure i followed is the same as i always do, my favorite, the photographic method. I used my PCB Photographic Artwork Transfer UV Cabinet to transfer the artwork from paper to PCB, and then my PCB Etching Bath with Heater and Agitation to etch the board. Here is the result: (click to enlarge)

http://www.pcbheaven.com/projectpages/images/ktypethermcouplepidcontroller_1313912533.jpg

This time the result was even better. I reduced the exposure time from 750 to 600''. For the story, i began exposures as long as 950'' which had very bad results, then i droped doen to 850, 800, 750 and now 600. I think i will try one at 500''. There are still lots of throuhg-hole components but this is going to change gradually, as i empty the through-hole stock that i have.

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913107.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913153.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913177.jpg
I drilled the holes for the through-hole componentsI solder them, as well as the wire-bridgesThen i soldered the MAX6675 and all the SMD components








Through-hole to SMDI now had to solder the 6 7-segment displays, but i had big plans for those :D. They are through-hole components but i plan to solder them as if they were SMDs. Why? Well, first of all i save myself from drilling another 60 boring holes. But basically, if it is better to solder them on the bottom layer, so that i can mount the board directly onto the box.

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913538.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913551.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913592.jpg
The displays are normally through-holeI put the first row in a pre-drilled PCB which i will use as a stencilAnd i bend the pins 90 degrees
http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913616.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913643.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1313913665.jpg
This is the result so farI do the same for the other sideReady!


So now, i can solder them as SMD components on the bottom side of the PCB. This is the result (click to enlarge):

http://www.pcbheaven.com/projectpages/images/ktypethermcouplepidcontroller_1313913854.jpg

liyf 发表于 2012-1-12 22:50:06

There are still some minor things to do with the PCB before it is ready to hook it up in the power supply. First of all, i had to put the reset button. Also, i had to slightly mod the 4-pin connector for the fans. A PC fan connector has 4 pins but the back side is made to fit also a 3-pins connector. This way, both a 3 or 4 wire fan can be inserted. After all, both fan types have the same pinout for the first 3 wires. They only differ on the 4th wire.

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314380566.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314380587.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314380615.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314380919.jpg
I soldered the switch on a 2-pin connector.This is the back side of the buttonI sliced the plastick back behind the 4th pin of the an connector This way, both a 3 and 4-wire fan can be correctly orientated


Then, i made the 2-buttons,the LED wire and the potentiometer connectors:

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381131.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381167.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381191.jpg
I had no better buttons to use, but i have already order a fewI have a 5-positions connector because i may want to add more buttonsI have one 3mm LED and one 5mm LED
http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381226.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381259.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381323.jpg
I think i will keep this set-up. The green LED will be for the power.There are 2 potentiometers, one for the temperature and one for the fan speedThe potentiometers are directly connected to the analog inputs of the PIC


I got a K-type thermocouple from ebay with small mass, but still it does not react very fast in changes. So, i will use one typical K-type thermocouple from a multimeter. I do not have one right now in stock, but i think that right now its on the plane for Greece.At last, i am now ready to plug all the connectors on the PCB and hook it on the power supply. I do not expect to see much... As a matter of fact, i will see absolutely nothing, for the PIC that i use has a totally empty flash. I am ready to plug the programmer and start playing... Here is the PCB (as always, click to enlarge):

http://www.pcbheaven.com/projectpages/images/ktypethermcouplepidcontroller_1314381647.jpg







Boot me up! (August 30 2011)I wrote a quick and dirty software for the PIC to read the thermocouple. Actually, i copied the routine from my Soldering Station because i use the same chip to interface and compensate the thermocouple. So far, the PCB does nothing more than reading the temperature from the thermocouple, but i'm excited because the 7-segment displays work like a charm. The 4511 driver to drive the segments and the ULN2003 to drive the digits was a really good idea and i will use it for my future projects. Once again i was impressed by the precision of the thermocouple. It is really impressive what 2 dissimilar wires can do!

http://www.pcbheaven.com/projectpages/images/ktypethermcouplepidcontroller_1314685156.jpg



A problem with the PCB ruined the dayWell, it was expected to happen... After all, this PCB is the prototype, so i should not get mad... Anyway, here is the thing: First of all, i wanted to test the TMR1 gate function of the PIC and set it to measure the fan RPM. I may use this method for my next project (PC fan controller), so i added the brown wire to the PCB. I may remove it afterwards, because i do not really want to have RPM feedback from the fan. The fan will run with PWM pulses in an open loop.The thing that really messed me up is the PWM output. I've done this error many times, the very same error. I get the PWM output from the wrong PIC pin. This time, instead of taking the PWM ouput from pin 8 (SEG21/CCP3/P3A/AN5/RE0), i took it from pin 5 (SEG15/VREF+/C1IN+/AN3/RA3). So i had to cut the line from pin 5 and connect a wire (the white wire) to get the PWM from the correct pin. The result is a fully functional but ugly PCB

http://www.pcbheaven.com/projectpages/images/ktypethermcouplepidcontroller_1314683985.jpg

liyf 发表于 2012-1-12 22:50:57

I kept this dryer many months for such an occasion. It was a present that my girlfriend found in a shampoo package. She asked me if i wanted to keep this, and instead of a hair dryer i actually saw motor and a heater :D.

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315117879.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315117900.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315117926.jpg
This is the hair dryerAnd this is an exploded viewThe heater resistor is 800 watts!




http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315118370.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315118386.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315118404.jpg
The motor is a 12V DC, it has 4 diodes to rectify the ACI will remove the wire and the switch from the heater resistorAnd i will keep the fan blades. The motor sounds like a train


The heater comes with a built-in mechanical bimetallic thermostat because we don't want the lady to have a thermal shock. I measured the temperature before i hack it, and it was 80 to 90oC. When i removed the thermostat the temperature climbed up to 300oC before i unplug it.

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315118931.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315118958.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315118977.jpg
The heater comes with a built-in bimetallic thermostatI bridged the thermostat with a thick wireI added 2 new wires to power the heater
http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315119012.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315119059.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315119088.jpg
I will use the plastic cover cone to drive the air through the heaterThis is the final assembly of the heater. The base diameter fits perfectly on this PC fan







A faster thermocouple (September 10 2011)I tried the thermocouple that i got from ebay to see how it reacts in temperature changes. This thermocouple has a large mass to heat, so the reaction is not very fast. So i decided to change the thermocouple with a smaller mass to have faster reaction to temperature changes:

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1314381531.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315120029.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315120045.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315120062.jpg
This is the thermocouple with the large mass and slow reactionAnd this is a typical fast-acting K-type thermocouple for multimetersI don't need the socket for the multimeterThis is what i'm going to use


The thermocouple is ready to work with the controller, and the controller is ready to be programmed!

http://www.pcbheaven.com/projectpages/images/ktypethermcouplepidcontroller_1315120078.jpg



The new (and hopefully final) schematic (September 13 2011)So, if you have already read the previous pages and more specifically page #3, you may have notice that i made a few mistakes on the PCB which i had to fix them with two wire bridges. I tested the board with these wires and it seems that it works perfectly. So, here is the new (and hopefully last) schematic diagram of the PID controller:

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1315942252.png

Yet again, due to the fact that the image above is low resolution and the schematic is not very clear, i upload the eagle files for this project:

http://www.pcbheaven.com/pics/attach.png K-Type Thermocouple PID Controller - Eagle Schematic V1.1




Explosion is something that can happen while prototyping (September 16 2011)This is what happened: A little tiny bug in the software caused the output to go high rapidly. I was testing the controller while i was playing my favorite game. The incident first excited my nose. The heater became very hot, about 350oC, and the plastic cover took fire. But that's only the beginning. I tried to pull the thermocouple back and put off the fire, but the plastic had already melt and the thermocouple stuck in there. So i pulled it with force, but unfortunately the thermocouple wire touched the 220V resistor...

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316088711.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316088723.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316088736.jpg
This is what happens when 220V goes through the MAX6675The plastic went on fireAnd the thermocouple got a nice plastic coating ;)


So there will be a small delay to repair the controller...

liyf 发表于 2012-1-12 22:51:21

So, i began repairing the controller. The casualties from this mistake are:

The MAX6675 had a really bad day...The PIC has one (or more) defective ports. Although it works, its not reliable any more. I will keep it for experiments though.The 4511 is not workingThe TRIC reacts very strange - not normal operation
Ok, it happens... I replaced all the above-mentioned parts and the controller works again just fine.

http://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316375814.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316375832.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316375867.jpghttp://www.pcbheaven.com/projectpages/images/thumbs/ktypethermcouplepidcontroller_1316375886.jpg
These chips had a bad day... Must be changedThe triac is nor operating normally, so i will change it as wellI enjoy using my new hot-air soldering station for the SMDFinally, the controller operates normally.




The PIC SoftwareVersion 1.1 - September 20 2011 - Changelog:

[Bugfix] I fixed the bug when calculating the derivative term which could cause output oscillations.[Performance] I changed the output burst control and now it runs without causing delay to the A/D module.

http://www.pcbheaven.com/pics/attach.png K-Type Thermocouple PID Controller - Assembly listing - V1.1


http://www.pcbheaven.com/pics/attach.png K-Type Thermocouple PID Controller - HEX file - V1.1








Version 1.0 - September 19 2011

Here is the very first PIC software for the controller (Version 1.0):
The assembly file was corrupted so i lost version 1.0 assembly listing.


http://www.pcbheaven.com/pics/attach.png K-Type Thermocouple PID Controller - HEX file - V1.0


The PC fan is controlled with PWM pulses. The first potentiometer adjusts the duty cycle of the pulses and therefore the speed of the fan can be directly adjusted. The software can read the speed of the fan for security reasons: If the fan stalls for any reason, the heater must immediately be turned off.The PID routine has these parameters:GAIN_P_Constant: The gain multiplier for the Proportional termGAIN_I_Constant: The gain multiplier for the Integral termGAIN_D_Constant: The gain multiplier for the Derivative termTIME_I_Constant: The time interval for the Integral accumulationTIME_D_Constant: The time interval for the Derivative calculationThese parameters are currently constants, but i plan to preserve some EEPROM space to save them there and also i will probably make a UI routine to change them from the controller buttons directly.The heater control is done with bursts. Each burst has a length of about 250 mSec. The mains power supply has a frequency of 50 Hz (period=20mSec). So, during each burst, at least 12 full AC periods go through the triac to the heater. The interval between the bursts depends on the PID output calculation.The buttons have currently no operation. I currently use the LEDs only for debugging reasons. The red LED corresponds to the power bursts of the heater. The green LED changes state every time an integral value is accumulated. I plan to change the function of the green LED and i will use it as a power indicator: If the controller has power, the LED will be always on. I kinda like the way that the red LED operates, so i may keep it as is.

华蓉东根 发表于 2012-2-9 21:36:00

佩服你,能发这么好的帖子,厉害

ffey8810 发表于 2012-6-15 16:30:48

38

过来一起顶!

robter 发表于 2015-10-26 21:38:52

这个很好,学习了,多谢楼主

gl542400 发表于 2017-2-11 14:34:28

这个很好,学习了,多谢楼主
页: [1]
查看完整版本: K-Type Thermocouple PID Controller