PDA

View Full Version : PID controller in 16F737



joeri
- 15th June 2006, 20:42
Hi, I want to control an oven with a pic.
I basicaly have build the oven, including the temp-sensing with a NTC.
The oven will be used for making SMD PCB's.
Therefor it has to follow a temperature profile in time.
I want to do this with a PID-controller.
I calculated the PID parameters (gain, I, D) by the step response.

I also tried to build the PID algorithm.
Only, in case of overshoot, I will have a negative error (wish temp minus real temp).
I wrote a routine to handle negative values; to multiply and subtract negative values (see below).
As this is quite complex, does anyone know if there is a more simple (faster) method to implement a PID for this application?

code;
AminB: '*** PROCEDURE A - B ***
tekA=NCD(A)
tekB=NCD(B)
IF (tekA = 16 AND tekB = 16) OR (tekA <>16 AND tekB<>16) Then 'check if A and B have same sign
abswaardeAminB = ABS(A-B)
IF tekA = 16 Then
IF NCD(A-B) = 16 Then
tekAminB = 16
Else
tekAminB = 0
EndIF
Else
tekAminB = NCD(A-B)
EndIF
Else
abswaardeAminB = ABS(A) + ABS(B)
IF NCD(A-B) = 16 Then
tekAminB = 16
Else
tekAminB = 0
EndIF
EndIF
'assembly of the value
IF tekAminB = 16 Then
C= 0 - abswaardeAminB 'negative word
Else
C = abswaardeAminB
EndIF
Return

AmaalB: '*** AmaalB ***
IF NCD(A) = 16 XOR NCD(B) = 16 Then
C = ABS(A) * ABS(B)
C = 0 - C
Else
C = ABS(A) * ABS(B)
EndIF
Return

regelkring:
errlastlast = errlast
errlast = err
err = wenswaarde - adval2 'wish temp minus real temp
A = 2
B = errlast
GoSub AmaalB
A = C
B = errlastlast
GoSub AminB
A = err
B = C
GoSub AminB
B = C
A = D100 'd*100
GoSub AmaalB
DTERM = C
A = I100 'I*100
B = err
GoSub AmaalB
A = C 'ITerm
B = 0 - DTERM
GoSub AminB
ID = C 'IDterm
A = err
B = errlast
GoSub AminB 'C bevat Pterm
A = 100
B = C
GoSub AmaalB
A = C
B= 0 - ID
GoSub AminB 'P + ID = PID
A = gain10 'gain * 10
B = C
GoTo AmaalB
IF NCD(C) = 16 Then
C = ABS(c)/1000 'PID term
C = 0 - C
Else
C = C / 1000
EndIF
A = duty
B = 0 - C
GoSub AminB
duty = C
IF duty > 100 AND NCD(duty)<>16 Then duty = 100
IF NCD(duty) = 16 Then duty = 0

Return

Acetronics2
- 16th June 2006, 14:39
Hi,

As it's a slow process ... Have a look here :

http://www.parallax.com/dl/docs/books/edu/ic.pdf

Can be directly used with PBP ... just few mods for your sensor ( will a NTC fit your temp range ??? I'm not so sure ... )

Good reading

Alain

joeri
- 17th June 2006, 22:50
I knows this document and will have a look at it.
My intention was to have a PID which I can use afterwards for any process I want.
The NTC is no problem. It comes with the original oven, and I measured the curves to translate the R-value towards °C.

Ron Marcus
- 18th June 2006, 06:09
I knows this document and will have a look at it.
My intention was to have a PID which I can use afterwards for any process I want.
The NTC is no problem. It comes with the original oven, and I measured the curves to translate the R-value towards °C.

What are the resistance values over the range desired? Will you use it for non lead solder, and will it (oven) be quick enough to heat up so as not to over stress the components?
I use a Cuisinart digital convection oven, and it is a little on the slow side to hit 225c. No problems though, other than pizza tasting a little metallic.

Ron

joeri
- 19th June 2006, 21:16
at 100°C I have 11 kOhm; at 150°C I have 3 kOhm; at 260°C I have 500Ohm. I use a current source which drives a small current through the NTC, then I amplify the voltage over the NTC with a opamp and bring it into the analog pic input. So far, so good.

The oven is a samsung with 1500W. I added two heat resistors from a waffle machine (another 1000W), so total of 2,5KW.
This boosts quite fast. Also, I have a fan to equalize the temp inside the oven. The complete oven is packed in rockwool.

But my problem is the PID. Any experience on how to work with negative errors (overshoot)?

The calculate PID values are:
gain= 10
I= 0,04
D = 100

So it seems I have a PD controller. Due to the slow process, that might be ok. Or not?

Ron Marcus
- 19th June 2006, 21:56
at 100°C I have 11 kOhm; at 150°C I have 3 kOhm; at 260°C I have 500Ohm. I use a current source which drives a small current through the NTC, then I amplify the voltage over the NTC with a opamp and bring it into the analog pic input. So far, so good.

The oven is a samsung with 1500W. I added two heat resistors from a waffle machine (another 1000W), so total of 2,5KW.
This boosts quite fast. Also, I have a fan to equalize the temp inside the oven. The complete oven is packed in rockwool.

But my problem is the PID. Any experience on how to work with negative errors (overshoot)?

The calculate PID values are:
gain= 10
I= 0,04
D = 100

So it seems I have a PD controller. Due to the slow process, that might be ok. Or not?

It sounds like the rock wool is overkill, plus you want to cool things down pretty quickly once soldered. I crack the door of the toaster oven slightly for my high tech solution.
I really think the PID may be overkill. If it were me, I would take the current value at a given time and compare it to a desired constant value with ...

heat_loop:
for time = 1 to 10

If curr_temp_val < set_temp_val then
relay = 0; A lower number means the temp is too high.
else relay = 1 ; temp too low
endif
pause 1000
next time
goto get_next_heat_increment ; Put next temp constant into set_temp_val and start again.

Otherwise, the relay pulls in to increase temperature.You can check/regulate the temp this way until the next time increment is reached. At this point, update set_temp_val and compare. You can make the time increments every 10 seconds, or every second for that matter. A heavily insulated unit will require you to cut off power to the elements early, or you will have substantial overshoot. I'd say to use the rockwool for the hydroponic "tomatoes", and use less insulation or an automatic vent to the outside.

joeri
- 20th June 2006, 19:38
I will keep it in mind for the 'tomatoes'.
I have a fan in the oven that can cool things down quickly.
Also, I made a LCD-screen in the oven to read out the temp.
Thanks for the help, but I want to implement the PID in order to have the controller ready when I want to use it for more sophisticated processes..

sammy
- 23rd June 2006, 19:09
hi:
take a look at these links. they should get you started.

http://www.web-ee.com/Schematics/Temp%20Controller/temp%20controller.htm


http://www.parallax.com/dl/docs/prod/sic/Web-PC-v1.0.pdf


the documentation from parallax is great.

latter
sam

joeri
- 24th June 2006, 12:39
Thank you for your support. :)
I continued with my code and got it up and running.
So this subject can be closed.