DIY编程器网

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2864|回复: 1
打印 上一主题 下一主题

Reflow oven with PID control

[复制链接]
跳转到指定楼层
楼主
发表于 2013-9-11 07:44:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
原文:
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:
  1. symbol Kp = 1000
  2. symbol Ki = 20
  3. symbol Kd = 10

  4. symbol dt = 1
  5. symbol set_temp =w0
  6. symbol set_time =b0
  7. symbol sensor = 1
  8. symbol cur_temp = w1
  9. symbol cur_time=b1
  10. symbol oven = 7

  11. symbol led_hot =5
  12. symbol led_hold =4
  13. symbol err = b2
  14. symbol pre_temp =b3
  15. symbol INT_MAX = 1000
  16. symbol PRO_MAX = 15000
  17. symbol DER_MAX = 5000
  18. symbol PID_MAX = 52768
  19. symbol PID_MIN = 12768
  20. symbol PID = w2
  21. symbol x=b4
  22. symbol input_button1= pinc.1




  23. '#########################################################################################

  24. INIT:
  25. set_temp =0
  26. set_time =0
  27. PID = 49000

  28. '#########################################################################################


  29. Main:


  30. do
  31. low oven
  32. low led_hot
  33. low led_hold

  34. if input_button1 = 0 then        'Waits in this loop until button1 is pressed
  35.   exit   
  36. endif  
  37.                
  38. gosub get_temp
  39. gosub Phase_1
  40. gosub get_temp

  41. gosub Phase_2
  42. gosub get_temp

  43. gosub Phase_3
  44. gosub get_temp

  45. gosub Phase_4


  46. low oven

  47. loop

  48. goto main



  49. '#########################################################################################


  50. get_temp:        'Reads thermocouple

  51. readadc10 sensor, cur_temp

  52. return


  53. '#########################################################################################

  54. Phase_1:

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



  57. if cur_temp < set_temp then
  58. gosub get_temp
  59.   high led_hot
  60.   gosub PID_calc
  61.   gosub PID_control
  62. endif

  63. low led_hot  
  64. for  cur_time=1 to set_time
  65. gosub get_temp
  66.   high led_hold
  67.   gosub PID_calc
  68.   gosub PID_control
  69.   pause 1000
  70. next cur_time

  71. low led_hold



  72. return

  73. '#########################################################################################  

  74. Phase_2:

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

  77. if cur_temp < set_temp then
  78. gosub get_temp
  79.   high led_hot
  80.   gosub PID_calc
  81.   gosub PID_control
  82. endif

  83. low led_hot  
  84. for  cur_time=1 to set_time
  85. gosub get_temp
  86.   high led_hold
  87.   gosub PID_calc
  88.   gosub PID_control
  89.   pause 1000
  90. next cur_time

  91. low led_hold



  92. return



  93. '#########################################################################################  

  94. Phase_3:

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

  97. if cur_temp < set_temp then
  98. gosub get_temp
  99.   high led_hot
  100.   gosub PID_calc
  101.   gosub PID_control
  102. endif

  103. low led_hot  
  104. for  cur_time=1 to set_time
  105. gosub get_temp
  106.   high led_hold
  107.   gosub PID_calc
  108.   gosub PID_control
  109.   pause 1000
  110. next cur_time

  111. low led_hold



  112. return


  113. '#########################################################################################  

  114. Phase_4:

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


  117. if cur_temp => set_temp then
  118. gosub get_temp
  119.   high led_hot
  120.   gosub PID_calc
  121.   gosub PID_control
  122. endif

  123. low led_hot
  124. return

  125. '#########################################################################################  

  126. PID_calc:

  127. gosub get_temp

  128. if PID > 49000 then
  129.         PID = 49000
  130. else
  131.         PID = PID
  132. endif


  133. if cur_temp <= set_temp then        'for negative errors
  134.        
  135.         err = set_temp - cur_temp        max 65         'error
  136.        
  137.         w3 = Ki * err * dt max INT_MAX        'INTEGRAL..........................
  138.         PID = PID + w3 max PID_MAX       
  139.                        
  140.         w3 = Kp * err max PRO_MAX        'PROPORTIONAL......................
  141.         PID = PID + w3 max PID_MAX        'Int + Pro
  142.        
  143. else 'for positive errors

  144.         err = cur_temp - set_temp        max 65        'error
  145.        
  146.         w3 = Ki * err * dt max INT_MAX        'INTEGRAL.........................
  147.         PID = PID - w3 min PID_MIN       
  148.        
  149.         w3 = Kp * err max PRO_MAX        'PROPORTIONAL....................
  150.         PID = PID - w3 min PID_MIN        'Int + Pro
  151.        
  152. endif



  153. 'if cur_temp > err then 'temp increasing
  154.         'w3 = cur_temp - err
  155.         'w3 = w3 * Kd max DER_MAX        'DERIVATIVE ......................
  156.         'PID = PID - w3 min PID_MIN        'int + pro + der
  157. 'elseif cur_temp < err then 'temp decreasing
  158.         'w3 = err - cur_temp
  159.         'w3 = w3 * Kd max DER_MAX        'DERIVATIVE ......................
  160.         'PID = PID + w3 max PID_MAX        'int + pro + der
  161. 'else
  162.         'w3 = 0 'no derivative part
  163. 'endif


  164. 'pre_temp= cur_temp


  165. return

  166. '#########################################################################################  


  167. PID_control:

  168. for x = 1 to 1000                                'Manual PWM with 1 second period (adjust pause at end of main routine to get 1 sec period)
  169.         if x > PID then
  170.                 low oven
  171.         else
  172.                 high oven
  173.         endif
  174.        
  175.         pause 6
  176. next x



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

  178. return

  179. '#########################################################################################
复制代码
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                                               
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏1 分享分享 支持支持 反对反对
沙发
发表于 2015-10-22 21:52:07 | 只看该作者
感谢楼主提供这么好的东东
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|文字版|手机版|DIY编程器网 ( 桂ICP备14005565号-1 )

GMT+8, 2024-12-26 15:27 , 耗时 0.079991 秒, 21 个查询请求 , Gzip 开启.

各位嘉宾言论仅代表个人观点,非属DIY编程器网立场。

桂公网安备 45031202000115号

DIY编程器群(超员):41210778 DIY编程器

DIY编程器群1(满员):3044634 DIY编程器1

diy编程器群2:551025008 diy编程器群2

QQ:28000622;Email:libyoufer@sina.com

本站由桂林市临桂区技兴电子商务经营部独家赞助。旨在技术交流,请自觉遵守国家法律法规,一旦发现将做封号删号处理。

快速回复 返回顶部 返回列表