給需要的的人,指證,點評。
Altium Designer畫的原理圖和PCB圖如下:(51hei附件中可下載工程文件)
2019-07-28_020343.png (43.87 KB, 下載次數: 181)
下載附件
2019-7-28 21:06 上傳
2019-07-28_020314.png (43.47 KB, 下載次數: 161)
下載附件
2019-7-28 21:06 上傳
2019-07-28_020103.png (55.39 KB, 下載次數: 164)
下載附件
2019-7-28 21:06 上傳
0.png (8.93 KB, 下載次數: 190)
下載附件
2019-7-29 00:38 上傳
0.png (3.26 KB, 下載次數: 186)
下載附件
2019-7-29 00:39 上傳
Arduino源程序如下:
- // SolderingStation v0.6
- //
- // ATmega168/328-controlled Soldering Station for Hakko T12 Tips.
- // This version of the code implements:
- // - PID control of the heater
- // - Temperature measurement of the tip
- // - Temperature control via rotary encoder
- // - Boost mode by pressing rotary encoder switch
- // - Time driven sleep/power off mode according to handle movement
- // - Information display on OLED
- //
- // Future versions may implement:
- // - Measurement of input voltage and vcc
- // - Buzzer
- // - Setup menu
- // - Storing default values into the EEPROM
- // - Check if iron is connected
- //
- //
- // Clockspeed 16 MHz external.
- //
- // 2019 by Stefan Wagner
- //
- // based on the work of Jurgis Bal?iūnas (http://jurgis.me)
- // Libraries
- #include <PID_v1.h>
- #include <U8glib.h>
- // Pins
- #define SENSOR_PIN A0 // temperature sense
- #define VIN_PIN A1 // input voltage sense
- #define BUZZER_PIN 5 // buzzer
- #define BUTTON_PIN 6 // rotary encoder switch
- #define ROTARY_1_PIN 7 // rotary encoder 1
- #define ROTARY_2_PIN 8 // rotary encoder 2
- #define CONTROL_PIN 9 // heater MOSFET PWM control
- #define SWITCH_PIN 10 // handle vibration switch
- // Temperature control values
- #define TEMP_MIN 150 // min selectable temperature
- #define TEMP_MAX 400 // max selectable temperature
- #define TEMP_DEFAULT 320 // default start setpoint
- #define TEMP_SLEEP 150 // temperature in sleep mode
- #define TEMP_BOOST 50 // temperature increase in boost mode
- #define TEMP_STEP 10 // rotary encoder temp change steps
- // Timer values (0 = disabled)
- #define TIME2SLEEP 5 // time to enter sleep mode in minutes
- #define TIME2OFF 15 // time to shut off heater in minutes
- #define TIMEOFBOOST 30 // time of boost mode in seconds
- // Define the aggressive and conservative PID tuning parameters
- double aggKp=20, aggKi=0, aggKd=1;
- double consKp=20, consKi=1, consKd=1;
- // Variables for pin change interrupt
- volatile uint8_t a0, b0, c0, d0;
- volatile int count = TEMP_DEFAULT;
- volatile bool handleMoved;
-
- // Variables for temperature control
- double Setpoint = TEMP_DEFAULT;
- double Input, Output, CurrentTemp, ShowTemp;
-
- // Other variables
- bool inSleepMode = false;
- bool inOffMode = false;
- bool inBoostMode = false;
- uint32_t sleepmillis;
- uint32_t boostmillis;
- uint8_t goneMinutes;
- uint8_t goneSeconds;
-
- // Specify the links and initial PID tuning parameters
- PID ctrl(&Input, &Output, &Setpoint, aggKp, aggKi, aggKd, REVERSE);
-
- // Setup u8g object (OLED 128x64, Fast I2C)
- U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_NO_ACK|U8G_I2C_OPT_FAST);
- void setup() {
- // set the pin modes
- pinMode(SENSOR_PIN, INPUT);
- pinMode(CONTROL_PIN, OUTPUT);
- pinMode(ROTARY_1_PIN, INPUT_PULLUP);
- pinMode(ROTARY_2_PIN, INPUT_PULLUP);
- pinMode(BUTTON_PIN, INPUT_PULLUP);
- pinMode(SWITCH_PIN, INPUT_PULLUP);
- // setup pin change interrupt for rotary encoder
- PCMSK0 = bit (PCINT0); // Configure pin change interrupt on Pin8
- PCICR = bit (PCIE0); // Enable pin change interrupt
- PCIFR = bit (PCIF0); // Clear interrupt flag
- // prepare and start OLED
- if ( u8g.getMode() == U8G_MODE_R3G3B2 ) u8g.setColorIndex(255);
- else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) u8g.setColorIndex(3);
- else if ( u8g.getMode() == U8G_MODE_BW ) u8g.setColorIndex(1);
- else if ( u8g.getMode() == U8G_MODE_HICOLOR ) u8g.setHiColorByRGB(255,255,255);
- // tell the PID to range between 0 and the full window size
- ctrl.SetOutputLimits(0, 255);
- // start PID
- ctrl.SetMode(AUTOMATIC);
- // set initial temperature to default value and clear rotary encoder values
- count = TEMP_DEFAULT;
- a0 = PINB & 1;
- b0 = PIND>>7 & 1;
- // reset sleep timer
- sleepmillis = millis();
- }
-
- void loop() {
- BOOSTCheck(); // check and activate/deactivate boost mode
- SLEEPCheck(); // check and activate/deactivate sleep modes
- ADCSample(); // reads temperature and vibration switch of the iron
- PIDUpdate(); // updates the PID and sets the PWM duty cycle for the heater
- OLEDRedraw(); // updates the OLED
- }
- // check and activate/deactivate boost mode
- void BOOSTCheck() {
- // check rotary encoder switch
- uint8_t c = digitalRead(BUTTON_PIN);
- if ( !c && c0 ) {
- inBoostMode = !inBoostMode;
- if (inBoostMode) boostmillis = millis();
- handleMoved = true;
- }
- c0 = c;
- // check timer when in boost mode
- if (inBoostMode) {
- goneSeconds = (millis() - boostmillis) / 1000;
- if (goneSeconds >= TIMEOFBOOST) inBoostMode = false;
- }
- }
- // check and activate/deactivate sleep modes
- void SLEEPCheck() {
- if (handleMoved) { // if handle was moved
- handleMoved = false; // reset handleMoved flag
- inSleepMode = false; // reset sleep flag
- inOffMode = false; // reset off flag
- sleepmillis = millis(); // reset sleep timer
- }
- // check time passed since the handle was moved
- goneMinutes = (millis() - sleepmillis) / 60000;
- if ( (TIME2SLEEP > 0) && (goneMinutes >= TIME2SLEEP) ) inSleepMode = true;
- if ( (TIME2OFF > 0) && (goneMinutes >= TIME2OFF ) ) inOffMode = true;
- }
- // reads temperature and vibration switch of the iron
- void ADCSample() {
- // shut off heater in order to measure temperature and vibration switch
- // this also allows the bootstrap capacitor to recharge
- analogWrite(CONTROL_PIN, 255);
- delayMicroseconds(300);
-
- // read temperature and filter ADC by multisampling
- uint16_t adc = 0;
- for (uint8_t i = 0; i < 32; i++)
- adc += analogRead(SENSOR_PIN);
- adc >>= 5;
- // check handle vibration switch
- uint8_t d = digitalRead(SWITCH_PIN);
- if (d != d0) {
- handleMoved = true;
- d0 = d;
- }
-
- // turn on again heater
- analogWrite(CONTROL_PIN, Output);
-
- // apply quadratic equation to get temperature
- double temp = -0.0013*adc*adc + 1.696*adc - 59.284;
-
- // additional temperature filtering
- CurrentTemp += (temp-CurrentTemp)*0.05;
- }
- // updates the PID and sets the PWM duty cycle for the heater
- void PIDUpdate() {
- if (inOffMode) Setpoint = 0;
- else if (inSleepMode) Setpoint = TEMP_SLEEP;
- else if (inBoostMode) Setpoint = count + TEMP_BOOST;
- else Setpoint = count;
-
- Input = CurrentTemp;
- double gap = abs(Setpoint-Input); //distance away from setpoint
- if (gap < 20) ctrl.SetTunings(consKp, consKi, consKd);
- else ctrl.SetTunings(aggKp, aggKi, aggKd);
- ctrl.Compute();
- analogWrite(CONTROL_PIN, Output);
- }
- // updates the OLED
- void OLEDRedraw() {
- u8g.firstPage();
- do {
- // draw setpoint temperature
- u8g.setFont(u8g_font_9x15);
- u8g.setFontPosTop();
- u8g.drawStr( 0, 0, "SET:");
- u8g.setPrintPos(40,0);
- u8g.print(Setpoint, 0);
- // draw status of heater
- u8g.setPrintPos(82,0);
- if (inOffMode) u8g.print(" OFF");
- else if (inSleepMode) u8g.print("SLEEP");
- else if (inBoostMode) u8g.print("BOOST");
- else if (Output < 180) u8g.print(" HEAT");
- else u8g.print(" HOLD");
- // draw current temperature in big figures
- u8g.setFont(u8g_font_fub42n);
- u8g.setFontPosTop();
- u8g.setPrintPos(15,20);
- u8g.print(CurrentTemp, 0);
- } while(u8g.nextPage());
- }
- // Pin change interrupt service routine for rotary encoder
- ISR (PCINT0_vect) {
- uint8_t a = PINB & 1;
- uint8_t b = PIND>>7 & 1;
- if (a != a0) { // A changed
- a0 = a;
- if (b != b0) { // B changed
- b0 = b;
- count = constrain(count + ((a == b) ? TEMP_STEP : -TEMP_STEP), TEMP_MIN, TEMP_MAX);
- handleMoved = true;
- }
- }
- }
復制代碼
所有資料51hei提供下載:
T12 文件夾.zip
(1.15 MB, 下載次數: 556)
2019-7-28 21:08 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|