查看完整版本: Reflow oven with PID control

liyf 发表于 2013-9-11 07:44:08

Reflow oven with PID control

原文:
Hi guys ,

i' currently building a reflow oven with PID control with PICAXE 28X1.I'm using a standard pizza oven and using a relay to control the main power switch.
Since i'm still a newbie in regard of PID control and PWM, i have intergrate the PID control from greencardigan project 'coffee maker' into the source code of my project.

The oven should operate with this parameters
1.heat to 150°C and maintain for 40s
2.heat to 190°C and maintain for 10s
3.heat to 245°C and maintain for 10s
4. Cool down to room tempereature

the code is as followed:
symbol Kp = 1000
symbol Ki = 20
symbol Kd = 10

symbol dt = 1
symbol set_temp =w0
symbol set_time =b0
symbol sensor = 1
symbol cur_temp = w1
symbol cur_time=b1
symbol oven = 7

symbol led_hot =5
symbol led_hold =4
symbol err = b2
symbol pre_temp =b3
symbol INT_MAX = 1000
symbol PRO_MAX = 15000
symbol DER_MAX = 5000
symbol PID_MAX = 52768
symbol PID_MIN = 12768
symbol PID = w2
symbol x=b4
symbol input_button1= pinc.1




'#########################################################################################

INIT:
set_temp =0
set_time =0
PID = 49000

'#########################################################################################


Main:


do
low oven
low led_hot
low led_hold

if input_button1 = 0 then        'Waits in this loop until button1 is pressed
exit   
endif
               
gosub get_temp
gosub Phase_1
gosub get_temp

gosub Phase_2
gosub get_temp

gosub Phase_3
gosub get_temp

gosub Phase_4


low oven

loop

goto main



'#########################################################################################


get_temp:        'Reads thermocouple

readadc10 sensor, cur_temp

return


'#########################################################################################

Phase_1:

set_temp =123 'set temperate at 150°C
set_time =40'hold 150°C for 40s



if cur_temp < set_temp then
gosub get_temp
high led_hot
gosub PID_calc
gosub PID_control
endif

low led_hot
forcur_time=1 to set_time
gosub get_temp
high led_hold
gosub PID_calc
gosub PID_control
pause 1000
next cur_time

low led_hold



return

'#########################################################################################

Phase_2:

set_temp =156 'set temperate at 190°C
set_time =10'hold 190°C for 10s

if cur_temp < set_temp then
gosub get_temp
high led_hot
gosub PID_calc
gosub PID_control
endif

low led_hot
forcur_time=1 to set_time
gosub get_temp
high led_hold
gosub PID_calc
gosub PID_control
pause 1000
next cur_time

low led_hold



return



'#########################################################################################

Phase_3:

set_temp =201 'set temperate at 245°C
set_time =10'hold 245°C for 10s

if cur_temp < set_temp then
gosub get_temp
high led_hot
gosub PID_calc
gosub PID_control
endif

low led_hot
forcur_time=1 to set_time
gosub get_temp
high led_hold
gosub PID_calc
gosub PID_control
pause 1000
next cur_time

low led_hold



return


'#########################################################################################

Phase_4:

set_temp =20 'set temperate at 25°C
set_time =10'go to 25°C to cool down


if cur_temp => set_temp then
gosub get_temp
high led_hot
gosub PID_calc
gosub PID_control
endif

low led_hot
return

'#########################################################################################

PID_calc:

gosub get_temp

if PID > 49000 then
        PID = 49000
else
        PID = PID
endif


if cur_temp <= set_temp then        'for negative errors
       
        err = set_temp - cur_temp        max 65         'error
       
        w3 = Ki * err * dt max INT_MAX        'INTEGRAL..........................
        PID = PID + w3 max PID_MAX       
                       
        w3 = Kp * err max PRO_MAX        'PROPORTIONAL......................
        PID = PID + w3 max PID_MAX        'Int + Pro
       
else 'for positive errors

        err = cur_temp - set_temp        max 65        'error
       
        w3 = Ki * err * dt max INT_MAX        'INTEGRAL.........................
        PID = PID - w3 min PID_MIN       
       
        w3 = Kp * err max PRO_MAX        'PROPORTIONAL....................
        PID = PID - w3 min PID_MIN        'Int + Pro
       
endif



'if cur_temp > err then 'temp increasing
        'w3 = cur_temp - err
        'w3 = w3 * Kd max DER_MAX        'DERIVATIVE ......................
        'PID = PID - w3 min PID_MIN        'int + pro + der
'elseif cur_temp < err then 'temp decreasing
        'w3 = err - cur_temp
        'w3 = w3 * Kd max DER_MAX        'DERIVATIVE ......................
        'PID = PID + w3 max PID_MAX        'int + pro + der
'else
        'w3 = 0 'no derivative part
'endif


'pre_temp= cur_temp


return

'#########################################################################################


PID_control:

for x = 1 to 1000                                'Manual PWM with 1 second period (adjust pause at end of main routine to get 1 sec period)
        if x > PID then
                low oven
        else
                high oven
        endif
       
        pause 6
next x



pause 54                                        'Adjust to get timing right on PID mode (1 sec PWM period)

return

'#########################################################################################The PID controller seems to be not functioning. The oven will heat to 160°C and the picaxe will exit the program.
Can someone spot any mistake?

Thanks

grimmjaws                                               

robter 发表于 2015-10-22 21:52:07

感谢楼主提供这么好的东东
页: [1]
查看完整版本: Reflow oven with PID control