单片机教程网

电脑版
提示:原网页已由神马搜索转码, 内容由www.51hei.com提供.
上一页
1/2
下一页
查看:28331|回复:55

T12白光洛铁PCB原理图开源 Arduino源程序

 [复制链接]
ID:576039发表于 2019-7-28 21:13|显示全部楼层
给需要的的人,指证,点评。
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
2019-07-28_020343.png
2019-07-28_020314.png
2019-07-28_020103.png0.png0.png

Arduino源程序如下:
  1. // SolderingStation v0.6
  2. //
  3. // ATmega168/328-controlled Soldering Station for Hakko T12 Tips.
  4. // This version of the code implements:
  5. // - PID control of the heater
  6. // - Temperature measurement of the tip
  7. // - Temperature control via rotary encoder
  8. // - Boost mode by pressing rotary encoder switch
  9. // - Time driven sleep/power off mode according to handle movement
  10. // - Information display on OLED
  11. //
  12. // Future versions may implement:
  13. // - Measurement of input voltage and vcc
  14. // - Buzzer
  15. // - Setup menu
  16. // - Storing default values into the EEPROM
  17. // - Check if iron is connected
  18. //
  19. //
  20. // Clockspeed 16 MHz external.
  21. //
  22. // 2019 by Stefan Wagner
  23. //
  24. // based on the work of Jurgis Bal?iūnas (http://jurgis.me)



  25. // Libraries
  26. #include< PID_v1.h>
  27. #include< U8glib.h>

  28. // Pins
  29. #define SENSOR_PIN   A0       // temperature sense
  30. #define VIN_PIN     A1       // input voltage sense
  31. #define BUZZER_PIN     5       // buzzer
  32. #define BUTTON_PIN     6       // rotary encoder switch
  33. #define ROTARY_1_PIN   7       // rotary encoder 1
  34. #define ROTARY_2_PIN   8       // rotary encoder 2
  35. #define CONTROL_PIN   9       // heater MOSFET PWM control
  36. #define SWITCH_PIN   10       // handle vibration switch

  37. // Temperature control values
  38. #define TEMP_MIN     150     // min selectable temperature
  39. #define TEMP_MAX     400     // max selectable temperature
  40. #define TEMP_DEFAULT  320     // default start setpoint
  41. #define TEMP_SLEEP   150     // temperature in sleep mode
  42. #define TEMP_BOOST     50     // temperature increase in boost mode
  43. #define TEMP_STEP     10     // rotary encoder temp change steps

  44. // Timer values (0 = disabled)
  45. #define TIME2SLEEP     5       // time to enter sleep mode in minutes
  46. #define TIME2OFF     15       // time to shut off heater in minutes
  47. #define TIMEOFBOOST   30       // time of boost mode in seconds

  48. // Define the aggressive and conservative PID tuning parameters
  49. double aggKp=20, aggKi=0, aggKd=1;
  50. double consKp=20, consKi=1, consKd=1;

  51. // Variables for pin change interrupt
  52. volatile uint8_t a0, b0, c0, d0;
  53. volatile int count = TEMP_DEFAULT;
  54. volatile bool handleMoved;

  55. // Variables for temperature control
  56. double Setpoint = TEMP_DEFAULT;
  57. double Input, Output, CurrentTemp, ShowTemp;

  58. // Other variables
  59. bool inSleepMode = false;
  60. bool inOffMode   = false;
  61. bool inBoostMode = false;
  62. uint32_t sleepmillis;
  63. uint32_t boostmillis;
  64. uint8_t  goneMinutes;
  65. uint8_t  goneSeconds;

  66. // Specify the links and initial PID tuning parameters
  67. PID ctrl(&Input,& Output,& Setpoint, aggKp, aggKi, aggKd, REVERSE);

  68. // Setup u8g object (OLED 128x64, Fast I2C)
  69. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);



  70. void setup() {
  71.   // set the pin modes
  72.   pinMode(SENSOR_PIN,   INPUT);
  73.   pinMode(CONTROL_PIN,  OUTPUT);
  74.   pinMode(ROTARY_1_PIN, INPUT_PULLUP);
  75.   pinMode(ROTARY_2_PIN, INPUT_PULLUP);
  76.   pinMode(BUTTON_PIN,   INPUT_PULLUP);
  77.   pinMode(SWITCH_PIN,   INPUT_PULLUP);

  78.   // setup pin change interrupt for rotary encoder
  79.   PCMSK0 = bit (PCINT0);           // Configure pin change interrupt on Pin8
  80.   PCICR  = bit (PCIE0);             // Enable pin change interrupt
  81.   PCIFR  = bit (PCIF0);             // Clear interrupt flag

  82.   // prepare and start OLED
  83.   if     ( u8g.getMode() == U8G_MODE_R3G3B2 )   u8g.setColorIndex(255);
  84.   else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) u8g.setColorIndex(3);
  85.   else if ( u8g.getMode() == U8G_MODE_BW )     u8g.setColorIndex(1);
  86.   else if ( u8g.getMode() == U8G_MODE_HICOLOR )  u8g.setHiColorByRGB(255,255,255);

  87.   // tell the PID to range between 0 and the full window size
  88.   ctrl.SetOutputLimits(0, 255);

  89.   // start PID
  90.   ctrl.SetMode(AUTOMATIC);

  91.   // set initial temperature to default value and clear rotary encoder values
  92.   count = TEMP_DEFAULT;
  93.   a0 = PINB& 1;
  94.   b0 = PIND>>7& 1;

  95.   // reset sleep timer
  96.   sleepmillis = millis();
  97. }


  98. void loop() {
  99.   BOOSTCheck();     // check and activate/deactivate boost mode
  100.   SLEEPCheck();     // check and activate/deactivate sleep modes
  101.   ADCSample();       // reads temperature and vibration switch of the iron
  102.   PIDUpdate();       // updates the PID and sets the PWM duty cycle for the heater
  103.   OLEDRedraw();     // updates the OLED
  104. }




  105. // check and activate/deactivate boost mode
  106. void BOOSTCheck() {
  107.   // check rotary encoder switch
  108.   uint8_t c = digitalRead(BUTTON_PIN);
  109.   if ( !c&& c0 ) {
  110.    inBoostMode = !inBoostMode;
  111.    if (inBoostMode) boostmillis = millis();
  112.    handleMoved = true;
  113.   }
  114.   c0 = c;

  115.   // check timer when in boost mode
  116.   if (inBoostMode) {
  117.    goneSeconds = (millis() - boostmillis) / 1000;
  118.    if (goneSeconds >= TIMEOFBOOST) inBoostMode = false;
  119.   }
  120. }


  121. // check and activate/deactivate sleep modes
  122. void SLEEPCheck() {
  123.   if (handleMoved) {               // if handle was moved
  124.    handleMoved = false;           // reset handleMoved flag
  125.    inSleepMode = false;           // reset sleep flag
  126.    inOffMode   = false;           // reset off flag
  127.    sleepmillis = millis();         // reset sleep timer
  128.   }

  129.   // check time passed since the handle was moved
  130.   goneMinutes = (millis() - sleepmillis) / 60000;
  131.   if ( (TIME2SLEEP > 0)&& (goneMinutes >= TIME2SLEEP) ) inSleepMode = true;
  132.   if ( (TIME2OFF   > 0)&& (goneMinutes >= TIME2OFF  ) ) inOffMode   = true;
  133. }


  134. // reads temperature and vibration switch of the iron
  135. void ADCSample() {
  136.   // shut off heater in order to measure temperature and vibration switch
  137.   // this also allows the bootstrap capacitor to recharge
  138.   analogWrite(CONTROL_PIN, 255);
  139.   delayMicroseconds(300);
  140.   
  141.   // read temperature and filter ADC by multisampling
  142.   uint16_t adc = 0;
  143.   for (uint8_t i = 0; i< 32; i++)
  144.    adc += analogRead(SENSOR_PIN);
  145.   adc >>= 5;

  146.   // check handle vibration switch
  147.   uint8_t d = digitalRead(SWITCH_PIN);
  148.   if (d != d0) {
  149.    handleMoved = true;
  150.    d0 = d;
  151.   }
  152.   
  153.   // turn on again heater
  154.   analogWrite(CONTROL_PIN, Output);

  155.   // apply quadratic equation to get temperature
  156.   double temp = -0.0013*adc*adc + 1.696*adc - 59.284;
  157.   
  158.   // additional temperature filtering
  159.   CurrentTemp += (temp-CurrentTemp)*0.05;
  160. }


  161. // updates the PID and sets the PWM duty cycle for the heater
  162. void PIDUpdate() {
  163.   if     (inOffMode)   Setpoint = 0;
  164.   else if (inSleepMode) Setpoint = TEMP_SLEEP;
  165.   else if (inBoostMode) Setpoint = count + TEMP_BOOST;
  166.   else             Setpoint = count;
  167.   
  168.   Input = CurrentTemp;
  169.   double gap = abs(Setpoint-Input); //distance away from setpoint
  170.   if (gap< 20) ctrl.SetTunings(consKp, consKi, consKd);
  171.   else ctrl.SetTunings(aggKp, aggKi, aggKd);
  172.   ctrl.Compute();
  173.   analogWrite(CONTROL_PIN, Output);
  174. }


  175. // updates the OLED
  176. void OLEDRedraw() {
  177.   u8g.firstPage();
  178.   do {
  179.    // draw setpoint temperature
  180.    u8g.setFont(u8g_font_9x15);
  181.    u8g.setFontPosTop();
  182.    u8g.drawStr( 0, 0,  "SET:");
  183.    u8g.setPrintPos(40,0);
  184.    u8g.print(Setpoint, 0);

  185.    // draw status of heater
  186.    u8g.setPrintPos(82,0);
  187.    if     (inOffMode)   u8g.print("  OFF");
  188.    else if (inSleepMode)  u8g.print("SLEEP");
  189.    else if (inBoostMode)  u8g.print("BOOST");
  190.    else if (Output< 180) u8g.print(" HEAT");
  191.    else             u8g.print(" HOLD");

  192.    // draw current temperature in big figures
  193.    u8g.setFont(u8g_font_fub42n);
  194.    u8g.setFontPosTop();
  195.    u8g.setPrintPos(15,20);
  196.    u8g.print(CurrentTemp, 0);
  197.   } while(u8g.nextPage());
  198. }


  199. // Pin change interrupt service routine for rotary encoder
  200. ISR (PCINT0_vect) {
  201.   uint8_t a = PINB& 1;
  202.   uint8_t b = PIND>>7& 1;

  203.   if (a != a0) {           // A changed
  204.    a0 = a;
  205.    if (b != b0) {         // B changed
  206.      b0 = b;
  207.      count = constrain(count + ((a == b) ? TEMP_STEP : -TEMP_STEP), TEMP_MIN, TEMP_MAX);
  208.      handleMoved = true;
  209.    }
  210.   }
  211. }
复制代码

所有资料51hei提供下载:
T12 文件夹.zip(1.15 MB, 下载次数: 552)

评分

黑币 +50
收起理由
+ 50
共享资料的黑币奖励!

查看全部评分

ID:272625发表于 2019-8-6 20:00|显示全部楼层
好资料,希望楼主能上传些成品图片看看。
ID:598522发表于 2019-8-9 18:43|显示全部楼层
很好,好资料,51黑有你更精彩!!!
ID:598522发表于 2019-8-16 18:13|显示全部楼层
好资料,终于有黑币可以用了
ID:590584发表于 2019-8-17 20:33|显示全部楼层
   谢谢分享。
ID:297381发表于 2019-8-20 09:40来自手机|显示全部楼层
谢谢分享
ID:600360发表于 2019-8-22 12:38来自手机|显示全部楼层
谢谢分享
ID:198286发表于 2019-9-7 18:01|显示全部楼层
很好,吧你做好的图片发来欣赏下
ID:609112发表于 2019-9-15 14:14|显示全部楼层
谢谢分享,这个真牛逼
ID:432073发表于 2019-9-15 18:16|显示全部楼层
很好,好资料,51黑有你更精彩!!!
ID:436736发表于 2019-9-23 22:03|显示全部楼层
做的很好,开元很彻底。
ID:609801发表于 2019-10-10 10:06来自手机|显示全部楼层
谢谢分享
ID:599349发表于 2019-10-14 15:44|显示全部楼层
感谢楼主的分享,学习中
ID:79544发表于 2019-10-16 08:04|显示全部楼层
感谢分享!赞。
ID:622823发表于 2019-10-31 13:44|显示全部楼层
感谢分享,非常不错的资料。
ID:622823发表于 2019-10-31 16:27|显示全部楼层
不错 的资料  这个版本 的少见
ID:436736发表于 2019-11-4 16:25|显示全部楼层
很实用的例子 多谢分享。
ID:638374发表于 2019-11-9 09:33|显示全部楼层
谢谢分享。
ID:347654发表于 2019-11-12 15:51|显示全部楼层
感谢分享,抽空试制,如成功也会分享给大家
ID:649577发表于 2019-11-30 01:53|显示全部楼层
感谢分享,非常不错的资料
ID:651779发表于 2019-12-1 00:16来自手机|显示全部楼层
摩拜大神,根本看不懂[em19
ID:607710发表于 2019-12-4 15:35|显示全部楼层
肯定有些伸手党傻眼了
ID:279787发表于 2019-12-13 11:17|显示全部楼层
这个图用的MP2307,输入24V很危险啊
ID:477892发表于 2019-12-19 21:12来自手机|显示全部楼层
感谢楼主分享!
ID:642926发表于 2019-12-20 08:32|显示全部楼层
谢谢分享
ID:150151发表于 2019-12-22 19:34|显示全部楼层
我打了五块板。。
ID:150151发表于 2019-12-24 09:40来自手机|显示全部楼层
打板5块
6E839266-CDC8-4C0E-903D-6F6B094A868A.jpeg
ID:677234发表于 2019-12-30 10:43|显示全部楼层
感谢,感谢。
ID:407499发表于 2020-1-18 20:40|显示全部楼层

感谢分享
ID:76671发表于 2020-1-27 11:16|显示全部楼层
谢谢分享,改一下可以用esp8266
ID:150151发表于 2020-2-19 15:28|显示全部楼层
51hei图片_20200219152830.jpg
51hei图片_202002191528301.jpg
51hei图片_202002191528302.jpg
我做了,屏不显示,是什么问题?有谁做成功过的说一下。
ID:471632发表于 2020-2-19 17:11|显示全部楼层
Arduino在哪里呢?怎么上传程序?
ID:150151发表于 2020-2-21 09:09|显示全部楼层
tigerzq 发表于 2020-2-19 17:11
Arduino在哪里呢?怎么上传程序?

ICSP接口。
ID:430492发表于 2020-3-10 13:00|显示全部楼层
这款确实有点创新,很少有人用Arduino写T12的控制。
ID:705985发表于 2020-3-10 19:37来自手机|显示全部楼层
谢谢,好资料!开源的很好
ID:702957发表于 2020-3-13 18:20|显示全部楼层
下载看一下 谢谢
ID:150151发表于 2020-3-15 01:35|显示全部楼层
链接:https://pan.baidu.com/s/1lC2Y5Sn7U_L-oxWhTOjhNA
提取码:gxat改成中文了的文件,原程序已经加了注释,打包有需要的自己下载,附上u8g2自定义字库的相关文件和工具。20200305已备份

原版英文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面

新版中文界面

新版中文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面

原版英文界面
ID:230374发表于 2020-3-29 20:40|显示全部楼层
谢谢分享
ID:230374发表于 2020-4-7 17:58|显示全部楼层
我参考此列有制作成,其中一项楼主不太明白,X4  KP-301  2P  EARTH看了图纸是空脚位,没有找到和那个脚位连接,手柄自动没有成功,忘赐教;
ID:725307发表于 2020-4-9 09:27|显示全部楼层
楼主厉害

手机版|小黑屋|51黑电子论坛|51黑电子论坛6群QQ管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网